[macruby-changes] [491] MacRuby/trunk/sample-macruby/HotCocoa/demo/lib
source_changes at macosforge.org
source_changes at macosforge.org
Tue Aug 26 23:10:58 PDT 2008
Revision: 491
http://trac.macosforge.org/projects/ruby/changeset/491
Author: rich at infoether.com
Date: 2008-08-26 23:10:58 -0700 (Tue, 26 Aug 2008)
Log Message:
-----------
basic demo structure
Modified Paths:
--------------
MacRuby/trunk/sample-macruby/HotCocoa/demo/lib/application.rb
Added Paths:
-----------
MacRuby/trunk/sample-macruby/HotCocoa/demo/lib/views/
MacRuby/trunk/sample-macruby/HotCocoa/demo/lib/views/buttons.rb
MacRuby/trunk/sample-macruby/HotCocoa/demo/lib/views/web_view.rb
Modified: MacRuby/trunk/sample-macruby/HotCocoa/demo/lib/application.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/demo/lib/application.rb 2008-08-27 06:10:40 UTC (rev 490)
+++ MacRuby/trunk/sample-macruby/HotCocoa/demo/lib/application.rb 2008-08-27 06:10:58 UTC (rev 491)
@@ -1,16 +1,31 @@
require 'hotcocoa'
+include HotCocoa
+
# Replace the following code with your own hotcocoa code
-class Application
-
- include HotCocoa
+class DemoApplication
+ def self.register(view_class)
+ view_classes << view_class
+ end
+
+ def self.view_classes
+ @view_classes ||= []
+ end
+
+ def self.view_with_description(description)
+ @view_classes.detect {|view| view.description == description}
+ end
+
+ attr_reader :current_demo_view, :main_window
+
def start
- application :name => "Demo" do |app|
+ load_view_files
+ application(:name => "Demo") do |app|
app.delegate = self
- window :frame => [100, 100, 500, 500], :title => "HotCocoa Demo Application" do |win|
- win << label(:text => "Hello!", :layout => {:start => false})
+ @main_window = window(:frame => [100, 100, 500, 500], :title => "HotCocoa Demo Application") do |win|
+ win << segment_control
win.will_close { exit }
end
end
@@ -39,6 +54,36 @@
# window/bring_all_to_front
def on_bring_all_to_front(menu)
end
+
+ private
+
+ def demo(description)
+ main_window.view.remove(current_demo_view) if current_demo_view
+ @current_demo_view = DemoApplication.view_with_description(description).create
+ main_window << @current_demo_view
+ end
+
+ def segment_control
+ @segment_control ||= create_segment_control
+ end
+
+ def create_segment_control
+ segmented_control(:layout => {:expand => :width, :align => :center, :start => false}, :segments => demo_app_segments) do |seg|
+ seg.on_action do
+ demo(@segment_control.selected_segment.label)
+ end
+ end
+ end
+
+ def demo_app_segments
+ DemoApplication.view_classes.collect {|view_class| {:label => view_class.description, :width => 0}}
+ end
+
+ def load_view_files
+ Dir.glob(File.join(File.dirname(__FILE__), 'views', '*.rb')).each do |file|
+ load file
+ end
+ end
end
-Application.new.start
\ No newline at end of file
+DemoApplication.new.start
\ No newline at end of file
Added: MacRuby/trunk/sample-macruby/HotCocoa/demo/lib/views/buttons.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/demo/lib/views/buttons.rb (rev 0)
+++ MacRuby/trunk/sample-macruby/HotCocoa/demo/lib/views/buttons.rb 2008-08-27 06:10:58 UTC (rev 491)
@@ -0,0 +1,16 @@
+class ButtonsView
+
+ def self.description
+ "Button Views"
+ end
+
+ def self.create
+ layout_view :mode => :horizontal, :frame => [0, 0, 0, 0], :layout => {:expand => [:width, :height]} do |view|
+ view.margin = 0
+ view << button(:title => "hello", :layout => {:expand => :width, :start => false})
+ end
+ end
+
+ DemoApplication.register(self)
+
+end
Added: MacRuby/trunk/sample-macruby/HotCocoa/demo/lib/views/web_view.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/demo/lib/views/web_view.rb (rev 0)
+++ MacRuby/trunk/sample-macruby/HotCocoa/demo/lib/views/web_view.rb 2008-08-27 06:10:58 UTC (rev 491)
@@ -0,0 +1,26 @@
+framework 'webkit'
+
+class WebView
+
+ def self.description
+ "Web Views"
+ end
+
+ def self.create
+ layout_view :frame => [0, 0, 0, 0], :layout => {:expand => [:width, :height]}, :margin => 0, :spacing => 0 do |view|
+ web_view = web_view(:layout => {:expand => [:width, :height]}, :url => "http://www.ruby-lang.org")
+ view << web_view
+ view << layout_view(:mode => :horizontal, :frame => [0, 0, 0, 40], :layout => {:expand => :width, :bottom_padding => 2}, :margin => 0, :spacing => 0) do |hview|
+ hview << button(:title => "Go", :layout => {:align => :center}).on_action do
+ web_view.url = @url.to_s
+ end
+ @url = text_field(:layout => {:expand => :width, :align => :center})
+ hview << @url
+ end
+ end
+ end
+
+ DemoApplication.register(self)
+
+end
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080826/29918fdd/attachment-0001.html
More information about the macruby-changes
mailing list