Modified: MacRuby/trunk/sample-macruby/HotCocoa/calculator.rb (402 => 403)
--- MacRuby/trunk/sample-macruby/HotCocoa/calculator.rb 2008-08-03 18:52:02 UTC (rev 402)
+++ MacRuby/trunk/sample-macruby/HotCocoa/calculator.rb 2008-08-03 19:10:34 UTC (rev 403)
@@ -19,19 +19,32 @@
def show
application do |app|
- window :frame => [100, 100, 220, 280], :title => "Calculator", :view => :nolayout, :style => [:titled, :closable, :miniturizable] do |win|
- @value = text_field :frame => [10, 230, 200, 40], :text => "0", :font => font(:name => "Tahoma", :size => 22), :text_align => :right
- win << value
- @button_view = view :frame => [10, 10, 200, 240]
- win << button_view
- add_buttons
- win.will_close { exit }
- end
+ main_window << value
+ main_window << button_view
+ main_window.will_close { exit }
end
end
private
+ def main_window(&block)
+ @main_window ||= window(:frame => [100, 100, 220, 280], :title => "Calculator", :view => :nolayout, :style => [:titled, :closable, :miniturizable], &block)
+ end
+
+ def value
+ @value ||= text_field(:frame => [10, 230, 200, 40], :text => "0", :font => font(:name => "Tahoma", :size => 22), :text_align => :right)
+ end
+
+ def button_view
+ @button_view || create_button_view
+ end
+
+ def create_button_view
+ @button_view = view(:frame => [10, 10, 200, 240])
+ add_buttons
+ @button_view
+ end
+
def add_buttons
calc_button("CL", 0, 4) { clear }
calc_button("SQR", 1, 4) { sqrt }