Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 134 lines (100 sloc) 3.93 kB
565c99a @thbar Documentation fixes
authored
1 Magic is a gem making it easier to develop UI:
e5eabd4 @thbar Fix readme formatting
authored
2 - Windows Forms, WPF/Silverlight with IronRuby
565c99a @thbar Documentation fixes
authored
3 - Swing with JRuby
bdced06 @thbar Added a better README. Preparing gem release.
authored
4
5 h1. USAGE
6
565c99a @thbar Documentation fixes
authored
7 Here are quick starters (some of these are under samples/):
d57da62 @thbar Updated README with WPF support.
authored
8
936128d @thbar Added Silverlight example on README
authored
9 h2. Windows Forms
10
c23d824 @thbar More formatting.
authored
11 <pre><code>form = Magic.build do
e5eabd4 @thbar Fix readme formatting
authored
12 @menu = main_menu do
13 menu_item("&File") do
14 menu_item("&New")
15 menu_item("&Quit").click { Application.Exit }
16 menu_item("&Other Quit", :click => lambda { Application.Exit })
17 end
18 end
19 form(:text => "Title", :menu => @menu) do
20 flow_layout_panel(:dock => :fill) do
21 button(:text => "Click me!").click do
22 MessageBox.Show("Hello from button!")
23 end
24 end
25 end
26 end
27
28 Application.Run(form)
29 </code></pre>
936128d @thbar Added Silverlight example on README
authored
30
d57da62 @thbar Updated README with WPF support.
authored
31 h2. WPF
936128d @thbar Added Silverlight example on README
authored
32
c23d824 @thbar More formatting.
authored
33 <pre><code>window = Magic.build do
e5eabd4 @thbar Fix readme formatting
authored
34 window(:width => 600, :height => 480, :title => 'Hello world!') do
35 stack_panel(:margin => thickness(30)) do
36 button(:content => 'Click me!', :font_size => 22).click do
37 MessageBox.show("Ok!")
38 end
39 end
40 end
41 end
42
43 app = Application.new
44 app.run(window)
45 </code></pre>
936128d @thbar Added Silverlight example on README
authored
46
d57da62 @thbar Updated README with WPF support.
authored
47 h2. Silverlight
48
49 You'll need to run "rake compress" to create magic-compressed.rb, which gathers all the magic files into one. Once you have magic-compressed.rb, you can use it like that:
936128d @thbar Added Silverlight example on README
authored
50
c23d824 @thbar More formatting.
authored
51 <pre><code>require "silverlight"
e5eabd4 @thbar Fix readme formatting
authored
52 require "magic-compressed"
53
54 class App < SilverlightApplication
936128d @thbar Added Silverlight example on README
authored
55
e5eabd4 @thbar Fix readme formatting
authored
56 def initialize
57 application.root_visual = Magic.build do
58 stack_panel do
59 10.times { |i| text_block(:text => i.to_s, :width => 30,:height => 30) }
60 end
61 end
62 end
63 end
936128d @thbar Added Silverlight example on README
authored
64
e5eabd4 @thbar Fix readme formatting
authored
65 $app = App.new
66 </code></pre>
936128d @thbar Added Silverlight example on README
authored
67
68 It makes it easy to create XAML-free applications, or to reduce the amount of XAML to be created.
bdced06 @thbar Added a better README. Preparing gem release.
authored
69
565c99a @thbar Documentation fixes
authored
70 h2. Swing
71
72 Preliminary support for Swing has just been added. Here's an example:
73
c23d824 @thbar More formatting.
authored
74 <pre><code>import 'javax.swing.JFrame'
e5eabd4 @thbar Fix readme formatting
authored
75 import 'javax.swing.JButton'
76
77 frame = Magic.build do
78 JFrame do
79 title 'Hello!'
80 size 400,500
81 JButton('Press me') do |b|
82 b.addActionListener do
83 b.setText 'Pressed!'
84 end
85 end
86 end
87 end
88
89 frame.set_default_close_operation(JFrame::EXIT_ON_CLOSE)
90 frame.show
91 </code></pre>
565c99a @thbar Documentation fixes
authored
92
bdced06 @thbar Added a better README. Preparing gem release.
authored
93 h1. UNDER THE COVER
94
95 A few points (see spec/magic_spec.rb for details):
96
97 * classes to be built are inferred from method calls (converted from snake_case to CamelCase)
98 ** menu_item creates an instance of MenuItem
99 ** button becomes Button
100 ** flow_layout_panel becomes FlowLayoutPanel
355362b @thbar Allows properties setting from the block. Passes last created object …
authored
101 * if a method call matches an existing method of the parent, the method is called
102 * the instanciated control is passed as an optional param to the block
936128d @thbar Added Silverlight example on README
authored
103 * method calls automatically add the object to its parent children collection (if the object is a Control, a MenuItem or a UIElement - this will become configurable)
d57da62 @thbar Updated README with WPF support.
authored
104 * if the parent responds to :content (eg: WPF Window), then parent.content will use the (unique) child
bdced06 @thbar Added a better README. Preparing gem release.
authored
105 * if a Hash is passed, corresponding properties are set after instanciation (:text => "This is the text")
106 * if the property is an enum, snake_case symbol value is allowed (:dock => :fill is the same as :dock => DockStyle.Fill)
107 * handlers are registered if a lambda is passed (:click => lambda)
108 * handlers can also be registered by calling the block directly (button.lambda do ... end)
109 * instance variables can be reused (form.menu = @menu)
110 * non-control (like BackgroundWorker for long-running operations) instances can be created (worker = background_worker)
111 * the last evaluted expression is returned.
112
113 h1. TESTING
114
d57da62 @thbar Updated README with WPF support.
authored
115 Magic comes with its set of specs (based on MSpec). You'll currently have to tweak Rakefile (see spec task) to match your environment.
116
117 Then you can run (either on Windows or Mac OS):
bdced06 @thbar Added a better README. Preparing gem release.
authored
118
c23d824 @thbar More formatting.
authored
119 <pre><code>rake spec
e5eabd4 @thbar Fix readme formatting
authored
120 </code></pre>
bdced06 @thbar Added a better README. Preparing gem release.
authored
121
122 to see all the (m)specs running.
123
936128d @thbar Added Silverlight example on README
authored
124 Note that I currently use a few nasty mocks (see mocks.rb) that I'll need to clean-up.
125
565c99a @thbar Documentation fixes
authored
126 h1. TODO
bdced06 @thbar Added a better README. Preparing gem release.
authored
127
565c99a @thbar Documentation fixes
authored
128 * remove obsolete .Net flagged enum support (IronRuby now supports X | Y)
129 * split the core into toolkit-specific builders
bdced06 @thbar Added a better README. Preparing gem release.
authored
130
131 h1. COPYRIGHT
132
133 Copyright (c) 2008 Thibaut Barrère. See LICENSE for details.
Something went wrong with that request. Please try again.