Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 134 lines (100 sloc) 3.93 kb
565c99a8 »
2009-07-05 Documentation fixes
1 Magic is a gem making it easier to develop UI:
e5eabd41 »
2010-04-17 Fix readme formatting
2 - Windows Forms, WPF/Silverlight with IronRuby
565c99a8 »
2009-07-05 Documentation fixes
3 - Swing with JRuby
bdced068 »
2009-03-02 Added a better README. Preparing gem release.
4
5 h1. USAGE
6
565c99a8 »
2009-07-05 Documentation fixes
7 Here are quick starters (some of these are under samples/):
d57da622 »
2009-03-12 Updated README with WPF support.
8
936128dd »
2009-03-09 Added Silverlight example on README
9 h2. Windows Forms
10
c23d8248 »
2010-04-17 More formatting.
11 <pre><code>form = Magic.build do
e5eabd41 »
2010-04-17 Fix readme formatting
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>
936128dd »
2009-03-09 Added Silverlight example on README
30
d57da622 »
2009-03-12 Updated README with WPF support.
31 h2. WPF
936128dd »
2009-03-09 Added Silverlight example on README
32
c23d8248 »
2010-04-17 More formatting.
33 <pre><code>window = Magic.build do
e5eabd41 »
2010-04-17 Fix readme formatting
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>
936128dd »
2009-03-09 Added Silverlight example on README
46
d57da622 »
2009-03-12 Updated README with WPF support.
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:
936128dd »
2009-03-09 Added Silverlight example on README
50
c23d8248 »
2010-04-17 More formatting.
51 <pre><code>require "silverlight"
e5eabd41 »
2010-04-17 Fix readme formatting
52 require "magic-compressed"
53
54 class App < SilverlightApplication
936128dd »
2009-03-09 Added Silverlight example on README
55
e5eabd41 »
2010-04-17 Fix readme formatting
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
936128dd »
2009-03-09 Added Silverlight example on README
64
e5eabd41 »
2010-04-17 Fix readme formatting
65 $app = App.new
66 </code></pre>
936128dd »
2009-03-09 Added Silverlight example on README
67
68 It makes it easy to create XAML-free applications, or to reduce the amount of XAML to be created.
bdced068 »
2009-03-02 Added a better README. Preparing gem release.
69
565c99a8 »
2009-07-05 Documentation fixes
70 h2. Swing
71
72 Preliminary support for Swing has just been added. Here's an example:
73
c23d8248 »
2010-04-17 More formatting.
74 <pre><code>import 'javax.swing.JFrame'
e5eabd41 »
2010-04-17 Fix readme formatting
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>
565c99a8 »
2009-07-05 Documentation fixes
92
bdced068 »
2009-03-02 Added a better README. Preparing gem release.
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
355362b5 »
2009-03-19 Allows properties setting from the block. Passes last created object …
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
936128dd »
2009-03-09 Added Silverlight example on README
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)
d57da622 »
2009-03-12 Updated README with WPF support.
104 * if the parent responds to :content (eg: WPF Window), then parent.content will use the (unique) child
bdced068 »
2009-03-02 Added a better README. Preparing gem release.
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
d57da622 »
2009-03-12 Updated README with WPF support.
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):
bdced068 »
2009-03-02 Added a better README. Preparing gem release.
118
c23d8248 »
2010-04-17 More formatting.
119 <pre><code>rake spec
e5eabd41 »
2010-04-17 Fix readme formatting
120 </code></pre>
bdced068 »
2009-03-02 Added a better README. Preparing gem release.
121
122 to see all the (m)specs running.
123
936128dd »
2009-03-09 Added Silverlight example on README
124 Note that I currently use a few nasty mocks (see mocks.rb) that I'll need to clean-up.
125
565c99a8 »
2009-07-05 Documentation fixes
126 h1. TODO
bdced068 »
2009-03-02 Added a better README. Preparing gem release.
127
565c99a8 »
2009-07-05 Documentation fixes
128 * remove obsolete .Net flagged enum support (IronRuby now supports X | Y)
129 * split the core into toolkit-specific builders
bdced068 »
2009-03-02 Added a better README. Preparing gem release.
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.