[macruby-changes] [403] MacRuby/trunk/sample-macruby/HotCocoa/calculator.rb
source_changes at macosforge.org
source_changes at macosforge.org
Sun Aug 3 12:10:34 PDT 2008
Revision: 403
http://trac.macosforge.org/projects/ruby/changeset/403
Author: rich at infoether.com
Date: 2008-08-03 12:10:34 -0700 (Sun, 03 Aug 2008)
Log Message:
-----------
refactor to make more pretty
Modified Paths:
--------------
MacRuby/trunk/sample-macruby/HotCocoa/calculator.rb
Modified: MacRuby/trunk/sample-macruby/HotCocoa/calculator.rb
===================================================================
--- 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 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080803/46ad9e19/attachment.html
More information about the macruby-changes
mailing list