purple_shoes 0.0.101

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. data/README.md +56 -0
  2. data/VERSION +1 -0
  3. data/bin/pshoes +23 -0
  4. data/bin/pshoes.bat +2 -0
  5. data/lib/plugins/video.rb +88 -0
  6. data/lib/purple_shoes.rb +51 -0
  7. data/lib/shoes/anim.rb +47 -0
  8. data/lib/shoes/app.rb +688 -0
  9. data/lib/shoes/basic.rb +254 -0
  10. data/lib/shoes/colors.rb +149 -0
  11. data/lib/shoes/download.rb +26 -0
  12. data/lib/shoes/help.rb +473 -0
  13. data/lib/shoes/helper_methods.rb +295 -0
  14. data/lib/shoes/main.rb +96 -0
  15. data/lib/shoes/manual.rb +6 -0
  16. data/lib/shoes/ruby.rb +61 -0
  17. data/lib/shoes/slot.rb +104 -0
  18. data/lib/shoes/style.rb +41 -0
  19. data/lib/shoes/text.rb +46 -0
  20. data/lib/shoes/url.rb +14 -0
  21. data/lib/shoes/widget.rb +23 -0
  22. data/samples/class-book.yaml +387 -0
  23. data/samples/cy.png +0 -0
  24. data/samples/loogink.png +0 -0
  25. data/samples/potato_chopping/1258_s001.gif +0 -0
  26. data/samples/potato_chopping/1258_s002.gif +0 -0
  27. data/samples/potato_chopping/1258_s003.gif +0 -0
  28. data/samples/potato_chopping/1258_s004.gif +0 -0
  29. data/samples/potato_chopping/1258_s005.gif +0 -0
  30. data/samples/potato_chopping/1258_s006.gif +0 -0
  31. data/samples/potato_chopping/1258_s007.gif +0 -0
  32. data/samples/potato_chopping/1258_s008.gif +0 -0
  33. data/samples/potato_chopping/1258_s009.gif +0 -0
  34. data/samples/potato_chopping/1258_s010.gif +0 -0
  35. data/samples/potato_chopping/1258_s011.gif +0 -0
  36. data/samples/potato_chopping/1258_s012.gif +0 -0
  37. data/samples/potato_chopping/1258_s013.gif +0 -0
  38. data/samples/potato_chopping/1258_s014.gif +0 -0
  39. data/samples/potato_chopping/1258_s015.gif +0 -0
  40. data/samples/potato_chopping/1258_s016.gif +0 -0
  41. data/samples/potato_chopping/1258_s017.gif +0 -0
  42. data/samples/potato_chopping/1258_s018.gif +0 -0
  43. data/samples/potato_chopping/1258_s019.gif +0 -0
  44. data/samples/potato_chopping/1258_s020.gif +0 -0
  45. data/samples/potato_chopping/1258_s021.gif +0 -0
  46. data/samples/potato_chopping/1258_s022.gif +0 -0
  47. data/samples/potato_chopping/1258_s023.gif +0 -0
  48. data/samples/potato_chopping/1258_s024.gif +0 -0
  49. data/samples/potato_chopping/1258_s025.gif +0 -0
  50. data/samples/potato_chopping/1258_s026.gif +0 -0
  51. data/samples/potato_chopping/1258_s027.gif +0 -0
  52. data/samples/potato_chopping/1258_s028.gif +0 -0
  53. data/samples/potato_chopping/1258_s029.gif +0 -0
  54. data/samples/potato_chopping/1258_s030.gif +0 -0
  55. data/samples/potato_chopping/1258_s031.gif +0 -0
  56. data/samples/potato_chopping/1258_s032.gif +0 -0
  57. data/samples/potato_chopping/1258_s033.gif +0 -0
  58. data/samples/potato_chopping/1258_s034.gif +0 -0
  59. data/samples/potato_chopping/1258_s035.gif +0 -0
  60. data/samples/potato_chopping/1258_s036.gif +0 -0
  61. data/samples/potato_chopping/1258_s037.gif +0 -0
  62. data/samples/potato_chopping/1258_s038.gif +0 -0
  63. data/samples/potato_chopping/1258_s039.gif +0 -0
  64. data/samples/potato_chopping/1258_s040.gif +0 -0
  65. data/samples/potato_chopping/1258_s041.gif +0 -0
  66. data/samples/potato_chopping/1258_s042.gif +0 -0
  67. data/samples/potato_chopping/1258_s043.gif +0 -0
  68. data/samples/potato_chopping/1258_s044.gif +0 -0
  69. data/samples/potato_chopping/1258_s045.gif +0 -0
  70. data/samples/potato_chopping/1258_s046.gif +0 -0
  71. data/samples/potato_chopping/1258_s047.gif +0 -0
  72. data/samples/potato_chopping/1258_s048.gif +0 -0
  73. data/samples/potato_chopping/1258_s049.gif +0 -0
  74. data/samples/potato_chopping/1258_s050.gif +0 -0
  75. data/samples/potato_chopping/1258_s051.gif +0 -0
  76. data/samples/potato_chopping/1258_s052.gif +0 -0
  77. data/samples/potato_chopping/1258_s053.gif +0 -0
  78. data/samples/potato_chopping/1258_s054.gif +0 -0
  79. data/samples/potato_chopping/1258_s055.gif +0 -0
  80. data/samples/potato_chopping/1258_s056.gif +0 -0
  81. data/samples/potato_chopping/1258_s057.gif +0 -0
  82. data/samples/potato_chopping/1258_s058.gif +0 -0
  83. data/samples/potato_chopping/1258_s059.gif +0 -0
  84. data/samples/sample1.rb +30 -0
  85. data/samples/sample10.rb +11 -0
  86. data/samples/sample11.rb +12 -0
  87. data/samples/sample12.rb +22 -0
  88. data/samples/sample13.rb +15 -0
  89. data/samples/sample14.rb +75 -0
  90. data/samples/sample15.rb +20 -0
  91. data/samples/sample16.rb +12 -0
  92. data/samples/sample17.rb +12 -0
  93. data/samples/sample18.rb +24 -0
  94. data/samples/sample19.rb +39 -0
  95. data/samples/sample2.rb +16 -0
  96. data/samples/sample20.rb +26 -0
  97. data/samples/sample21.rb +7 -0
  98. data/samples/sample22.rb +13 -0
  99. data/samples/sample23.rb +10 -0
  100. data/samples/sample24.rb +22 -0
  101. data/samples/sample25.rb +22 -0
  102. data/samples/sample27.rb +19 -0
  103. data/samples/sample28.rb +64 -0
  104. data/samples/sample29.rb +12 -0
  105. data/samples/sample3.rb +10 -0
  106. data/samples/sample30.rb +30 -0
  107. data/samples/sample31.rb +24 -0
  108. data/samples/sample34.rb +29 -0
  109. data/samples/sample35.rb +33 -0
  110. data/samples/sample36.rb +48 -0
  111. data/samples/sample37.rb +10 -0
  112. data/samples/sample38.rb +14 -0
  113. data/samples/sample4.rb +9 -0
  114. data/samples/sample40.rb +19 -0
  115. data/samples/sample42.rb +15 -0
  116. data/samples/sample43.rb +26 -0
  117. data/samples/sample44.rb +57 -0
  118. data/samples/sample45.rb +12 -0
  119. data/samples/sample46.rb +35 -0
  120. data/samples/sample47.rb +20 -0
  121. data/samples/sample48.rb +33 -0
  122. data/samples/sample49.rb +33 -0
  123. data/samples/sample5.rb +8 -0
  124. data/samples/sample50.rb +326 -0
  125. data/samples/sample58.rb +19 -0
  126. data/samples/sample6.rb +11 -0
  127. data/samples/sample7.rb +5 -0
  128. data/samples/sample8.rb +9 -0
  129. data/samples/sample9.rb +12 -0
  130. data/samples/sample99.rb +4 -0
  131. data/samples/sounds/102719__sarge4267__explosion.mp3 +0 -0
  132. data/samples/sounds/145622__andybrannan__train-fog-horn-long-wyomming.aiff +0 -0
  133. data/samples/sounds/46492__phreaksaccount__shields1.ogg +0 -0
  134. data/samples/sounds/61847__simon-rue__boink-v3.wav +0 -0
  135. data/snapshots/sample1.png +0 -0
  136. data/snapshots/sample10.png +0 -0
  137. data/snapshots/sample11.png +0 -0
  138. data/snapshots/sample12.png +0 -0
  139. data/snapshots/sample13.png +0 -0
  140. data/snapshots/sample14.png +0 -0
  141. data/snapshots/sample15.png +0 -0
  142. data/snapshots/sample16.png +0 -0
  143. data/snapshots/sample17.png +0 -0
  144. data/snapshots/sample18.png +0 -0
  145. data/snapshots/sample19.png +0 -0
  146. data/snapshots/sample2.png +0 -0
  147. data/snapshots/sample20.png +0 -0
  148. data/snapshots/sample21.png +0 -0
  149. data/snapshots/sample22.png +0 -0
  150. data/snapshots/sample23.png +0 -0
  151. data/snapshots/sample24.png +0 -0
  152. data/snapshots/sample25.png +0 -0
  153. data/snapshots/sample27.png +0 -0
  154. data/snapshots/sample28.png +0 -0
  155. data/snapshots/sample29.png +0 -0
  156. data/snapshots/sample3-osx.png +0 -0
  157. data/snapshots/sample3.png +0 -0
  158. data/snapshots/sample30.png +0 -0
  159. data/snapshots/sample31.png +0 -0
  160. data/snapshots/sample33.png +0 -0
  161. data/snapshots/sample34.png +0 -0
  162. data/snapshots/sample35.png +0 -0
  163. data/snapshots/sample36.png +0 -0
  164. data/snapshots/sample37.png +0 -0
  165. data/snapshots/sample38.png +0 -0
  166. data/snapshots/sample4.png +0 -0
  167. data/snapshots/sample40.png +0 -0
  168. data/snapshots/sample42.png +0 -0
  169. data/snapshots/sample43.png +0 -0
  170. data/snapshots/sample44-linux.png +0 -0
  171. data/snapshots/sample44.png +0 -0
  172. data/snapshots/sample45.png +0 -0
  173. data/snapshots/sample46.png +0 -0
  174. data/snapshots/sample47.png +0 -0
  175. data/snapshots/sample48.png +0 -0
  176. data/snapshots/sample49.png +0 -0
  177. data/snapshots/sample5.png +0 -0
  178. data/snapshots/sample50.png +0 -0
  179. data/snapshots/sample58.png +0 -0
  180. data/snapshots/sample6.png +0 -0
  181. data/snapshots/sample7.png +0 -0
  182. data/snapshots/sample8.png +0 -0
  183. data/snapshots/sample9.png +0 -0
  184. data/snapshots/sample99.png +0 -0
  185. data/static/code_highlighter.js +188 -0
  186. data/static/code_highlighter_ruby.js +26 -0
  187. data/static/man-editor-notepad.png +0 -0
  188. data/static/man-editor-osx.png +0 -0
  189. data/static/man-ele-background.png +0 -0
  190. data/static/man-ele-border.png +0 -0
  191. data/static/man-ele-button.png +0 -0
  192. data/static/man-ele-check.png +0 -0
  193. data/static/man-ele-editbox.png +0 -0
  194. data/static/man-ele-editline.png +0 -0
  195. data/static/man-ele-image.png +0 -0
  196. data/static/man-ele-listbox.png +0 -0
  197. data/static/man-ele-progress.png +0 -0
  198. data/static/man-ele-radio.png +0 -0
  199. data/static/man-ele-shape.png +0 -0
  200. data/static/man-ele-textblock.png +0 -0
  201. data/static/man-ele-video.png +0 -0
  202. data/static/man-shot1.png +0 -0
  203. data/static/manual-en.txt +3969 -0
  204. data/static/manual-ja.txt +3882 -0
  205. data/static/manual.css +184 -0
  206. data/static/purple_shoes-icon.png +0 -0
  207. data/static/rshoes-icon.png +0 -0
  208. data/static/shoes-manual-apps.png +0 -0
  209. data/static/sound_jars/jl1.0.1.jar +0 -0
  210. data/static/sound_jars/jogg-0.0.7.jar +0 -0
  211. data/static/sound_jars/jorbis-0.0.15.jar +0 -0
  212. data/static/sound_jars/mp3spi1.9.5.jar +0 -0
  213. data/static/sound_jars/tritonus_share.jar +0 -0
  214. data/static/sound_jars/vorbisspi1.0.3.jar +0 -0
  215. metadata +271 -0
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,3969 @@
1
+ # -*- encoding: utf-8 -*-
2
+ = Hello! =
3
+
4
+ Shoes is a tiny graphics toolkit. It's simple and straightforward. Shoes was
5
+ born to be easy! Really, it was made for absolute beginners. There's really
6
+ nothing to it. Purple Shoes is one of colorful Shoes. It is written in JRuby
7
+ with SWT.
8
+
9
+ You see, the trivial Shoes program can be just one line:
10
+
11
+ {{{
12
+ #!ruby
13
+ Shoes.app{button("Click me!"){alert("Good job.")}}
14
+ }}}
15
+
16
+ Shoes programs are written in a language called Ruby. When Shoes is handed
17
+ this simple line of Ruby code, a window appears with a button inside reading
18
+ "Click me!" When the button is clicked, a message pops up.
19
+
20
+ On Windows 7, here's how this might look: !{margin_left: 100}man-shot1.png!
21
+
22
+ While lots of Shoes apps are graphical games and art programs, you can also
23
+ layout text and edit controls easily. !{margin_left: 80}shoes-manual-apps.png!
24
+
25
+ And, ideally, Shoes programs will run on any of the major platforms out there.
26
+ Microsoft Windows, Apple's Mac OS X, Linux and many others.
27
+
28
+ ^So, welcome to Purple Shoes' built-in manual. This manual is a Purple Shoes program itself!^
29
+
30
+ == Introducing Purple Shoes ==
31
+
32
+ How does Purple Shoes look on OS X and Linux? Does it really look okay? Is it all
33
+ ugly and awkward? People must immediately convulse! It must be so watered down
34
+ trying to do everything.
35
+
36
+ Well, before getting into the stuff about installing and running Purple Shoes, time to
37
+ just check out some screenshots, to give you an idea of what you can do.
38
+
39
+ ==== Mac OS X ====
40
+
41
+ Purple Shoes is confirmed on Apple Mac OSX10.5 PPC via X11.
42
+ !{margin_left: 100}../snapshots/sample3-osx.png!
43
+
44
+ This is the `sample3.rb` on Mac OS X.
45
+
46
+ All circles are drawn randomly. You can draw and animate shapes in Purple Shoes.
47
+
48
+ ==== Windows ====
49
+
50
+ Purple Shoes is confirmed to run on '''Microsoft Windows XP''' and '''Windows 7'''.
51
+ !{margin_left: 0}../snapshots/sample33.png!
52
+
53
+ Above is pictured the `sample33.rb` running on Windows 7. Purple Shoes
54
+ has three extended libraries for chipmunk physics, bloopsaphone and 3D texture
55
+ mapping. First two are binary libraries, so far work on Windows only.
56
+
57
+ ==== Linux ====
58
+
59
+ Here's a screenshot of the `sample44.rb` running on '''Ubuntu
60
+ on VirtualBox for Windows'''. !{margin_left: 130}../snapshots/sample44-linux.png!
61
+
62
+ This example is also draws ovals and lines to build the clock, which is animated to
63
+ show or hide itself several times each second.
64
+
65
+ Notice the text on the top of the app, showing the current time. Purple Shoes has the
66
+ skills to layout words using any color, bold, italics, underlines, and supports
67
+ loading fonts.
68
+
69
+ == Installing Purple Shoes ==
70
+
71
+ Okay, on to installing Purple Shoes. I'm sure you're wondering: do I need to install
72
+ Ruby? Do I need to unzip anything? What commands do I need to type?
73
+
74
+ Yeah. You need to install Ruby and Gems. But, no need to worry about it.
75
+ We'll talk through all the steps.
76
+
77
+ ==== Step 1: Installing Purple Shoes ====
78
+
79
+ At first, install Ruby. On '''Windows''',
80
+ visit the site of [[http://rubyinstaller.org/ RubyInstaller for Windows]] to
81
+ download the latest '''RubyInstaller 1.9.2 or 1.9.3'''.
82
+
83
+ Then just do the following one line.
84
+
85
+ * gem install green_shoes
86
+
87
+ That's all. Too easy?
88
+
89
+ '''Note:''' green_shoes gem is on [[http://rubygems.org/gems/green_shoes RubyGems.org]].
90
+ If you get some errors of rdoc, try to add `--no-ri --no-rdoc` option.
91
+
92
+ ==== Step 2: Start a New Text File ====
93
+
94
+ Shoes programs are just plain text files ending with a '''.rb''' extension.
95
+
96
+ Here are a few ways to create a blank text file:
97
+
98
+ * On '''Mac OS X''', visit your '''Applications''' folder and double-click on the '''TextEdit''' app. A blank editor window should come up. Now, go to the '''Format''' menu and select the '''Make Plain Text''' option. Okay, you're all set! !man-editor-osx.png!
99
+ * On '''Windows''', go to the Start menu. Select '''All Programs''', then '''Accessories''', then '''Notepad'''. !man-editor-notepad.png!
100
+ * On '''Linux''', most distros come with '''gedit'''. You might try running that. Or, if your distro is KDE-based, run '''kate'''.
101
+
102
+ Now, in your blank window, type in the following:
103
+
104
+ {{{
105
+ require 'green_shoes'
106
+ Shoes.app do
107
+ para "Welcome to Shoes"
108
+ end
109
+ }}}
110
+
111
+ Save to your desktop as `welcome.rb`.
112
+
113
+ ==== Step 3: Run It! Go Shoes! ====
114
+
115
+ To run your program, just open console window and run the following.
116
+
117
+ * ruby welcome.rb !man-editor-osx.png!
118
+
119
+ So, not much of a program yet. But it's something! You've got the knack of it, at least!
120
+
121
+ ==== What Can You Make With Shoes? ====
122
+
123
+ Well, you can make windowing applications. But Shoes is inspired by the web, so
124
+ applications tend to use images and text layout rather than a lot of widgets.
125
+ For example, Shoes doesn't come with tabbed controls or toolbars. Shoes is a
126
+ ''tiny'' toolkit, remember?
127
+
128
+ Still, Shoes does have a few widgets like buttons and edit boxes. And many
129
+ missing elements (like tabbed controls or toolbars) can be simulated with
130
+ images.
131
+
132
+ Shoes is written in part thanks to a very good art engine called Cairo, which
133
+ is used for drawing with shapes and colors. Also thanks to an awesome text
134
+ lay out engine called Pango. In this way, Shoes is inspired by
135
+ NodeBox and Processing, two very good languages for drawing animated graphics.
136
+
137
+ == The Rules of Purple Shoes ==
138
+
139
+ Time to stop guessing how Purple Shoes works. Some of the tricky things will come
140
+ back to haunt you. I've boiled down the central rules to Purple Shoes. These are the
141
+ things you MUST know to really make it all work.
142
+
143
+ These are general rules found throughout Purple Shoes. While Purple Shoes has an overall
144
+ philosophy of simplicity and clarity, there are a few points that need to be
145
+ studied and remembered.
146
+
147
+ ==== Shoes Tricky Blocks ====
148
+
149
+ Okay, this is absolutely crucial. Purple Shoes does a trick with blocks. This trick
150
+ makes everything easier to read. But it also can make blocks harder to use
151
+ once you're in deep.
152
+
153
+ '''Let's take a normal Ruby block:'''
154
+
155
+ {{{
156
+ Shoes.app do
157
+ ary = ['potion', 'swords', 'shields']
158
+ ary.each do |item|
159
+ puts item
160
+ end
161
+ end
162
+ }}}
163
+
164
+ In Purple Shoes, these sorts of blocks work the same. This block above loops through
165
+ the array and stores each object in the `item` variable. The `item` variable
166
+ disappears (goes out of scope) when the block ends.
167
+
168
+ One other thing to keep in mind is that `self` stays the same inside normal
169
+ Ruby blocks. Whatever `self` was before the call to `each`, it is the same
170
+ inside the `each` block.
171
+
172
+ '''Both of these things are also true for most Purple Shoes blocks.'''
173
+
174
+ {{{
175
+ Shoes.app do
176
+ stack do
177
+ para "First"
178
+ para "Second"
179
+ para "Third"
180
+ end
181
+ end
182
+ }}}
183
+
184
+ Here we have two blocks. The first block is sent to `Shoes.app`. This `app`
185
+ block changes `self`.
186
+
187
+ The other block is the `stack` block. That block does NOT change self.
188
+
189
+ '''For what reason does the `app` block change self?''' Let's start by
190
+ spelling out that last example completely.
191
+
192
+ {{{
193
+ Shoes.app do
194
+ self.stack do
195
+ self.para "First"
196
+ self.para "Second"
197
+ self.para "Third"
198
+ end
199
+ end
200
+ }}}
201
+
202
+ All of the `self`s in the above example are the App object. Purple Shoes uses Ruby's
203
+ `instance_eval` to change self inside the `app` block. So the method calls to
204
+ `stack` and `para` get sent to the app.
205
+
206
+ '''This also is why you can use instance variables throughout a Shoes app:'''
207
+
208
+ {{{
209
+ Shoes.app do
210
+ @s = stack do
211
+ @p1 = para "First"
212
+ @p2 = para "Second"
213
+ @p3 = para "Third"
214
+ end
215
+ end
216
+ }}}
217
+
218
+ These instance variables will all end up inside the App object.
219
+
220
+ '''Whenever you create a new Shoes.app window, `self` is also changed.'''
221
+
222
+ {{{
223
+ Shoes.app title: "MAIN" do
224
+ para self
225
+ button "Spawn" do
226
+ Shoes.app title: "CHILD" do
227
+ para self
228
+ end
229
+ end
230
+ end
231
+ }}}
232
+
233
+ ==== Block Redirection ====
234
+
235
+ The `stack` block is a different story, though. It doesn't change `self` and
236
+ it's basically a regular block.
237
+
238
+ '''But there's a trick:''' when you attach a `stack` and give it a block, the
239
+ App object places that stack in its memory. The stack gets popped off when the
240
+ block ends. So all drawing inside the block gets '''redirected''' from the
241
+ App's top slot to the new stack.
242
+
243
+ So those three `para`s will get drawn on the `stack`, even though they actually
244
+ get sent to the App object first.
245
+
246
+ {{{
247
+ Shoes.app do
248
+ stack do
249
+ para "First"
250
+ para "Second"
251
+ para "Third"
252
+ end
253
+ end
254
+ }}}
255
+
256
+ A bit tricky, you see? This can bite you even if you know about it.
257
+
258
+ One way it'll get you is if you try to edit a stack somewhere else in your
259
+ program, outside the `app` block.
260
+
261
+ Like let's say you pass around a stack object. And you have a class that edits
262
+ that object.
263
+
264
+ {{{
265
+ class Messenger
266
+ def initialize slot
267
+ @slot = slot
268
+ end
269
+ def add msg
270
+ para msg rescue puts $!
271
+ end
272
+ end
273
+
274
+ Shoes.app do
275
+ slot = stack
276
+ m = Messenger.new slot
277
+ m.add 'hello'
278
+ end
279
+ }}}
280
+
281
+ So, let's assume you pass the stack object into your Messenger class when the
282
+ app starts. And, later, when a message comes in, the `add` method gets used to
283
+ append a paragraph to that stack. Should work, right?
284
+
285
+ Nope, it won't work. The `para` method won't be found. The App object isn't
286
+ around any more. And it's the one with the `para` method.
287
+
288
+ Fortunately, each Shoes object has an `app` method that will let you reopen the
289
+ App object so you can do some further editing.
290
+
291
+ {{{
292
+ class Messenger
293
+ def initialize slot
294
+ @slot = slot
295
+ end
296
+ def add msg
297
+ @slot.app do
298
+ para msg rescue puts $!
299
+ end
300
+ end
301
+ end
302
+
303
+ Shoes.app do
304
+ slot = stack
305
+ m = Messenger.new slot
306
+ m.add 'hello'
307
+ end
308
+ }}}
309
+
310
+ As you can imagine, the `app` object changes `self` to the App object.
311
+
312
+ So the rules here are:
313
+
314
+ 1. '''Methods named "app" or which create new windows alter `self` to the App
315
+ object.'''[[BR]](This is true for both Shoes.app and Slot.app, as well as
316
+ [[Element.window]] and [[Element.dialog]].)[[BR]]
317
+ 2. '''Blocks attached to stacks, flows or any manipulation method (such as
318
+ append) do not change self. Instead, they pop the slot on to the app's editing
319
+ stack.'''
320
+
321
+ ==== Careful With Fixed Heights ====
322
+
323
+ Fixed widths on slots are great so you can split the window into columns.
324
+
325
+ {{{
326
+ Shoes.app do
327
+ flow do
328
+ stack :width => 200 do
329
+ background lavender
330
+ caption "Column one"
331
+ para "is 200 pixels wide"
332
+ end
333
+ stack :width => -200 do
334
+ background bisque
335
+ caption "Column two"
336
+ para "is 100% minus 200 pixels wide"
337
+ end
338
+ end
339
+ end
340
+ }}}
341
+
342
+ Fixed heights on slots should be less common. Usually you want your text and
343
+ images to just flow down the window as far as they can. Height usually happens
344
+ naturally.
345
+
346
+ The important thing here is that fixed heights actually force slots to behave
347
+ differently. To be sure that the end of the slot is chopped off perfectly, the
348
+ slot becomes a '''nested window'''. A new layer is created by the operating
349
+ system to keep the slot in a fixed square.
350
+
351
+ One difference between normal slots and nested window slots is that the latter
352
+ can have scrollbars.
353
+
354
+ {{{
355
+ Shoes.app do
356
+ stack width: 200, height: 200, scroll: true do
357
+ background "#DFA"
358
+ 100.times do |i|
359
+ para "Paragraph No. #{i}"
360
+ end
361
+ flush
362
+ end
363
+ end
364
+ }}}
365
+
366
+ These nested windows require more memory. They tax the application a bit more.
367
+ So if you're experiencing some slowness with hundreds of fixed-height slots,
368
+ try a different approach.
369
+
370
+ '''Note:''' Fixed height magic (the slot becomes a nested window) is implemented
371
+ in Purple Shoes as a trial so far. Need to add `flush` method.
372
+
373
+ {{{
374
+ Shoes.app do
375
+ stack :width => 200 do
376
+ background "#DFA"
377
+ 100.times do |i|
378
+ para "Paragraph No. #{i}"
379
+ end
380
+ end
381
+ end
382
+ }}}
383
+
384
+ ==== Image and Shape Blocks ====
385
+
386
+ Most beginners start littering the window with shapes. It's just easier to
387
+ throw all your rectangles and ovals in a slot.
388
+
389
+ '''However, bear in mind that Shoes will create objects for all those
390
+ shapes!'''
391
+
392
+ {{{
393
+ Shoes.app do
394
+ fill black.push(0.1)
395
+ 100.times do |i|
396
+ oval i, i, i * 2 if i > 0
397
+ end
398
+ end
399
+ }}}
400
+
401
+ In this example, one-hundred Oval objects are created. This isn't too bad.
402
+ But things would be slimmer if we made these into a single shape.
403
+
404
+ {{{
405
+ # Not yet available
406
+ Shoes.app do
407
+ fill black(0.1)
408
+ shape do
409
+ 100.times do |i|
410
+ oval i, i, i * 2 if i > 0
411
+ end
412
+ end
413
+ end
414
+ }}}
415
+
416
+ Oh, wait. The ovals aren't filled in this time! That's because the ovals have
417
+ been combined into a single huge shape. And Shoes isn't sure where to fill in
418
+ this case.
419
+
420
+ So you usually only want to combine into a single shape when you're dealing
421
+ strictly with outlines.
422
+
423
+ Another option is to combine all those ovals into a single image.
424
+
425
+ {{{
426
+ # Not yet available
427
+ Shoes.app do
428
+ fill black(0.1)
429
+ image 300, 300 do
430
+ 100.times do |i|
431
+ oval i, i, i * 2
432
+ end
433
+ end
434
+ end
435
+ }}}
436
+
437
+ There we go! The ovals are all combined into a single 300 x 300 pixel image.
438
+ In this case, storing that image in memory might be much bigger than having
439
+ one-hundred ovals around. But when you're dealing with thousands of shapes,
440
+ the image block can be cheaper.
441
+
442
+ The point is: it's easy to group shapes together into image or shape blocks, so
443
+ give it a try if you're looking to gain some speed. Shape blocks particularly
444
+ will save you some memory and speed.
445
+
446
+ ''Note:'' Purple Shoes doesn't support this magic (grouping shapes together
447
+ into image or shape blocks) so far.
448
+
449
+ ==== UTF-8 Everywhere ====
450
+
451
+ Ruby itself isn't Unicode aware. And UTF-8 is a type of Unicode. (See
452
+ [[http://en.wikipedia.org/wiki/UTF-8 Wikipedia]] for a full explanation of
453
+ UTF-8.)
454
+
455
+ However, UTF-8 is common on the web. And lots of different platforms support
456
+ it. So to cut down on the amount of conversion that Purple Shoes has to do,
457
+ Purple Shoes expects all strings to be in UTF-8 format.
458
+
459
+ This is great because you can show a myriad of languages (Russian, Japanese,
460
+ Spanish, English) using UTF-8 in Purple Shoes. Just be sure that your text editor
461
+ uses UTF-8!
462
+
463
+ To illustrate:
464
+
465
+ {{{
466
+ Shoes.app do
467
+ stack :margin => 10 do
468
+ @edit = edit_box do
469
+ @para.text = @edit.text
470
+ end
471
+ @para = para ""
472
+ end
473
+ end
474
+ }}}
475
+
476
+ This app will copy anything you paste into the edit box and display it in a
477
+ Purple Shoes paragraph. You can try copying some foreign text (such as
478
+ Greek or Japanese) into this box to see how it displays.
479
+
480
+ This is a good test because it proves that the edit box gives back UTF-8
481
+ characters. And the paragraph can be set to any UTF-8 characters.
482
+
483
+ '''Important note:''' if some UTF-8 characters don't display for you, you will
484
+ need to change the paragraph's font. This is especially common on OS X.
485
+
486
+ So, a good Japanese font on OS X is '''AppleGothic''' and on Windows is '''MS
487
+ UI Gothic'''.
488
+
489
+ {{{
490
+ Shoes.app do
491
+ para "てすと (te-su-to)",
492
+ font: case RUBY_PLATFORM
493
+ when /mingw/; "MS UI Gothic"
494
+ when /darwin/; "AppleGothic, Arial"
495
+ else "Arial"
496
+ end
497
+ end
498
+ }}}
499
+
500
+ Again, anything which takes a string in Purple Shoes will need a UTF-8 string.
501
+ Edit boxes, edit lines, list boxes, window titles and text blocks all take UTF-8.
502
+ If you give a string with bad characters in it, an error will show up in the
503
+ console.
504
+
505
+ ==== The Main App and Its Requires ====
506
+
507
+ '''NOTE:''' This rule is for Raisins. Policeman and Purple Shoes use TOPLEVEL_BINDING.
508
+ So, you can get `main`, Ruby top-level object, with the first snippet. Although you
509
+ need to use `Shoes::Para` instead of `Para` outside `Shoes.app` block.
510
+
511
+ Each Shoes app is given a little room where it can create itself. You can
512
+ create classes and set variables and they won't be seen by other Shoes
513
+ programs. Each program runs inside its own anonymous class.
514
+
515
+ {{{
516
+ main = self
517
+ Shoes.app do
518
+ para main.to_s
519
+ end
520
+ }}}
521
+
522
+ This anonymous class is called `(shoes)` and it's just an empty, unnamed class.
523
+ The `Shoes` module is mixed into this class (using `include Shoes`) so that you
524
+ can use either `Para` or `Shoes::Para` when referring to the paragraph class.
525
+
526
+ The advantages of this approach are:
527
+
528
+ * Shoes apps cannot share local variables.
529
+ * Classes created in the main app code are temporary.
530
+ * The Shoes module can be mixed in to the anonymous class, but not the top-level environment of Ruby itself.
531
+ * Garbage collection can clean up apps entirely once they complete.
532
+
533
+ The second part is especially important to remember.
534
+
535
+ {{{
536
+ class Storage; end
537
+
538
+ Shoes.app do
539
+ para Storage.new
540
+ end
541
+ }}}
542
+
543
+ The `Storage` class will disappear once the app completes. Other apps aren't
544
+ able to use the Storage class. And it can't be gotten to from files that are
545
+ loaded using `require`.
546
+
547
+ When you `require` code, though, that code will stick around. It will be kept
548
+ in the Ruby top-level environment.
549
+
550
+ So, the rule is: '''keep your temporary classes in the code with the app and
551
+ keep your permanent classes in requires.'''
552
+
553
+ = Shoes =
554
+
555
+ Purple Shoes is all about drawing windows and the stuff inside those windows. Let's
556
+ focus on the window itself, for now. The other sections [[Slots]] and
557
+ [[Elements]] cover everything that goes inside the window.
558
+
559
+ For here on, the manual reads more like a dictionary. Each page is mostly a
560
+ list of methods you can use for each topic covered. The idea is to be very
561
+ thorough and clear about everything.
562
+
563
+ So, if you've hit this far in the manual and you're still hazy about getting
564
+ started, you should probably either go back to the [[Hello! beginning]] of the
565
+ manual. Or you could try [[https://cloud.github.com/downloads/shoes/shoes/nks.pdf Nobody Knows
566
+ Shoes]], the beginner's leaflet PDF.
567
+
568
+ ==== Finding Your Way ====
569
+
570
+ This section covers:
571
+
572
+ * [[Built-in Built-in methods]] - general methods available anywhere in a Purple Shoes program.
573
+ * [[App The App window]] - methods found attached to every main Purple Shoes window.
574
+ * [[Styles The Styles Master List]] - a complete list of every style in Purple Shoes.
575
+ * [[Classes The Classes list]] - a chart showing what Purple Shoes classes subclass what.
576
+ * [[Colors The Colors list]] - a chart of all built-in colors and the [[Built-in.rgb]] numbers for each.
577
+
578
+ If you find yourself paging around a lot and not finding something, give the
579
+ [[Search]] page a try. It's the quickest way to get around.
580
+
581
+ After this general reference, there are two other more specific sections:
582
+
583
+ * [[Slots]] - covering [[Element.stack]] and [[Element.flow]], the two types of slots.
584
+ * [[Elements]] - documentation for all the buttons, shapes, images, and so on.
585
+
586
+ Two really important pages in there are the [[Element Element Creation]] page
587
+ (which lists all the elements you can add) and the [[Common Common Methods]]
588
+ page (which lists methods you'll find on any slot or element.)
589
+
590
+ == Built-in Methods ==
591
+
592
+ These methods can be used anywhere throughout Purple Shoes programs.
593
+
594
+ All of these commands are unusual because you don't attach them with a dot.
595
+ '''Every other method in this manual must be attached to an object with a dot.'''
596
+ But these are built-in methods (also called: Kernel methods.) Which means no dot!
597
+
598
+ A common one is `alert`:
599
+
600
+ {{{
601
+ alert "No dots in sight"
602
+ }}}
603
+
604
+ Compare that to the method `reverse`, which isn't a Kernel method and is only
605
+ available for Arrays and Strings:
606
+
607
+ {{{
608
+ #!ruby
609
+ Shoes.app do
610
+ para "Plaster of Paris".reverse
611
+ #=> "siraP fo retsalP"
612
+ para [:dogs, :cows, :snakes].reverse
613
+ #=> [:snakes, :cows, :dogs]
614
+ end
615
+ }}}
616
+
617
+ Most Purple Shoes methods for drawing and making buttons and so on are attached to
618
+ slots. See the section on [[Slots]] for more.
619
+
620
+ ==== Built-in Constants ====
621
+
622
+ Purple Shoes also has a handful of built-in constants which may prove useful if you
623
+ are trying to sniff out what release of Purple Shoes is running.
624
+
625
+ '''DIR''' is a full path of `purple_shoes/lib`.
626
+
627
+ '''COLORS''' is a complete list of colors available to the app.
628
+
629
+ '''FONTS''' is a complete list of fonts available to the app.
630
+
631
+ '''VERSION''' is a Purple Shoes version.
632
+
633
+ {{{
634
+ Shoes.app do
635
+ para VERSION
636
+ para fg(DIR, red)
637
+ image File.join(DIR, '../static/gshoes-icon.png')
638
+ para fg(FONTS.join(', '), green)
639
+ para COLORS.map{|k, v| [k, v]}
640
+ end
641
+ }}}
642
+
643
+ === alert(message: a string, :block => true or false, title: a string) » nil ===
644
+
645
+ Pops up a window containing a short message.
646
+
647
+ {{{
648
+ #!ruby
649
+ alert "I'm afraid I must interject!"
650
+ }}}
651
+
652
+ Please use alerts sparingly, as they are incredibly annoying! If you are using
653
+ alerts to show messages to help you debug your program, try checking out the
654
+ standard Ruby method `puts` or `p` methods.
655
+
656
+ If you want to make alert() thread safe, i.e. unblock main thread, use `:block => false` option.
657
+ If you want to change window title, use `:title => a string` option.
658
+
659
+ === ask(message: a string) » a string ===
660
+
661
+ Pops up a window and asks a question. For example, you may want to ask someone
662
+ their name.
663
+
664
+ {{{
665
+ #!ruby
666
+ if name = ask("Please, enter your name:")
667
+ Shoes.app{para "Welcome, #{name}!"}
668
+ end
669
+ }}}
670
+
671
+ When the above script is run, the person at the computer will see a window with
672
+ a blank box for entering their name. The name will then be saved in the `name`
673
+ variable.
674
+
675
+ === ask_color(title: a string) » a RGB array ===
676
+
677
+ Pops up a color picker window. The program will wait for a color to be picked,
678
+ then gives you back a Color object. See the `Color` help for some ways you can
679
+ use this color.
680
+
681
+ {{{
682
+ #!ruby
683
+ backcolor = ask_color "Pick a background"
684
+ Shoes.app do
685
+ background backcolor
686
+ end
687
+ }}}
688
+
689
+ === ask_open_file() » a string ===
690
+
691
+ Pops up an "Open file..." window. It's the standard window which shows all of
692
+ your folders and lets you select a file to open. Hands you back the name of the
693
+ file.
694
+
695
+ {{{
696
+ #!ruby
697
+ filename = ask_open_file
698
+ Shoes.app do
699
+ para File.read(filename)
700
+ end
701
+ }}}
702
+
703
+ === ask_save_file() » a string ===
704
+
705
+ Pops up a "Save file..." window, similiar to `ask_open_file`, described
706
+ previously.
707
+
708
+ {{{
709
+ #!ruby
710
+ save_as = ask_save_file
711
+ Shoes.app do
712
+ para save_as
713
+ end
714
+ }}}
715
+
716
+ === ask_open_folder() » a string ===
717
+
718
+ Pops up an "Open folder..." window. It's the standard window which shows all of
719
+ your folders and lets you select a folder to open. Hands you back the name of
720
+ the folder.
721
+
722
+ {{{
723
+ #!ruby
724
+ folder = ask_open_folder
725
+ Shoes.app do
726
+ para Dir.entries(folder)
727
+ end
728
+ }}}
729
+
730
+ === ask_save_folder() » a string ===
731
+
732
+ Pops up a "Save folder..." window, similiar to `ask_open_folder`, described
733
+ previously.
734
+
735
+ {{{
736
+ #!ruby
737
+ save_to = ask_save_folder
738
+ Shoes.app do
739
+ para save_to
740
+ end
741
+ }}}
742
+
743
+
744
+ === confirm(question: a string) » true or false ===
745
+
746
+ Pops up a yes-or-no question. If the person at the computer, clicks '''yes''',
747
+ you'll get back a `true`. If not, you'll get back `false`.
748
+
749
+ {{{
750
+ #!ruby
751
+ if confirm("Draw a circle?")
752
+ Shoes.app{ oval top: 0, left: 0, radius: 50 }
753
+ end
754
+ }}}
755
+
756
+ === exit() ===
757
+
758
+ Stops your program. Call this anytime you want to suddenly call it quits.
759
+
760
+ '''PLEASE NOTE:''' If you need to use Ruby's own `exit` method (like in a
761
+ forked Ruby process,) call `Kernel.exit`.
762
+
763
+ === font(message: a string) » an array of font family names ===
764
+
765
+ Loads a TrueType (or other type of font) from a file. While TrueType is
766
+ supported by all platforms, your platform may support other types of fonts.
767
+ Shoes uses each operating system's built-in font system to make this work.
768
+
769
+ '''Note:''' Purple Shoes doesn't support font method so far.
770
+
771
+ Here's a rough idea of what fonts work on which platforms:
772
+
773
+ * Bitmap fonts (.bdf, .pcf, .snf) - Linux
774
+ * Font resource (.fon) - Windows
775
+ * Windows bitmap font file (.fnt) - Linux, Windows
776
+ * PostScript OpenType font (.otf) - Mac OS X, Linux, Windows
777
+ * Type1 multiple master (.mmm) - Windows
778
+ * Type1 font bits (.pfb) - Linux, Windows
779
+ * Type1 font metrics (.pfm) - Linux, Windows
780
+ * TrueType font (.ttf) - Mac OS X, Linux, Windows
781
+ * TrueType collection (.ttc) - Mac OS X, Linux, Windows
782
+
783
+ If the font is properly loaded, you'll get back an array of font names found in
784
+ the file. Otherwise, `nil` is returned if no fonts were found in the file.
785
+
786
+ Also of interest: the `Shoes::FONTS` constant is a complete list of fonts
787
+ available to you on this platform. You can check for a certain font by using
788
+ `include?`.
789
+
790
+ {{{
791
+ if Shoes::FONTS.include? "Coolvetica"
792
+ alert "Coolvetica is available on this system."
793
+ else
794
+ alert "You do not have the Coolvetica font."
795
+ end
796
+ }}}
797
+
798
+ If you have trouble with fonts showing up, make sure your app loads the font
799
+ before it is used. Especially on OS X, if fonts are used before they are
800
+ loaded, the font cache will tend to ignore loaded fonts.
801
+
802
+ === gradient(color1, color2) » a range of RGB array ===
803
+
804
+ Builds a linear gradient from two colors. For each color, you may pass in
805
+ a color/rgb method or a string describing the color. The `gradient(green, red)` is
806
+ the same as `green..red` for example. Also possible to use different kind of args
807
+ like this: `gradient(green, '#FA3')`
808
+
809
+ {{{
810
+ Shoes.app do
811
+ oval 100, 100, 100,
812
+ fill: gradient(green, '#FA3'), angle: 45
813
+ end
814
+ }}}
815
+
816
+ === gray(the numbers: darkness, alpha) » a RGB array ===
817
+
818
+ Create a grayscale color from a level of darkness and, optionally, an alpha
819
+ level.
820
+
821
+ {{{
822
+ Shoes.app do
823
+ nostroke
824
+ 11.times do |i|
825
+ y = x = 50 + 10 * i
826
+ r = 200 - 10 * i
827
+ oval x, y, r, fill: gray(1-i*0.1)
828
+ end
829
+ end
830
+ }}}
831
+
832
+ === rgb(red, green, blue, alpha) » an array of decimal numbers ===
833
+
834
+ Create a color from red, green and blue components. An alpha level (indicating
835
+ transparency) can also be added, optionally.
836
+
837
+ When passing in a whole number, use values from 0 to 255.
838
+
839
+ {{{
840
+ Shoes.app do
841
+ blueviolet = rgb(138, 43, 226, 0.5)
842
+ darkgreen = rgb(0, 100, 0, 0.5)
843
+ oval 100, 100, 100,
844
+ fill: [blueviolet, darkgreen].sample(1)
845
+ end
846
+ }}}
847
+
848
+ Or, use a decimal number from 0.0 to 1.0.
849
+
850
+ {{{
851
+ Shoes.app do
852
+ blueviolet = rgb(0.54, 0.17, 0.89)
853
+ darkgreen = rgb(0, 0.4, 0)
854
+ oval 100, 100, 100,
855
+ fill: [blueviolet, darkgreen].sample(1)
856
+ end
857
+ }}}
858
+
859
+ == The App Object ==
860
+
861
+ An App is a single window running code at a URL. When you switch URLs, a new
862
+ App object is created and filled up with stacks, flows and other Purple Shoes
863
+ elements.
864
+
865
+ The App is the window itself. Which may be closed or cleared and filled with
866
+ new elements. !{:margin_left => 100}../snapshots/sample46.png!
867
+
868
+ The App itself, in slot/box terminology, is a flow. See the ''Slots'' section
869
+ for more, but this just means that any elements placed directly at the
870
+ top-level will flow.
871
+
872
+ === Shoes.app(styles) { ... } » Shoes::App ===
873
+
874
+ Starts up a Purple Shoes app window. This is the starting place for making a Purple
875
+ Shoes program. Inside the block, you fill the window with various Purple Shoes
876
+ elements (buttons, artwork, etc.) and, outside the block, you use the `styles` to
877
+ describe how big the window is. Perhaps also the name of the app.
878
+
879
+ {{{
880
+ #!ruby
881
+ Shoes.app title: "White Circle",
882
+ width: 200, height: 200 do
883
+ background black
884
+ fill white
885
+ oval top: 20, left: 20, radius: 160
886
+ end
887
+ }}}
888
+
889
+ In the case above, a small window is built. 200 pixels by 200 pixels.
890
+ And, inside the window, two elements: a black background and a
891
+ white circle.
892
+
893
+ Once an app is created, it is added to the [[App.Shoes.APPS]] list. If you
894
+ want an app to spawn more windows, see the [[Element.window]] method and the
895
+ [[Element.dialog]] method.
896
+
897
+ === Shoes.APPS() » An array of Shoes::App objects ===
898
+
899
+ Builds a complete list of all the Purple Shoes apps that are open right now. Once an
900
+ app is closed, it is removed from the list. Yes, you can run many apps at once
901
+ in Purple Shoes. It's completely encouraged.
902
+
903
+ {{{
904
+ Shoes.app do
905
+ button('Open a new app'){Shoes.app{}}
906
+ button('Print Shoes.APPS'){p Shoes.APPS}
907
+ end
908
+ }}}
909
+
910
+ === clipboard() » a string ===
911
+
912
+ Returns a string containing all of the text that's on the system clipboard.
913
+ This is the global clipboard that every program on the computer cuts and pastes
914
+ into.
915
+
916
+ === clipboard = a string ===
917
+
918
+ Stores `a string` of text in the system clipboard.
919
+
920
+ === close() ===
921
+
922
+ Closes the app window. If multiple windows are open and you want to close the
923
+ entire application, use the built-in method `exit`.
924
+
925
+ {{{
926
+ Shoes.app do
927
+ para 'hello'
928
+ button 'spawn' do
929
+ Shoes.app do
930
+ para 'hello'
931
+ button('close: close this window only'){close}
932
+ button('exit: quit Purple Shoes'){exit}
933
+ end
934
+ end
935
+ button('close: close this window only'){close}
936
+ button('exit: quit Purple Shoes'){exit}
937
+ end
938
+ }}}
939
+
940
+ === download(url: a string, styles) ===
941
+
942
+ Starts a download thread (much like XMLHttpRequest, if you're familiar with
943
+ JavaScript.) This method returns immediately and runs the download in the
944
+ background. Each download thread also fires `start`, `progress` and `finish`
945
+ events. You can send the download to a file or just get back a string (in the
946
+ `finish` event.)
947
+
948
+ If you attach a block to a download, it'll get called as the `finish` event.
949
+
950
+ {{{
951
+ Shoes.app do
952
+ stack do
953
+ title "Searching Google", size: 16
954
+ @status = para "One moment..."
955
+
956
+ download "http://is.gd/bXTVY7" do |goog|
957
+ @status.text = "Headers: #{goog.meta}"
958
+ end
959
+ end
960
+ end
961
+ }}}
962
+
963
+ This example is truly the simplest form of `download`:
964
+ pulling some web data down into memory and handling it once it's done.
965
+
966
+ Another simple use of `download` is to save some web data to a file, using the
967
+ `:save` style.
968
+
969
+ {{{
970
+ Shoes.app do
971
+ stack do
972
+ title "Downloading Google image", size: 16
973
+ @status = para "One moment..."
974
+
975
+ download "http://is.gd/GVAGF7",
976
+ :save => "nasa50th.gif" do
977
+ @status.text = "Okay, is downloaded."
978
+ image "nasa50th.gif", top: 100
979
+ end
980
+ end
981
+ end
982
+ }}}
983
+
984
+ If you need to send certain headers or actions to the web server, you can use
985
+ the `:method`, `:headers` and `:body` styles to customize the HTTP request.
986
+ (And, if you need to go beyond these, you can always break out Ruby's OpenURI
987
+ class.)
988
+
989
+ {{{
990
+ #!ruby
991
+ # Not yet available
992
+ Shoes.app do
993
+ stack do
994
+ title "GET Google", size: 16
995
+ @status = para "One moment..."
996
+
997
+ download "http://is.gd/bXTVY7",
998
+ :method => "GET" do |dump|
999
+ @status.text = dump.response.body
1000
+ end
1001
+ end
1002
+ end
1003
+ }}}
1004
+
1005
+ As you can see from the above example, Shoes makes use of the "GET" method to
1006
+ query google's search engine.
1007
+
1008
+ '''Note:''' Purple Shoes doesn't support the `:method`, `:headers` and `:body` styles.
1009
+
1010
+ {{{
1011
+ include Hpricot
1012
+ Shoes.app do
1013
+ status = para "One moment..."
1014
+ download 'http://is.gd/BatiRt' do |dl|
1015
+ samples = []
1016
+ Hpricot(dl).inner_text.each_line do |line|
1017
+ samples.push($1) if line =~ /(sample.*\.rb)/
1018
+ end
1019
+ status.text = samples.join(', ')
1020
+ flush
1021
+ end
1022
+ end
1023
+ }}}
1024
+
1025
+ As you can see from the above example, Purple Shoes includes the Hpricot
1026
+ library for parsing HTML.
1027
+
1028
+ '''Note:''' Windows platform only so far.
1029
+
1030
+ === location() » a string ===
1031
+
1032
+ Gets a string containing the URL of the current app.
1033
+
1034
+ === mouse() » an array of numbers: button, left, top ===
1035
+
1036
+ Identifies the mouse cursor's location, along with which button is being
1037
+ pressed.
1038
+
1039
+ {{{
1040
+ #!ruby
1041
+ Shoes.app do
1042
+ @p = para
1043
+ animate do
1044
+ button, left, top = self.mouse
1045
+ @p.replace "mouse: #{button}, #{left}, #{top}"
1046
+ end
1047
+ end
1048
+ }}}
1049
+
1050
+ === owner() » Shoes::App ===
1051
+
1052
+ Gets the app which launched this app. In most cases, this will be `nil`. But
1053
+ if this app was launched using the [[Element.window]] method, the owner will be
1054
+ the app which called `window`.
1055
+
1056
+ === started?() » true or false ===
1057
+
1058
+ Has the window been fully constructed and displayed? This is useful for
1059
+ threaded code which may try to use the window before it is completely built.
1060
+ (Also see the `start` event which fires once the window is open.)
1061
+
1062
+ '''Note:''' Purple Shoes doesn't support started? method so far.
1063
+
1064
+ === visit(url: a string) ===
1065
+
1066
+ Changes the location, in order to view a different Shoes URL.
1067
+
1068
+ Absolute URLs (such as http://google.com) are okay, but Purple Shoes will be expecting
1069
+ a Purple Shoes application to be at that address. (So, google.com won't work, as it's
1070
+ an HTML app.)
1071
+
1072
+ == The Styles Master List ==
1073
+
1074
+ You want to mess with the look of things? Well, throughout Purple Shoes, styles are
1075
+ used to change the way elements appear. In some cases, you can even style an
1076
+ entire class of elements. (Like giving all links without an underline.)
1077
+
1078
+ Styles are easy to spot. They usually show up when the element is created.
1079
+
1080
+ {{{
1081
+ Shoes.app title: "A Styling Sample" do
1082
+ para 'Purple Shoes', align: 'center', size: 50
1083
+ end
1084
+ }}}
1085
+
1086
+ Here we've got a `:title` style on the app. And on the paragraph inside the
1087
+ app, a center `:align` style and 50 font `:size` style.
1088
+
1089
+ The style hash can also be changed by using the [[Common.style]] method,
1090
+ available on every element and slot.
1091
+
1092
+ '''Note:''' Purple Shoes can change style hash on Shape element only so far.
1093
+
1094
+ {{{
1095
+ Shoes.app title: "A Styling Sample" do
1096
+ choose =
1097
+ lambda{[red, blue, green, yellow].sample}
1098
+ s = star 100, 50, 30, 200, 180, strokewidth: 5
1099
+ button 'change colors' do
1100
+ s.style stroke: choose.call, fill: choose.call
1101
+ end
1102
+ end
1103
+ }}}
1104
+
1105
+ Most styles can also be set by calling them as methods. (I'd use the manual
1106
+ search to find the method.)
1107
+
1108
+ '''Note:''' Purple Shoes doesn't support them as methods.
1109
+
1110
+ {{{
1111
+ # Not yet available
1112
+ Shoes.app title: "A Styling Sample" do
1113
+ choose =
1114
+ lambda{[red, blue, green, yellow].sample}
1115
+ s = star 100, 50, 30, 200, 180, strokewidth: 5
1116
+ button 'change colors' do
1117
+ s.stroke = choose.call; s.fill = choose.call
1118
+ end
1119
+ end
1120
+ }}}
1121
+
1122
+ Rather than making you plow through the whole manual to figure out what styles
1123
+ go where, this helpful page speeds through every style in Purple Shoes and suggests
1124
+ where that style is used.
1125
+
1126
+ === :align » a string ===
1127
+
1128
+ For: ''banner, caption, inscription, para, subtitle, tagline, title''
1129
+
1130
+ The alignment of the text. It is either:
1131
+
1132
+ * "left" - Align the text to the left.
1133
+ * "center" - Align the text in the center.
1134
+ * "right" - Align the text to the right.
1135
+
1136
+ === :angle » a number ===
1137
+
1138
+ For: ''background, border, line, oval, rect, shape, star''.
1139
+
1140
+ The angle at which to apply a gradient. Normally, gradient colors range from
1141
+ top to bottom. If the `:angle` is set to 90, the gradient will rotate 90
1142
+ degrees counter-clockwise and the gradient will go from left to right.
1143
+
1144
+ === :attach » a slot or element ===
1145
+
1146
+ For: ''flow, stack''.
1147
+
1148
+ Pins a slot relative to another slot or element. Also, one may write `:attach
1149
+ => Window` to position the slot at the window's top, left corner. Taking this
1150
+ a bit further, the style `:top => 10, :left => 10, :attach => Window` would
1151
+ place the slot at (10, 10) in the window's coordinates.
1152
+
1153
+ If a slot is attached to an element that moves, the slot will move with it. If
1154
+ the attachment is reset to `nil`, the slot will flow in with the other objects
1155
+ that surround, as normal.
1156
+
1157
+ '''Note:''' Purple Shoes doesn't support `:attach` style.
1158
+
1159
+ === :autoplay » true or false ===
1160
+
1161
+ For: ''video''.
1162
+
1163
+ Should this video begin playing after it appears? If set to `true`, the video
1164
+ will start without asking the user.
1165
+
1166
+ '''Note:''' Purple Shoes doesn't support ''video''.
1167
+
1168
+ === :back » true or false ===
1169
+
1170
+ For: ''shapes, image, textblocks''.
1171
+
1172
+ Comes to the back of the other elements.
1173
+
1174
+ {{{
1175
+ Shoes.app do
1176
+ rect 100, 100, 100, 100, fill: green
1177
+ rect 120, 120, 100, 100, fill: yellow
1178
+ para 'hello', left: 150, top: 150, front: true
1179
+ oval 150, 150, 100, 100, fill: red
1180
+ oval 180, 180, 100, 100, fill: gray, back: true
1181
+ end
1182
+ }}}
1183
+
1184
+ === :bottom » a number ===
1185
+
1186
+ For: ''all slots and elements''.
1187
+
1188
+ Sets the pixel coordinate of an element's lower edge. The edge is placed
1189
+ relative to its container's lower edge. So, `:bottom => 0` will align the
1190
+ element so that its bottom edge and the bottom edge of its slot touch.
1191
+
1192
+ '''Note:''' Purple Shoes doesn't support `:bottom` style.
1193
+
1194
+ === :cap » :curve or :rect or :project ===
1195
+
1196
+ For: ''arc, line, shape''.
1197
+
1198
+ Sets the shape of the line endpoint, whether curved or square. See the
1199
+ [[Art.cap]] method for more explanation.
1200
+
1201
+ === :center » true or false ===
1202
+
1203
+ For: ''arc, image, oval, rect, shape''.
1204
+
1205
+ Indicates whether the `:top` and `:left` coordinates refer to the center of the
1206
+ shape or not. If set to `true`, this is similar to setting the
1207
+ [[Art.transform]] method to `:center`.
1208
+
1209
+ '''Note:''' Purple Shoes doesn't support `:center` style.
1210
+
1211
+ === :change » a proc ===
1212
+
1213
+ For: ''edit_box, edit_line, list_box''.
1214
+
1215
+ The `change` event handler is stored in this style. See the [[EditBox.change]]
1216
+ method for the edit_box, as an example.
1217
+
1218
+ === :checked » true or false ===
1219
+
1220
+ For: ''check, radio''.
1221
+
1222
+ Is this checkbox or radio button checked? If set to `true`, the box is
1223
+ checked. Also see the [[Check.checked=]] method.
1224
+
1225
+ === :choose » a string ===
1226
+
1227
+ For: ''list_box''.
1228
+
1229
+ Sets the currently chosen item in the list. More information at
1230
+ [[ListBox.choose]].
1231
+
1232
+ === :click » a proc ===
1233
+
1234
+ For: ''arc, arrow, button, check, flow, image,
1235
+ line, link, oval, radio, rect, shape, stack, star''.
1236
+
1237
+ The `click` event handler is stored in this style. See the [[Events.click]]
1238
+ method for a description.
1239
+
1240
+ === :curve » a number ===
1241
+
1242
+ For: ''background, border, rect''.
1243
+
1244
+ The radius of curved corners on each of these rectangular elements. As an
1245
+ example, if this is set to 6, the corners of the rectangle are given a curve
1246
+ with a 6-pixel radius.
1247
+
1248
+ === :displace_left » a number ===
1249
+
1250
+ For: ''all slots and elements''.
1251
+
1252
+ Moves a shape, text block or any other kind of object to the left or right. A
1253
+ positive number displaces to the right by the given number of pixels; a
1254
+ negative number displaces to the left. Displacing an object doesn't effect the
1255
+ actual layout of the page. Before using this style, be sure to read the
1256
+ [[Position.displace]] docs, since its behavior can be a bit surprising.
1257
+
1258
+ '''Note:''' Purple Shoes doesn't support `:displace_left` style.
1259
+
1260
+ === :displace_top » a number ===
1261
+
1262
+ For: ''all slots and elements''.
1263
+
1264
+ Moves a shape, text block or any other kind of object up or down. A positive
1265
+ number moves the object down by this number of pixels; a negative number moves
1266
+ it up. Displacing doesn't effect the actual layout of the page or the object's
1267
+ true coordinates. Read the [[Position.displace]] docs, since its behavior can
1268
+ be a bit surprising.
1269
+
1270
+ '''Note:''' Purple Shoes doesn't support `:displace_top` style.
1271
+
1272
+ === :emphasis » a string ===
1273
+
1274
+ For: ''banner, caption, inscription, para, span, subtitle, tagline, title''.
1275
+
1276
+ Styles the text with an emphasis (commonly italicized.)
1277
+
1278
+ This style recognizes three possible settings:
1279
+
1280
+ * "normal" - the font is upright.
1281
+ * "oblique" - the font is slanted, but in a roman style.
1282
+ * "italic" - the font is slanted in an italic style.
1283
+
1284
+ === :family » a string ===
1285
+
1286
+ For: ''banner, caption, inscription, para, span, subtitle, tagline, title''.
1287
+
1288
+ Styles the text with a given font family. The string should contain the family
1289
+ name or a comma-separated list of families.
1290
+
1291
+ === :fill » a hex code, a rgb array or a range of either ===
1292
+
1293
+ For: ''background, banner, border, caption, inscription, para, line, oval,
1294
+ rect, shape, star, subtitle, tagline, title''.
1295
+
1296
+ The color of the background pen. For shapes, this is the fill color, the paint
1297
+ inside the shape. For textblock, this color is painted in the background
1298
+ (as if marked with a highlighter pen.)
1299
+
1300
+ === :font » a string ===
1301
+
1302
+ For: ''banner, caption, inscription, para, subtitle, tagline, title''.
1303
+
1304
+ Styles the text with a font description. The string is pretty flexible, but
1305
+ can take the form "[FAMILY-LIST] [STYLE-OPTIONS] [SIZE]", where FAMILY-LIST is
1306
+ a comma separated list of families optionally terminated by a comma,
1307
+ STYLE_OPTIONS is a whitespace separated list of words where each WORD describes
1308
+ one of style, variant, weight, stretch, or gravity, and SIZE is a decimal
1309
+ number (size in points) or optionally followed by the unit modifier "px" for
1310
+ absolute size. Any one of the options may be absent. If FAMILY-LIST is absent,
1311
+ then the default font family (Arial) will be used.
1312
+
1313
+ === :front » true or false ===
1314
+
1315
+ For: ''shapes, image, textblocks''.
1316
+
1317
+ Comes to the front of the other elements.
1318
+
1319
+ === :group » a string ===
1320
+
1321
+ For: ''radio''.
1322
+
1323
+ Indicates what group a radio button belongs to. Without this setting, radio
1324
+ buttons are grouped together with other radio buttons in their immediate slot.
1325
+ "Grouping" radio buttons doesn't mean they'll be grouped next to each other on
1326
+ the screen. It means that only one radio button from the group can be selected
1327
+ at a time.
1328
+
1329
+ By giving this style a string, the radio button will be grouped with other
1330
+ radio buttons that have the same group name.
1331
+
1332
+ === :height » a number ===
1333
+
1334
+ For: ''all slots and elements''.
1335
+
1336
+ Sets the pixel height of this object. If the number is a decimal number, the
1337
+ height becomes a percentage of its parent's height (with 0.0 being 0% and 1.0
1338
+ being 100%.)
1339
+
1340
+ === :hidden » true or false ===
1341
+
1342
+ For: ''all slots and elements''.
1343
+
1344
+ Hides or shows this object. Any object with `hidden: true` are not
1345
+ displayed on the screen. Neither are its children.
1346
+
1347
+ {{{
1348
+ Shoes.app do
1349
+ slot = stack hidden: true do
1350
+ title 'hello'
1351
+ flow do
1352
+ image File.join DIR, '../samples/loogink.png'
1353
+ end
1354
+ para link('Go go!'){alert 'hi'}
1355
+ end
1356
+ timer(2){slot.show}
1357
+ timer(5){slot.hide}
1358
+ end
1359
+ }}}
1360
+
1361
+ '''Note:''' Purple Shoes supports `:hidden` style for only slots, shapes, textblocks
1362
+ and images so far.
1363
+
1364
+ === :inner » a number ===
1365
+
1366
+ For: ''star''.
1367
+
1368
+ The size of the inner radius (in pixels.) The inner radius describes the solid
1369
+ circle within the star where the points begin to separate.
1370
+
1371
+ === :items » an array ===
1372
+
1373
+ For: ''list_box''.
1374
+
1375
+ The list of selections in the list box. See the [[Element.list_box]] method
1376
+ for an example.
1377
+
1378
+ === :justify » true or false ===
1379
+
1380
+ For: ''banner, caption, inscription, para, subtitle, tagline, title''.
1381
+
1382
+ Evenly spaces the text horizontally.
1383
+
1384
+ === :kerning » a number ===
1385
+
1386
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1387
+ strong, sub, sup, subtitle, tagline, title''.
1388
+
1389
+ Adds to the natural spacing between letters, in pixels.
1390
+
1391
+ '''Note:''' Purple Shoes doesn't support `:kerning` style.
1392
+
1393
+ === :leading » a number ===
1394
+
1395
+ For: ''banner, caption, inscription, para, subtitle, tagline, title''.
1396
+
1397
+ Sets the spacing between lines in a text block. Defaults to 4 pixels.
1398
+
1399
+ === :left » a number ===
1400
+
1401
+ For: ''all slots and elements''.
1402
+
1403
+ Sets the left coordinate of this object to a specific pixel. Setting `left: 10`
1404
+ places the object's left edge ten pixels away from the left edge of the
1405
+ slot containing it. If this style is left unset (or set to `nil`,) the object
1406
+ will flow in with the other objects surrounding it.
1407
+
1408
+ === :margin » a number or an array of four numbers ===
1409
+
1410
+ For: ''all slots and elements''.
1411
+
1412
+ Margins space an element out from its surroundings. Each element has a left,
1413
+ top, right, and bottom margin. If the `:margin` style is set to a single
1414
+ number, the spacing around the element uniformly matches that number. In other
1415
+ words, if `margin: 8` is set, all the margins around the element are set to
1416
+ eight pixels in length.
1417
+
1418
+ This style can also be given an array of four numbers in the form `[left, top,
1419
+ right, bottom]`.
1420
+
1421
+ === :margin_bottom » a number ===
1422
+
1423
+ For: ''all slots and elements''.
1424
+
1425
+ Sets the bottom margin of the element to a specific pixel size.
1426
+
1427
+ === :margin_left » a number ===
1428
+
1429
+ For: ''all slots and elements''.
1430
+
1431
+ Sets the left margin of the element to a specific pixel size.
1432
+
1433
+ === :margin_right » a number ===
1434
+
1435
+ For: ''all slots and elements''.
1436
+
1437
+ Sets the right margin of the element to a specific pixel size.
1438
+
1439
+ === :margin_top » a number ===
1440
+
1441
+ For: ''all slots and elements''.
1442
+
1443
+ Sets the top margin of the element to a specific pixel size.
1444
+
1445
+ === :outer » a number ===
1446
+
1447
+ For: ''star''.
1448
+
1449
+ Sets the outer radius (half of the ''total'' width) of the star, in pixels.
1450
+
1451
+ === :points » a number ===
1452
+
1453
+ For: ''star''.
1454
+
1455
+ How many points does this star have? A style of `points: 5` creates a
1456
+ five-pointed star.
1457
+
1458
+ === :radius » a number ===
1459
+
1460
+ For: ''oval''.
1461
+
1462
+ Sets the radius (half of the diameter or total width) for each of these
1463
+ elements. Setting this is equivalent to setting both `:width` and `:height` to
1464
+ double this number.
1465
+
1466
+ === :right » a number ===
1467
+
1468
+ For: ''all slots and elements''.
1469
+
1470
+ Sets the pixel coordinate of an element's right edge. The edge is placed
1471
+ relative to its container's rightmost edge. So, `:right => 0` will align the
1472
+ element so that its own right edge and the right edge of its slot touch.
1473
+ Whereas `:right => 20` will position the right edge of the element off to the
1474
+ left of its slot's right edge by twenty pixels.
1475
+
1476
+ '''Note:''' Purple Shoes doesn't support `:right` style.
1477
+
1478
+ === :rise » a number ===
1479
+
1480
+ For: ''banner, caption, inscription, para, span, subtitle, tagline, title''.
1481
+
1482
+ Lifts or plunges the font baseline for some text. For example, a
1483
+ [[Element.sup]] has a `:rise` of 10 pixels. Conversely, the [[Element.sub]]
1484
+ element has a `:rise` of -10 pixels.
1485
+
1486
+ === :scroll » true or false ===
1487
+
1488
+ For: ''flow, stack''.
1489
+
1490
+ Establishes this slot as a scrolling slot. If `:scroll => true` is set, the
1491
+ slot will show a scrollbar if any of its contents go past its height. The
1492
+ scrollbar will appear and disappear as needed. It will also appear inside the
1493
+ width of the slot, meaning the slot's width will never change, regardless of
1494
+ whether there is a scrollbar or not.
1495
+
1496
+ '''Note:''' Purple Shoes has restrictions. `:scroll` style is just a trial so far.
1497
+
1498
+ * common Slot instance methods, i.e. clear, hide, etc., don't work well
1499
+ * doesn't manage any mouse events
1500
+ * need to write `flush` explicitly
1501
+
1502
+ {{{
1503
+ Shoes.app do
1504
+ s = stack left: 100, top: 50, width: 300,
1505
+ height: 100, scroll: true do
1506
+ background gold
1507
+ image File.join(DIR, '../samples/loogink.png')
1508
+ 10.times{para 'hello'}
1509
+ flush
1510
+ end
1511
+ end
1512
+ }}}
1513
+
1514
+ === :secret » true or false ===
1515
+
1516
+ For: ''ask, edit_line''.
1517
+
1518
+ Used for password fields, this setting keeps any characters typed in from
1519
+ becoming visible on the screen. Instead, a replacement character (such as an
1520
+ asterisk) is show for each letter typed.
1521
+
1522
+ === :size » a number ===
1523
+
1524
+ For: ''banner, caption, inscription, para, span, subtitle, tagline, title''.
1525
+
1526
+ Sets the pixel size for the font used inside this text block.
1527
+
1528
+ Font size may also be augmented, through use of the following strings:
1529
+
1530
+ * "xx-small" - 57% of present size.
1531
+ * "x-small" - 64% of present size.
1532
+ * "small" - 83% of present size.
1533
+ * "medium" - no change in size.
1534
+ * "large" - 120% of present size.
1535
+ * "x-large" - 143% of present size.
1536
+ * "xx-large" - 173% of present size.
1537
+
1538
+ === :state » a string ===
1539
+
1540
+ For: ''button, check, edit_box, edit_line, list_box, radio''.
1541
+
1542
+ The `:state` style is for disabling or locking certain controls, if you don't
1543
+ want them to be edited.
1544
+
1545
+ Here are the possible style settings:
1546
+
1547
+ * nil - the control is active and editable.
1548
+ * "readonly" - the control is active but cannot be edited.
1549
+ * "disabled" - the control is not active (grayed out) and cannot be edited.
1550
+
1551
+ === :stretch » a string ===
1552
+
1553
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1554
+ strong, sub, sup, subtitle, tagline, title''.
1555
+
1556
+ Sets the font stretching used for a text object.
1557
+
1558
+ Possible settings are:
1559
+
1560
+ * "condensed" - a smaller width of letters.
1561
+ * "normal" - the standard width of letters.
1562
+ * "expanded" - a larger width of letters.
1563
+
1564
+ '''Note:''' Purple Shoes doesn't support `:stretch` style.
1565
+
1566
+ === :strikecolor » a RGB array ===
1567
+
1568
+ For: ''banner, caption, inscription, para, span, subtitle, tagline, title''.
1569
+
1570
+ The color used to paint any lines stricken through this text.
1571
+
1572
+ === :strikethrough » a string ===
1573
+
1574
+ For: ''banner, caption, inscription, para, span, subtitle, tagline, title''.
1575
+
1576
+ Is this text stricken through? Two options here:
1577
+
1578
+ * "none" - no strikethrough
1579
+ * "single" - a single-line strikethrough.
1580
+
1581
+ === :stroke » a hex code, a rgb array or a range of either ===
1582
+
1583
+ For: ''background, banner, border, caption, inscription, para, line, oval,
1584
+ rect, shape, star, subtitle, tagline, title''.
1585
+
1586
+ The color of the foreground pen. In the case of shapes, this is the color the
1587
+ lines are drawn with. For textblock, the letters are printed in this color.
1588
+
1589
+ === :strokewidth » a number ===
1590
+
1591
+ For: ''background, border, line, oval, rect, shape, star''.
1592
+
1593
+ The thickness of the stroke, in pixels, of the line defining each of these
1594
+ shapes. For example, the number two would set the strokewidth to 2 pixels.
1595
+
1596
+ === :text » a string ===
1597
+
1598
+ For: ''edit_box, edit_line''.
1599
+
1600
+ Sets the message displayed on the contents of edit_box or edit_line.
1601
+
1602
+ === :top » a number ===
1603
+
1604
+ For: ''all slots and elements''.
1605
+
1606
+ Sets the top coordinate for an object, relative to the top slot (window). If an
1607
+ object is set with `top: 40`, this means the object's top edge will be
1608
+ placed 40 pixels beneath the top edge of the top slot (window). If no
1609
+ `:top` style is given, the object is automatically placed in the natural flow
1610
+ of the slot it contains.
1611
+
1612
+ === :undercolor » a RGB array ===
1613
+
1614
+ For: ''banner, caption, inscription, para, span, subtitle, tagline, title''.
1615
+
1616
+ The color used to underline text.
1617
+
1618
+ === :underline » a string ===
1619
+
1620
+ For: ''banner, caption, inscription, para, span, subtitle, tagline, title''.
1621
+
1622
+ Dictates the style of underline used in the text.
1623
+
1624
+ The choices for this setting are:
1625
+
1626
+ * "none" - no underline at all.
1627
+ * "single" - a continuous underline.
1628
+ * "double" - two continuous parallel underlines.
1629
+ * "low" - a lower underline, beneath the font baseline. (This is generally recommended only for single characters, particularly when showing keyboard accelerators.)
1630
+ * "error" - a wavy underline, usually found indicating a misspelling.
1631
+
1632
+ === :variant » a string ===
1633
+
1634
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1635
+ strong, sub, sup, subtitle, tagline, title''.
1636
+
1637
+ Vary the font for a group of text. Two choices:
1638
+
1639
+ * "normal" - standard font.
1640
+ * "smallcaps" - font with the lower case characters replaced by smaller variants of the capital characters.
1641
+
1642
+ '''Note:''' Purple Shoes doesn't support `:variant` style.
1643
+
1644
+ === :weight » a string ===
1645
+
1646
+ For: ''banner, caption, inscription, para, span, subtitle, tagline, title''.
1647
+
1648
+ Set the boldness of the text. Commonly, this style is set to one of the
1649
+ following strings:
1650
+
1651
+ * "ultralight" - the ultralight weight (= 200)
1652
+ * "light" - the light weight (= 300)
1653
+ * "normal" - the default weight (= 400)
1654
+ * "semibold" - a weight intermediate between normal and bold (= 600)
1655
+ * "bold" - the bold weight (= 700)
1656
+ * "ultrabold" - the ultrabold weight (= 800)
1657
+ * "heavy" - the heavy weight (= 900)
1658
+
1659
+ However, you may also pass in the numerical weight directly.
1660
+
1661
+ === :width » a number ===
1662
+
1663
+ For: ''all slots and elements''.
1664
+
1665
+ Sets the pixel width for the element. If the number is a decimal, the width is
1666
+ converted to a percentage (with 0.0 being 0% and 1.0 being 100%.) A width of
1667
+ 100% means the object fills its parent slot.
1668
+
1669
+ === :wrap » a string ===
1670
+
1671
+ For: ''banner, caption, inscription, para, span, subtitle, tagline, title''.
1672
+
1673
+ How should the text wrap when it fills its width? Possible options are:
1674
+
1675
+ * "word" - Break lines at word breaks.
1676
+ * "char" - Break lines between characters, thus breaking some words.
1677
+ * "trim" - Cut the line off with an ellipsis if it goes too long.
1678
+
1679
+ == Classes List ==
1680
+
1681
+ There is a complete list of all the classes introduced by Purple Shoes.
1682
+
1683
+ Look at [[http://rdoc.info/github/ashbb/green_shoes/master/frames/file/README.md Green Shoes RDoc]].
1684
+
1685
+ == Colors List ==
1686
+
1687
+ The following list of colors can be used throughout Purple Shoes. As background
1688
+ colors or border colors. As stroke and fill colors. Most of these colors come
1689
+ from the X11 and HTML palettes.
1690
+
1691
+ All of these colors can be used by name. (So calling the `tomato` method from
1692
+ inside any slot will get you a nice reddish color.) Below each color, also
1693
+ find the exact numbers which can be used with the [[Built-in.rgb]] method.
1694
+
1695
+ {COLORS}
1696
+
1697
+ = Slots =
1698
+
1699
+ Slots are boxes used to lay out images, text and so on. The two most common
1700
+ slots are `stacks` and `flows`. Slots can also be referred to as "boxes" or
1701
+ "canvases" in Purple Shoes terminology.
1702
+
1703
+ Since the mouse wheel and PageUp and PageDown are so pervasive on every
1704
+ platform, vertical scrolling has really become the only overflow that matters.
1705
+ So, in Purple Shoes, just as on the web, width is generally fixed. While height goes
1706
+ on and on.
1707
+
1708
+ Now, you can also just use specific widths and heights for everything, if you
1709
+ want. That'll take some math, but everything could be perfect.
1710
+
1711
+ Generally, I'd suggest using stacks and flows. The idea here is that you want
1712
+ to fill up a certain width with things, then advance down the page, filling up
1713
+ further widths. You can think of these as being analogous to HTML's "block" and
1714
+ "inline" styles.
1715
+
1716
+ ==== Stacks ====
1717
+
1718
+ A stack is simply a vertical stack of elements. Each element in a stack is
1719
+ placed directly under the element preceding it.
1720
+
1721
+ A stack is also shaped like a box. So if a stack is given a width of 250, that
1722
+ stack is itself an element which is 250 pixels wide.
1723
+
1724
+ To create a new stack, use the [[Element.stack]] method, which is available
1725
+ inside any slot. So stacks can contain other stacks and flows.
1726
+
1727
+ ==== Flows ====
1728
+
1729
+ A flow will pack elements in as tightly as it can. A width will be filled, then
1730
+ will wrap beneath those elements. Text elements placed next to each other will
1731
+ appear as a single paragraph. Images and widgets will run together as a series.
1732
+
1733
+ Like the stack, a flow is a box. So stacks and flows can safely be embedded
1734
+ and, without respect to their contents, are identical. They just treat their
1735
+ contents differently.
1736
+
1737
+ Making a flow means calling the [[Element.flow]] method. Flows may contain
1738
+ other flows and stacks.
1739
+
1740
+ Last thing: The Purple Shoes window itself is a flow.
1741
+
1742
+ == Art for Slots ==
1743
+
1744
+ Each slot is like a canvas, a blank surface which can be covered with an
1745
+ assortment of colored shapes or gradients.
1746
+
1747
+ Many common shapes can be drawn with methods like `oval` and `rect`. You'll
1748
+ need to set up the paintbrush colors first, though.
1749
+
1750
+ The `stroke` command sets the line color. And the `fill` command sets the
1751
+ color used to paint inside the lines.
1752
+
1753
+ {{{
1754
+ #!ruby
1755
+ Shoes.app do
1756
+ stroke red
1757
+ fill blue
1758
+ oval top: 10, left: 10, radius: 100
1759
+ end
1760
+ }}}
1761
+
1762
+ That code gives you a blue pie with a red line around it. One-hundred pixels
1763
+ wide, placed just a few pixels southeast of the window's upper left corner.
1764
+
1765
+ The `blue` and `red` methods above are RGB array. See the section on
1766
+ Colors for more on how to mix colors.
1767
+
1768
+ ==== Inspiration from Processing and NodeBox ====
1769
+
1770
+ The artful methods generally come verbatim from NodeBox, a drawing kit for
1771
+ Python. In turn, NodeBox gets much of its ideas from Processing, a Java-like
1772
+ language for graphics and animation. I owe a great debt to the creators of
1773
+ these wonderful programs!
1774
+
1775
+ Purple Shoes does a few things differently from NodeBox and Processing. For example,
1776
+ Purple Shoes has different color methods, including having its own RGB array,
1777
+ though these are very similar to Processing's color methods. And Purple Shoes also
1778
+ allows images and gradients to be used for drawing lines and filling in shapes.
1779
+
1780
+ Shoes also borrows some animation ideas from Processing and will continue to
1781
+ closely consult Processing's methods as it expands.
1782
+
1783
+ === arc(left, top, width, height, angle1, angle2) » Shoes::Oval ===
1784
+
1785
+ Draws an arc shape (a section of an oval) at coordinates (left, top). This
1786
+ method just give you a bit more control than [[oval]], by offering the
1787
+ `:angle1` and `:angle2` styles. (In fact, you can mimick the `oval` method by
1788
+ setting `:angle1` to 0 and `:angle2` to `2*Math::PI`.)
1789
+
1790
+ {{{
1791
+ Shoes.app do
1792
+ fill yellow..green
1793
+ stroke red..blue
1794
+ strokewidth 10
1795
+ cap :curve
1796
+
1797
+ a = animate 12 do |i|
1798
+ @e.remove if @e
1799
+ r = i * (Math::PI * 0.01)
1800
+ @e = arc 100, 50, 180, 360, 0, r
1801
+ a.stop if r >= 2*Math::PI
1802
+ end
1803
+ end
1804
+ }}}
1805
+
1806
+ === arrow(left, top, width) » Shoes::Shape ===
1807
+
1808
+ Draws an arrow at coordinates (left, top) with a pixel `width`.
1809
+
1810
+ {{{
1811
+ Shoes.app do
1812
+ para 'An arrow shape:', left: 20, top: 10
1813
+ arrow 30, 40, 70
1814
+ end
1815
+ }}}
1816
+
1817
+ === cap(:curve or :rect or :project) » self ===
1818
+
1819
+ Sets the line cap, which is the shape at the end of every line you draw. If
1820
+ set to `:curve`, the end is rounded. The default is `:rect`, a line which ends
1821
+ abruptly flat. The `:project` cap is also fat, but sticks out a bit longer.
1822
+
1823
+ {{{
1824
+ Shoes.app do
1825
+ nofill
1826
+ strokewidth 20
1827
+ stroke green
1828
+ cap :curve
1829
+ line 100, 100, 300, 100
1830
+ line 100, 250, 300, 300
1831
+ cap :rect
1832
+ line 100, 150, 300, 150
1833
+ stroke blue
1834
+ cap :project
1835
+ line 100, 200, 300, 200
1836
+ line 200, 100, 200, 300
1837
+ strokewidth 1
1838
+ stroke red
1839
+ rect 100, 100, 200, 200
1840
+ end
1841
+ }}}
1842
+
1843
+ === fill(pattern) » pattern ===
1844
+
1845
+ Sets the fill bucket to a specific color (or pattern.) Patterns can be colors,
1846
+ gradients or images. So, once the fill bucket is set, you can draw shapes and
1847
+ they will be colored in with the pattern you've chosen.
1848
+
1849
+ To draw a star with an image pattern:
1850
+
1851
+ {{{
1852
+ #!ruby
1853
+ Shoes.app do
1854
+ fill File.join(DIR, "../static/gshoes-icon.png")
1855
+ star 200, 200, 5, 100, 50
1856
+ end
1857
+ }}}
1858
+
1859
+ To clear the fill bucket, use `nofill`. And to set the line color (the border
1860
+ of the star,) use the `stroke` method.
1861
+
1862
+ === nofill() » self ===
1863
+
1864
+ Blanks the fill color, so that any shapes drawn will not be filled in.
1865
+ Instead, shapes will have only a lining, leaving the middle transparent.
1866
+
1867
+ === nostroke() » self ===
1868
+
1869
+ Empties the line color. Shapes drawn will have no outer line. If `nofill` is
1870
+ also set, shapes drawn will not be visible.
1871
+
1872
+ === line(left, top, x2, y2) » Shoes::Line ===
1873
+
1874
+ Draws a line using the current line color (aka "stroke") starting at
1875
+ coordinates (left, top) and ending at coordinates (x2, y2).
1876
+
1877
+ === oval(left, top, radius) » Shoes::Oval ===
1878
+
1879
+ Draws a circular form at pixel coordinates (left, top) with a width and height
1880
+ of `radius` pixels. The line and fill colors are used to draw the shape. By
1881
+ default, the coordinates are for the oval's leftmost, top corner, but this can
1882
+ be changed by calling the [[Art.transform]] method or by using the `:center`
1883
+ style on the next method below.
1884
+
1885
+ {{{
1886
+ #!ruby
1887
+ Shoes.app do
1888
+ stroke blue
1889
+ strokewidth 4
1890
+ fill black
1891
+ oval 10, 10, 50
1892
+ end
1893
+ }}}
1894
+
1895
+ To draw an oval of varied proportions, you may also use the syntax: `oval(left, top, width, height)`.
1896
+
1897
+ === oval(styles) » Shoes::Oval ===
1898
+
1899
+ Draw circular form using a style hash. The following styles are supported:
1900
+
1901
+ * `top`: the y-coordinate for the oval pen.
1902
+ * `left`: the x-coordinate for the oval pen.
1903
+ * `radius`: the width and height of the circle.
1904
+ * `width`: a specific pixel width for the oval.
1905
+ * `height`: a specific pixel height for the oval.
1906
+ * `center`: do the coordinates specific the oval's center? (true or false)
1907
+
1908
+ These styles may also be altered using the `style` method on the Shape object.
1909
+
1910
+ '''Note:''' Purple Shoes doesn't support `center` style.
1911
+
1912
+ === rect(top, left, width, height) » Shoes::Rect ===
1913
+
1914
+ Draws a rectangle starting from coordinates (top, left) with dimensions of
1915
+ width x height.
1916
+
1917
+ As with all other shapes, the rectangle is drawn using the stroke and fill colors.
1918
+
1919
+ {{{
1920
+ #!ruby
1921
+ Shoes.app do
1922
+ stroke rgb(0.5, 0.5, 0.7)
1923
+ fill rgb(1.0, 1.0, 0.9)
1924
+ rect 10, 10, self.width - 20, self.height - 20
1925
+ end
1926
+ }}}
1927
+
1928
+ The above sample draws a rectangle which fills the area of its parent box,
1929
+ leaving a margin of 10 pixels around the edge. Also see the `background`
1930
+ method for a rectangle which defaults to filling its parent box.
1931
+
1932
+ === rect(styles) » Shoes::Rect ===
1933
+
1934
+ Draw a rectangle using a style hash. The following styles are supported:
1935
+
1936
+ * `top`: the y-coordinate for the rectangle.
1937
+ * `left`: the x-coordinate for the rectangle.
1938
+ * `curve`: the pixel radius of the rectangle's corners.
1939
+ * `width`: a specific pixel width for the rectangle.
1940
+ * `height`: a specific pixel height for the rectangle.
1941
+ * `center`: do the coordinates specific the rectangle's center? (true or false)
1942
+
1943
+ These styles may also be altered using the `style` method on the Shape object.
1944
+
1945
+ '''Note:''' Purple Shoes doesn't support `center` style.
1946
+
1947
+ === rotate(degrees: a number) » self ===
1948
+
1949
+ Rotates the pen used for drawing by a certain number of `degrees`, so that any
1950
+ shapes will be drawn at that angle.
1951
+
1952
+ In this example below, the rectangle drawn at (30, 30) will be rotated 45 degrees.
1953
+
1954
+ {{{
1955
+ #!ruby
1956
+ Shoes.app do
1957
+ fill "#333"
1958
+ rotate 45
1959
+ rect 30, 30, 40, 40
1960
+ end
1961
+ }}}
1962
+
1963
+ === shape(left, top) { ... } » Shoes::Shape ===
1964
+
1965
+ Describes an arbitrary shape to draw, beginning at coordinates (left, top) and
1966
+ continued by calls to `line_to`, `move_to`, `curve_to` and `arc_to` inside the
1967
+ block. You can look at it as sketching a shape with a long line that curves
1968
+ and arcs and bends.
1969
+
1970
+ {{{
1971
+ Shoes.app do
1972
+ fill yellow
1973
+ shape do
1974
+ move_to 50, 30
1975
+ curve_to 100, 100, 10, 20, 100, 50
1976
+ line_to 20, 100
1977
+ line_to 30, 30
1978
+ end
1979
+ end
1980
+ }}}
1981
+
1982
+ A shape can also contain other shapes. So, you can place an [[Art.oval]], a
1983
+ [[Art.rect]], a [[Art.line]], a [[Art.star]] or an [[Art.arrow]] (and all of
1984
+ the other methods in this [[Art]] section) inside a shape, but they will not be
1985
+ part of the line. They will be more like a group of shapes are all drawn as
1986
+ one.
1987
+
1988
+ '''Note:''' The above `line_to`, `move_to` and `curve_to` are Cairo::Context methods.
1989
+ Purple Shoes uses them directly inside the block. So, Purple Shoes doesn't support `arc_to`.
1990
+ Also Purple Shoes shape can not contain other shapes.
1991
+
1992
+ === star(left, top, points = 10, outer = 100.0, inner = 50.0) » Shoes::Star ===
1993
+
1994
+ Draws a star using the stroke and fill colors. The star is positioned with its
1995
+ center point at coordinates (left, top) with a certain number of `points`. The
1996
+ `outer` width defines the full radius of the star; the `inner` width specifies
1997
+ the radius of the star's middle, where points stem from.
1998
+
1999
+ === stroke(pattern) » pattern ===
2000
+
2001
+ Set the active line color for this slot. The `pattern` may be a color, a
2002
+ gradient or an image, all of which are categorized as "patterns." The line
2003
+ color is then used to draw the borders of any subsequent shape.
2004
+
2005
+ So, to draw a star with a red line around it:
2006
+
2007
+ {{{
2008
+ #!ruby
2009
+ Shoes.app do
2010
+ stroke red
2011
+ nofill
2012
+ star 100, 100
2013
+ end
2014
+ }}}
2015
+
2016
+ To clear the line color, use the `nostroke` method.
2017
+
2018
+ === strokewidth(a number) » self ===
2019
+
2020
+ Sets the line size for all drawing within this slot. Whereas the `stroke`
2021
+ method alters the line color, the `strokewidth` method alters the line size in
2022
+ pixels. Calling `strokewidth(4)` will cause lines to be drawn 4 pixels wide.
2023
+
2024
+ === transform(:center or :corner) » self ===
2025
+
2026
+ Should transformations (such as `skew` and `rotate`) be performed around the
2027
+ center of the shape? Or the corner of the shape? Shoes defaults to `:corner`.
2028
+
2029
+ '''Note:''' Purple Shoes doesn't support `transform` method.
2030
+
2031
+ === translate(left, top) » self ===
2032
+
2033
+ Moves the starting point of the drawing pen for this slot. Normally, the pen
2034
+ starts at (0, 0) in the top-left corner, so that all shapes are drawn from that
2035
+ point. With `translate`, if the starting point is moved to (10, 20) and a
2036
+ shape is drawn at (50, 60), then the shape is actually drawn at (60, 80) on the
2037
+ slot.
2038
+
2039
+ '''Note:''' Purple Shoes doesn't support `translate` method.
2040
+
2041
+ == Element Creation ==
2042
+
2043
+ Purple Shoes has a wide variety of elements, many cherry-picked from HTML. This page
2044
+ describes how to create these elements in a slot. See the Elements section of
2045
+ the manual for more on how to modify and use these elements after they have
2046
+ been placed.
2047
+
2048
+ === animate(fps) { |frame| ... } » Shoes::Anim ===
2049
+
2050
+ Starts an animation timer, which runs parallel to the rest of the app. The
2051
+ `fps` is a number, the frames per seconds. This number dictates how many times
2052
+ per second the attached block will be called.
2053
+
2054
+ The block is given a `frame` number. Starting with zero, the `frame` number
2055
+ tells the block how many frames of the animation have been shown.
2056
+
2057
+ {{{
2058
+ #!ruby
2059
+ Shoes.app do
2060
+ counter = para "STARTING"
2061
+ animate 24 do |frame|
2062
+ counter.replace "FRAME #{frame}"
2063
+ end
2064
+ end
2065
+ }}}
2066
+
2067
+ The above animation is shown 24 times per second. If no number is given, the
2068
+ `fps` defaults to 10.
2069
+
2070
+ === background(pattern) » Shoes::Background ===
2071
+
2072
+ Draws a Background element with a specific color (or pattern.) Patterns can be
2073
+ colors, gradients or images. Colors and images will tile across the
2074
+ background. Gradients stretch to fill the background.
2075
+
2076
+ '''PLEASE NOTE:''' Backgrounds are actual elements, not styles. HTML treats
2077
+ backgrounds like styles. Which means every box can only have one background.
2078
+ Purple Shoes layers background elements.
2079
+
2080
+ {{{
2081
+ #!ruby
2082
+ Shoes.app do
2083
+ background black
2084
+ background white, width: 50
2085
+ end
2086
+ }}}
2087
+
2088
+ The above example paints two backgrounds. First, a black background is painted
2089
+ over the entire app's surface area. Then a 50 pixel white stripe is painted
2090
+ along the left side.
2091
+
2092
+ === banner(text) » Shoes::Banner ===
2093
+
2094
+ Creates a Banner text block. Purple Shoes automatically styles this text to 48 pixels high.
2095
+
2096
+ === border(text, :strokewidth => a number) » Shoes::Border ===
2097
+
2098
+ Draws a Border element using a specific color (or pattern.) Patterns can be
2099
+ colors, gradients or images. Colors and images will tile across the border.
2100
+ Gradients stretch to fill the border.
2101
+
2102
+ '''PLEASE NOTE:''' Like Backgrounds, Borders are actual elements, not styles.
2103
+ HTML treats backgrounds and borders like styles. Which means every box can
2104
+ only have one borders. Purple Shoes layers border and background elements, along with
2105
+ text blocks, images, and everything else.
2106
+
2107
+ === button(text) { ... } » Shoes::Button ===
2108
+
2109
+ Adds a push button with the message `text` written across its surface. An
2110
+ optional block can be attached, which is called if the button is pressed.
2111
+
2112
+ === caption(text) » Shoes::Caption ===
2113
+
2114
+ Creates a Caption text block. Purple Shoes styles this text to 14 pixels high.
2115
+
2116
+ === check() » Shoes::Check ===
2117
+
2118
+ Adds a check box.
2119
+
2120
+ === code(text) » String ===
2121
+
2122
+ Create a Code text fragment. This text defaults to a monospaced font.
2123
+
2124
+ === del(text) » String ===
2125
+
2126
+ Creates a Del text fragment (short for "deleted") which defaults to text with a
2127
+ single strikethrough in its middle.
2128
+
2129
+ === dialog(styles) { ... } » Shoes::App ===
2130
+
2131
+ Opens a new app window (just like the [[Element.window]] method does,) but the
2132
+ window is given a dialog box look.
2133
+
2134
+ '''Note:''' Purple Shoes doesn't support `dialog` method.
2135
+
2136
+ === edit_box(text, :accepts_tab => true or false) » Shoes::EditBox ===
2137
+
2138
+ Adds a large, multi-line textarea to this slot. The `text` is optional and
2139
+ should be a string that will start out the box. An optional block can be
2140
+ attached here which is called any type the user changes the text in the box.
2141
+
2142
+ If `accepts_tab` is true a tab character is inserted.
2143
+ If `accepts_tab` is false the keyboard focus is moved to the next element
2144
+ in the focus chain. This accepts_tab defaults to false.
2145
+
2146
+ {{{
2147
+ #!ruby
2148
+ Shoes.app do
2149
+ edit_box
2150
+ edit_box text: "HORRAY EDIT ME"
2151
+ edit_box text: "small one",
2152
+ width: 100, height: 160
2153
+ end
2154
+ }}}
2155
+
2156
+ === edit_line(text) » Shoes::EditLine ===
2157
+
2158
+ Adds a single-line text box to this slot. The `text` is optional and should be
2159
+ a string that will start out the box. An optional block can be attached here
2160
+ which is called any type the user changes the text in the box.
2161
+
2162
+ === em(text) » String ===
2163
+
2164
+ Creates an Em text fragment (short for "emphasized") which, by default, is
2165
+ styled with italics.
2166
+
2167
+ === every(seconds) { |count| ... } » Shoes::Anim ===
2168
+
2169
+ A timer similar to the `animate` method, but much slower. This timer fires a
2170
+ given number of seconds, running the block attached. So, for example, if you
2171
+ need to check a web site every five minutes, you'd call `every(300)` with a
2172
+ block containing the code to actually ping the web site.
2173
+
2174
+ === flow(styles) { ... } » Shoes::Flow ===
2175
+
2176
+ A flow is an invisible box (or "slot") in which you place Purple Shoes elements. Both
2177
+ flows and stacks are explained in great detail on the main [[Slots]] page.
2178
+
2179
+ Flows organize elements horizontally. Where one would use a [[Element.stack]]
2180
+ to keep things stacked vertically, a flow places its contents end-to-end across
2181
+ the page. Once the end of the page is reached, the flow starts a new line of
2182
+ elements.
2183
+
2184
+ === image(path) » Shoes::Image ===
2185
+
2186
+ Creates an [[Image]] element for displaying a picture. PNG, JPEG and GIF
2187
+ formats are allowed.
2188
+
2189
+ The `path` can be a file path or a URL. All images loaded are temporarily
2190
+ cached in memory, but remote images are also cached locally in the user's
2191
+ personal Shoes directory. Remote images are loaded in the background; as with
2192
+ browsers, the images will not appear right away, but will be shown when they
2193
+ are loaded.
2194
+
2195
+ '''Note:''' Purple Shoes doesn't support the above personal Shoes directory.
2196
+
2197
+ === imagesize(path) » [width, height] ===
2198
+
2199
+ Quickly grab the width and height of an image. The image won't be loaded into
2200
+ the cache or displayed.
2201
+
2202
+ URGENT NOTE: This method cannot be used with remote images (loaded from HTTP,
2203
+ rather than the hard drive.)
2204
+
2205
+ === ins(text) » String ===
2206
+
2207
+ Creates an Ins text fragment (short for "inserted") which Purple Shoes styles with a
2208
+ single underline.
2209
+
2210
+ === inscription(text) » Shoes::Inscription ===
2211
+
2212
+ Creates an Inscription text block. Purple Shoes styles this text at 10 pixels high.
2213
+
2214
+ === link(text, :click => proc or string) » Shoes::Link ===
2215
+
2216
+ Creates a Link text block, which Purple Shoes styles with a single underline and
2217
+ colors with a #06E (blue) colored stroke.
2218
+
2219
+ The default LinkHover style is also single-underlined with a #039 (dark blue) stroke.
2220
+
2221
+ === link(text){ ... } » Shoes::Link ===
2222
+
2223
+ Creates a Link text block. You can also write with this style. When user clicks the link text,
2224
+ the block will be launched.
2225
+
2226
+ === list_box(:items => [strings, ...]) » Shoes::ListBox ===
2227
+
2228
+ Adds a drop-down list box containing entries for everything in the `items`
2229
+ array. An optional block may be attached, which is called if anything in the
2230
+ box becomes selected by the user.
2231
+
2232
+ {{{
2233
+ #!ruby
2234
+ Shoes.app do
2235
+ stack margin: 10 do
2236
+ para "Pick a card:"
2237
+ list_box items: ["Jac", "Ace", "Jok"] do |item|
2238
+ @p.text = "#{item} was picked!"
2239
+ end
2240
+ @p = para
2241
+ end
2242
+ end
2243
+ }}}
2244
+
2245
+ Call `ListBox#text` to get the selected string. See the `ListBox` section
2246
+ under `Native` controls for more help.
2247
+
2248
+ === progress() » Shoes::Progress ===
2249
+
2250
+ Adds a progress bar.
2251
+
2252
+ === para(text) » Shoes::Para ===
2253
+
2254
+ Create a Para text block (short for "paragraph") which Purple Shoes styles at 12
2255
+ pixels high.
2256
+
2257
+ === radio(group name: a string or symbol) » Shoes::Radio ===
2258
+
2259
+ Adds a radio button. If a `group name` is given, the radio button is
2260
+ considered part of a group. Among radio buttons in the same group, only one
2261
+ may be checked. (If no group name is given, the radio button is grouped with
2262
+ any other radio buttons in the same slot.)
2263
+
2264
+ === span(text) » Shoes::Span ===
2265
+
2266
+ Creates a Span text fragment, unstyled by default.
2267
+
2268
+ {{{
2269
+ Shoes.app do
2270
+ tagline "\n", 'hello ' * 5,
2271
+ span(em('Purple Shoes'), size: 8, rise: 15)
2272
+ end
2273
+ }}}
2274
+
2275
+ === stack(styles) { ... } » Shoes::Stack ===
2276
+
2277
+ Creates a new stack. A stack is a type of slot. (See the main [[Slots]] page
2278
+ for a full explanation of both stacks and flows.)
2279
+
2280
+ In short, stacks are an invisible box (a "slot") for placing stuff. As you add
2281
+ things to the stack, such as buttons or images, those things pile up
2282
+ vertically. Yes, they stack up!
2283
+
2284
+ === strong(text) » String ===
2285
+
2286
+ Creates a Strong text fragment, styled in bold by default.
2287
+
2288
+ === sub(text) » String ===
2289
+
2290
+ Creates a Sub text fragment (short for "subscript") which defaults to lowering
2291
+ the text by 10 pixels and styling it in an x-small font.
2292
+
2293
+ === subtitle(text) » String ===
2294
+
2295
+ Creates a Subtitle text block. Purple Shoes styles this text to 26 pixels high.
2296
+
2297
+ === sup(text) » String ===
2298
+
2299
+ Creates a Sup text fragment (short for "superscript") which defaults to raising
2300
+ the text by 10 pixels and styling it in an x-small font.
2301
+
2302
+ === tagline(text) » Shoes::Tagline ===
2303
+
2304
+ Creates a Tagline text block. Purple Shoes styles this text to 18 pixels high.
2305
+
2306
+ === timer(seconds) { ... } » Fixnum ===
2307
+
2308
+ A one-shot timer. If you want to schedule to run some code in a few seconds
2309
+ (or minutes, hours) you can attach the code as a block here.
2310
+
2311
+ To display an alert box five seconds from now:
2312
+
2313
+ {{{
2314
+ #!ruby
2315
+ Shoes.app do
2316
+ timer 5 do
2317
+ alert "Your five seconds are up."
2318
+ end
2319
+ end
2320
+ }}}
2321
+
2322
+ === title(text) » Shoes::Title ===
2323
+
2324
+ Creates a Title text block. Purple Shoes styles these elements to 34 pixels high.
2325
+
2326
+ === video(path or url) » Shoes::Video ===
2327
+
2328
+ Embeds a movie or plays an audio.
2329
+
2330
+ === window(styles) { ... } » Shoes::App ===
2331
+
2332
+ Opens a new app window. This method is almost identical to the
2333
+ [[App.Shoes.app]] method used to start an app in the first place. The
2334
+ difference is that the `window` method sets the new window's [[App.owner]]
2335
+ property. (A normal Shoes.app has its `owner` set to `nil`.)
2336
+
2337
+ So, the new window's `owner` will be set to the Shoes::App which launched the
2338
+ window. This way the child window can call the parent.
2339
+
2340
+ {{{
2341
+ #!ruby
2342
+ Shoes.app title: "The Owner" do
2343
+ button "Pop up?" do
2344
+ window do
2345
+ para "Okay, popped up from [#{owner.inspect}]."
2346
+ end
2347
+ end
2348
+ end
2349
+ }}}
2350
+
2351
+ == Events ==
2352
+
2353
+ Wondering how to catch stray mouse clicks or keyboard typing? Events are sent
2354
+ to a slot whenever a mouse moves inside the slot. Or whenever a key is
2355
+ pressed. Even when the slot is created or destroyed. You can attach a block
2356
+ to each of these events.
2357
+
2358
+ Mouse events include `motion`, `click`, `release`, `hover` and `leave`. Keyboard typing
2359
+ is represented by the `keypress` event. And the `start` and `finish` events
2360
+ indicate when a canvas comes into play or is discarded.
2361
+
2362
+ So, let's say you want to change the background of a slot whenever the mouse
2363
+ floats over it. We can use the `hover` event to change the background when the
2364
+ mouse comes inside the slot. And `leave` to change back when the mouse floats
2365
+ away.
2366
+
2367
+ {{{
2368
+ #!ruby
2369
+ Shoes.app do
2370
+ s = stack width: 200, height: 200 do
2371
+ background red
2372
+ end
2373
+ s.hover do
2374
+ s.clear { background blue }
2375
+ end
2376
+ s.leave do
2377
+ s.clear { background red }
2378
+ end
2379
+ end
2380
+ }}}
2381
+
2382
+ === click { |button, left, top| ... } » self ===
2383
+
2384
+ The click block is called when a mouse button is clicked. The `button` is the
2385
+ number of the mouse button which has been pressed. The `left` and `top` are
2386
+ the mouse coordinates at which the click happened.
2387
+
2388
+ To catch the moment when the mouse is unclicked, see the [[Events.release]] event.
2389
+
2390
+ === finish { |self| ... } » self ===
2391
+
2392
+ When a slot is removed, it's finish event occurs. The finish block is
2393
+ immediately handed `self`, the slot object which has been removed.
2394
+
2395
+ '''Note:''' Purple Shoes doesn't support `finish` method.
2396
+
2397
+ === hover { |self| ... } » self ===
2398
+
2399
+ The hover event happens when the mouse enters the slot. The block gets `self`,
2400
+ meaning the object which was hovered over.
2401
+
2402
+ To catch the mouse exiting the slot, check out the [[Events.leave]] event.
2403
+
2404
+ === keypress { |key| ... } » self ===
2405
+
2406
+ Whenever a key (or combination of keys) is pressed, the block gets called. The
2407
+ block is sent a `key` which is a string representing the character (such as the
2408
+ letter or number) on the key.
2409
+
2410
+ So, for example, if `Shift-a` is pressed, the block will get the string `"Shift_L"` and `"A"`.
2411
+
2412
+ And if the `F1` key is pressed, the `"F1"` string is received.
2413
+
2414
+ The left side modifier keys are `"Control_L"`, `"Shift_L"` and `"Alt_L"`. They appear in that order.
2415
+ If `Shift-Control-Alt-PgUp` is pressed, the strings will be
2416
+ `"Shift_L"`, `"Control_L"`, `"Alt_L"` and `"Page_Up"`.
2417
+
2418
+ One thing about the shift key. On
2419
+ US keyboards, `Shift-7` is an ampersand. So you'll get the string `"Shift_L"` and `"ampersand"` rather
2420
+ than `"Shift_L"` and `"7"`. And, if you press `Shift-Alt-7` on such a keyboard, you'll
2421
+ get the strings: `"Shift_L"`, `"Alt_L"` and `"ampersand"`.
2422
+
2423
+ {{{
2424
+ #!ruby
2425
+ Shoes.app do
2426
+ info = para "NO KEY is PRESSED."
2427
+ keypress do |k|
2428
+ info.replace "#{k.inspect} was PRESSED."
2429
+ end
2430
+ end
2431
+ }}}
2432
+
2433
+
2434
+ === leave { |self| ... } » self ===
2435
+
2436
+ The leave event takes place when the mouse cursor exits a slot. The moment it
2437
+ no longer is inside the slot's edges. When that takes place, the block is
2438
+ called with `self`, the slot object which is being left.
2439
+
2440
+ Also see [[Events.hover]] if you'd like to detect the mouse entering a slot.
2441
+
2442
+ === motion { |left, top| ... } » self ===
2443
+
2444
+ The motion block gets called every time the mouse moves around inside the slot.
2445
+ The block is handed the cursor's `left` and `top` coordinates.
2446
+
2447
+ {{{
2448
+ #!ruby
2449
+ Shoes.app width: 200, height: 200 do
2450
+ background black
2451
+ fill white
2452
+ circ = oval 0, 0, 100, 100
2453
+
2454
+ motion do |top, left|
2455
+ circ.move top - 50, left - 50
2456
+ end
2457
+ end
2458
+ }}}
2459
+
2460
+ === release { |button, left, top| ... } » self ===
2461
+
2462
+ The release block runs whenever the mouse is unclicked (on mouse up). When the
2463
+ finger is lifted. The `button` is the number of the button that was depressed.
2464
+ The `left` and `top` are the coordinates of the mouse at the time the button
2465
+ was released.
2466
+
2467
+ To catch the actual mouse click, use the [[Events.click]] event.
2468
+
2469
+ === start { |self| ... } » self ===
2470
+
2471
+ The first time the slot is drawn, the start event fires. The block is handed
2472
+ `self`, the slot object which has just been drawn.
2473
+
2474
+ '''Note:''' Purple Shoes doesn't support `start` method.
2475
+
2476
+ == Manipulation Blocks ==
2477
+
2478
+ The manipulation methods below make quick work of shifting around slots and
2479
+ inserting new elements.
2480
+
2481
+ === append() { ... } » self ===
2482
+
2483
+ Adds elements to the end of a slot.
2484
+
2485
+ {{{
2486
+ #!ruby
2487
+ Shoes.app do
2488
+ @slot = stack { para 'Good Morning' }
2489
+ timer 3 do
2490
+ @slot.append do
2491
+ title "Breaking News"
2492
+ tagline "Astronauts ",
2493
+ "arrested for space shuttle DUI."
2494
+ end
2495
+ end
2496
+ end
2497
+ }}}
2498
+
2499
+ The `title` and `tagline` elements will be added to the end of the `@slot`.
2500
+
2501
+ === after(element) { ... } » self ===
2502
+
2503
+ Adds elements to a specific place in a slot, just after the `element` which is
2504
+ a child of the slot.
2505
+
2506
+ === before(element) { ... } » self ===
2507
+
2508
+ Adds elements to a specific place in a slot, just before the `element` which is
2509
+ a child of the slot.
2510
+
2511
+ === clear() » self ===
2512
+
2513
+ Empties the slot of any elements, timers and nested slots. This is effectively
2514
+ identical to looping through the contents of the slot and calling each
2515
+ element's `remove` method.
2516
+
2517
+ === clear() { ... } » self ===
2518
+
2519
+ The clear method also takes an optional block. The block will be used to
2520
+ replace the contents of the slot.
2521
+
2522
+ {{{
2523
+ #!ruby
2524
+ Shoes.app do
2525
+ @slot = stack { para "Old text" }
2526
+ timer 3 do
2527
+ @slot.clear { para "Brand new text" }
2528
+ end
2529
+ end
2530
+ }}}
2531
+
2532
+ In this example, the "Old text" paragraph will be cleared out, replaced by the
2533
+ "Brand new text" paragraph.
2534
+
2535
+ === prepend() { ... } » self ===
2536
+
2537
+ Adds elements to the beginning of a slot.
2538
+
2539
+ {{{
2540
+ #!ruby
2541
+ Shoes.app do
2542
+ @slot = stack { para 'Good Morning' }
2543
+ timer 3 do
2544
+ @slot.prepend { para "Your car is ready." }
2545
+ end
2546
+ end
2547
+ }}}
2548
+
2549
+ The `para` element is added to the beginning of the `@slot`.
2550
+
2551
+ == Position of a Slot ==
2552
+
2553
+ Like any other element, slots can be styled and customized when they are created.
2554
+
2555
+ To set the width of a stack to 150 pixels:
2556
+
2557
+ {{{
2558
+ #!ruby
2559
+ Shoes.app do
2560
+ stack width: 150 do
2561
+ background yellow
2562
+ para "Now that's precision."
2563
+ end
2564
+ end
2565
+ }}}
2566
+
2567
+ Each style setting also has a method, which can be used to grab that particular
2568
+ setting. (So, like, the `width` method returns the width of the slot in
2569
+ pixels.)
2570
+
2571
+ === displace(left: a number, top: a number) » self ===
2572
+
2573
+ A shortcut method for setting the :displace_left and :displace_top styles.
2574
+ Displacing is a handy way of moving a slot without altering the layout. In
2575
+ fact, the `top` and `left` methods will not report displacement at all. So,
2576
+ generally, displacement is only for temporary animations. For example,
2577
+ jiggling a button in place.
2578
+
2579
+ The `left` and `top` numbers sent to `displace` are added to the slot's own
2580
+ top-left coordinates. To subtract from the top-left coordinate, use negative
2581
+ numbers.
2582
+
2583
+ '''Note:''' Purple Shoes doesn't support `displace` method.
2584
+
2585
+ === gutter() » a number ===
2586
+
2587
+ The size of the scrollbar area. When Purple Shoes needs to show a scrollbar, the
2588
+ scrollbar may end up covering up some elements that touch the edge of the
2589
+ window. The `gutter` tells you how many pixels to expect the scrollbar to
2590
+ cover.
2591
+
2592
+ This is commonly used to pad elements on the right, like so:
2593
+
2594
+ {{{
2595
+ Shoes.app do
2596
+ stack margin_right: 20 + gutter do
2597
+ para "Insert fat and ratified ",
2598
+ "declaration of independence here..."
2599
+ end
2600
+ end
2601
+ }}}
2602
+
2603
+ === height() » a number ===
2604
+
2605
+ The vertical size of the viewable slot in pixels. So, if this is a scrolling
2606
+ slot, you'll need to use `scroll_height()` to get the full size of the slot.
2607
+
2608
+ === hide() » self ===
2609
+
2610
+ Hides the slot, so that it can't be seen. See also [[Position.show]] and [[Position.toggle]].
2611
+
2612
+ === left() » a number ===
2613
+
2614
+ The left pixel location of the slot. Also known as the x-axis coordinate.
2615
+
2616
+ === move(left, top) » self ===
2617
+
2618
+ Moves the slot to specific coordinates, the (left, top) being the upper left
2619
+ hand corner of the slot.
2620
+
2621
+ '''Note:''' Purple Shoes doesn't support `move` method.
2622
+
2623
+ === remove() » self ===
2624
+
2625
+ Removes the slot. It will no longer be displayed and will not be listed in its
2626
+ parent's contents. It's gone.
2627
+
2628
+ '''Note:''' Purple Shoes doesn't support `remove` method. Use `clear` method.
2629
+
2630
+ === scroll() » true or false ===
2631
+
2632
+ Is this slot allowed to show a scrollbar? True or false. The scrollbar will
2633
+ only appear if the height of the slot is also fixed.
2634
+
2635
+ '''Note:''' Purple Shoes doesn't support `scroll` method.
2636
+
2637
+ === scroll_height() » a number ===
2638
+
2639
+ The vertical size of the full slot, including any of it which is hidden by scrolling.
2640
+
2641
+ '''Note:''' Purple Shoes doesn't support `scroll_height` method.
2642
+
2643
+ === scroll_max() » a number ===
2644
+
2645
+ The top coordinate which this slot can be scrolled down to. The top coordinate
2646
+ of a scroll bar is always zero. The bottom coordinate is the full height of
2647
+ the slot minus one page of scrolling. This bottom coordinate is what
2648
+ `scroll_max` returns.
2649
+
2650
+ This is basically a shortcut for writing `slot.scroll_height - slot.height`.
2651
+
2652
+ To scroll to the bottom of a slot, use `slot.scroll_top = slot.scroll_max`.
2653
+
2654
+ '''Note:''' Purple Shoes doesn't support `scroll_max` method.
2655
+
2656
+ === scroll_top() » a number ===
2657
+
2658
+ The top coordinate which this slot is scrolled down to. So, if the slot is
2659
+ scrolled down twenty pixels, this method will return `20`.
2660
+
2661
+ '''Note:''' Purple Shoes doesn't support `scroll_top` method.
2662
+
2663
+ === scroll_top = a number ===
2664
+
2665
+ Scrolls the slot to a certain coordinate. This must be between zero and
2666
+ `scroll_max`.
2667
+
2668
+ '''Note:''' Purple Shoes doesn't support `scroll_top=` method.
2669
+
2670
+ === show() » self ===
2671
+
2672
+ Reveals the slot, if it is hidden. See also [[Position.hide]] and
2673
+ [[Position.toggle]].
2674
+
2675
+ === style() » styles ===
2676
+
2677
+ Calling the `style` method with no arguments returns a hash of the styles
2678
+ presently applied to this slot.
2679
+
2680
+ While methods such as `height` and `width` return the true pixel dimensions of
2681
+ the slot, you can use `style[:height]` or `style[:width]` to get the dimensions
2682
+ originally requested.
2683
+
2684
+ {{{
2685
+ #!ruby
2686
+ Shoes.app do
2687
+ s = stack width: 1.0
2688
+ para s.style[:width]
2689
+ button('Then..'){s.append{para s.style[:width]}}
2690
+ end
2691
+ }}}
2692
+
2693
+ In this example, the paragraph under the stack will display "1.0".
2694
+ After click the button, will show you "600" pixels.
2695
+
2696
+ === style(styles) » styles ===
2697
+
2698
+ Alter the slot using a hash of style settings. Any of the methods on this page
2699
+ (aside from this method, of course) can be used as a style setting. So, for
2700
+ example, there is a `width` method, thus there is also a `width` style.
2701
+
2702
+ {{{
2703
+ #!ruby
2704
+ Shoes.app do
2705
+ s = stack { background green }
2706
+ s.style width: 400, height: 200
2707
+ end
2708
+ }}}
2709
+
2710
+ === toggle() » self ===
2711
+
2712
+ Hides the slot, if it is shown. Or shows the slot, if it is hidden.
2713
+
2714
+ === top() » a number ===
2715
+
2716
+ The top pixel location of the slot. Also known as the y-axis coordinate.
2717
+
2718
+ === width() » a number ===
2719
+
2720
+ The horizontal size of the slot in pixels.
2721
+
2722
+ == Traversing the Page ==
2723
+
2724
+ You may find yourself needing to loop through the elements inside a slot. Or
2725
+ maybe you need to climb the page, looking for a stack that is the parent of an
2726
+ element.
2727
+
2728
+ On any element, you may call the `parent` method to get the slot directly above
2729
+ it. And on slots, you can call the `contents` method to get all of the
2730
+ children. (Some elements, such as shapes, are not included in any slots.)
2731
+
2732
+ === contents() » an array of elements ===
2733
+
2734
+ Lists all elements in a slot.
2735
+
2736
+ === parent() » a Shoes::Stack or Shoes::Flow ===
2737
+
2738
+ Gets the object for this element's container.
2739
+
2740
+ {{{
2741
+ Shoes.app do
2742
+ s = stack do
2743
+ para 'Purple'
2744
+ @p = para 'Shoes'
2745
+ end
2746
+ para s
2747
+ para s.contents
2748
+ para @p.parent
2749
+ end
2750
+ }}}
2751
+
2752
+ = Elements =
2753
+
2754
+ Ah, here's the stuff of Purple Shoes. An element can be as simple as an oval shape. Or
2755
+ as complex as a para text string. You've encountered all of these elements before
2756
+ in the Slots section of the manual.
2757
+
2758
+ Purple Shoes has seven native controls: the Button, the EditLine, the EditBox, the
2759
+ ListBox, the Progress meter, the Check box and the Radio. By "native"
2760
+ controls, we mean that each of these seven elements is drawn by SWT apis
2761
+ directly. So, a Progress bar will never convert to the PNG image data.
2762
+
2763
+ Greem Shoes also has seven basic other types of elements: Background, Border, Image,
2764
+ Shape, TextBlock, Animate and Video. These all should look and act the same on
2765
+ every operating system.
2766
+
2767
+ Once an element is created, you will often still want to change it. To move it
2768
+ or hide it or get rid of it. You'll use the commands in this section to do that
2769
+ sort of stuff. (Especially check out the [[Common Common Methods]] section for
2770
+ commands you can use on any element.)
2771
+
2772
+ So, for example, use the `image` method to place a PNG on the screen.
2773
+ The `image` method gives you back an Image object. Use the methods of the Image
2774
+ object to change things up.
2775
+
2776
+ == Common Methods ==
2777
+
2778
+ A few methods are shared by every little element in Purple Shoes. Moving, showing,
2779
+ hiding. Removing an element. Basic and very general things. This list
2780
+ encompasses those common commands.
2781
+
2782
+ One of the most general methods of all is the `style` method (which is also
2783
+ covered as the [[Position.style]] method for slots.)
2784
+
2785
+ {{{
2786
+ #!ruby
2787
+ Shoes.app do
2788
+ stack do
2789
+ # Background, text and a button:
2790
+ # both are elements!
2791
+ @back = background green
2792
+ @text = banner "A Message for You, Rudy"
2793
+ @press = button "Stop your messin about!"
2794
+
2795
+ # And so, both can be styled.
2796
+ @text.style size: 12,
2797
+ markup: fg(@text.text, red), margin: 10
2798
+ @press.style width: 400
2799
+ @back.style height: 10
2800
+ end
2801
+ end
2802
+ }}}
2803
+
2804
+ For specific commands, see the other links to the left in the Elements section.
2805
+ Like if you want to pause or play a video file, check the [[Video]] section,
2806
+ since pausing and playing is peculiar to videos. No sense pausing a button.
2807
+
2808
+ === displace(left: a number, top: a number) » self ===
2809
+
2810
+ Displacing an element moves it. But without changing the layout around it.
2811
+ This is great for subtle animations, especially if you want to reserve a place
2812
+ for an element while it is still animating. Like maybe a quick button shake or
2813
+ a slot sliding into view.
2814
+
2815
+ When you displace an element, it moves relative to the upper-left corner where
2816
+ it was placed. So, if an element is at the coordinates (20, 40) and you
2817
+ displace it 2 pixels left and 6 pixels on top, you end up with the coordinates
2818
+ (22, 46).
2819
+
2820
+ {{{
2821
+ #!ruby
2822
+ # Not yet available
2823
+ Shoes.app do
2824
+ flow :margin => 12 do
2825
+ # Set up three buttons
2826
+ button "One"
2827
+ @two = button "Two"
2828
+ button "Three"
2829
+
2830
+ # Bounce the second button
2831
+ animate do |i|
2832
+ @two.displace(0, (Math.sin(i) * 6).to_i)
2833
+ end
2834
+ end
2835
+ end
2836
+ }}}
2837
+
2838
+ Notice that while the second button bounces, the other two buttons stay put.
2839
+ If we used a normal `move` in this situation, the second button would be moved
2840
+ out of the layout and the buttons would act as if the second button wasn't
2841
+ there at all. (See the [[Common.move]] example.)
2842
+
2843
+ '''Of particular note:''' if you use the `left` and `top` methods to get the
2844
+ coordinates of a displaced element, you'll just get back the normal
2845
+ coordinates. As if there was no displacement. Displacing is just intended for
2846
+ quick animations!
2847
+
2848
+ '''Note:''' Purple Shoes doesn't support `displace` method.
2849
+
2850
+ === height() » a number ===
2851
+
2852
+ The vertical screen size of the element in pixels. In the case of images, this
2853
+ is not the full size of the image. This is the height of the element as it is
2854
+ shown right now.
2855
+
2856
+ If you have a 150x150 pixel image and you set the width to 50 pixels, this
2857
+ method will return 50.
2858
+
2859
+ Also see the [[Common.width]] method for an example and some other comments.
2860
+
2861
+ === hide() » self ===
2862
+
2863
+ Hides the element, so that it can't be seen. See also [[Common.show]] and
2864
+ [[Common.toggle]].
2865
+
2866
+ === left() » a number ===
2867
+
2868
+ Gets you the pixel position of the left edge of the element.
2869
+
2870
+ === move(left: a number, top: a number) » self ===
2871
+
2872
+ Moves the element to a specific pixel position. The element is no longer
2873
+ inside the slot. So, it will not be stacked or flowed in with the
2874
+ other stuff in the slot. The element will float freely, now absolutely
2875
+ positioned instead.
2876
+
2877
+ {{{
2878
+ #!ruby
2879
+ Shoes.app do
2880
+ # Set up three buttons
2881
+ b = button "One"
2882
+ @two = button "Two"
2883
+ button "Three"
2884
+
2885
+ # Bounce the second button
2886
+ animate do |i|
2887
+ @two.move(33, 33 + (Math.sin(i) * 6).to_i)
2888
+ end
2889
+ end
2890
+ }}}
2891
+
2892
+ The second button is moved to a specific place, allowing the third button to
2893
+ slide over into its place. But it will not happen until you resize the window.
2894
+ If you want to slide the third button without resizing the window, add `flush` method.
2895
+
2896
+ === parent() » a Shoes::Stack or Shoes::Flow ===
2897
+
2898
+ Gets the object for this element's container. Also see the slot's
2899
+ [[Traversing.contents]] to do the opposite: get a container's elements.
2900
+
2901
+ === remove() » self ===
2902
+
2903
+ Removes the element from its slot. (In other words: throws it in the garbage.)
2904
+ The element will no longer be displayed.
2905
+
2906
+ === show() » self ===
2907
+
2908
+ Reveals the element, if it is hidden. See also [[Common.hide]] and
2909
+ [[Common.toggle]].
2910
+
2911
+ === style() » styles ===
2912
+
2913
+ Gives you the full set of styles applied to this element, in the form of a
2914
+ Hash. While methods like `width` and `height` and `top` give you back specific
2915
+ pixel dimensions, using `style[:width]` or `style[:top]`, you can get the
2916
+ original setting (things like "100%" for width or "10px" for top.)
2917
+
2918
+ {{{
2919
+ #!ruby
2920
+ Shoes.app do
2921
+ # A button which take up the whole page
2922
+ @b = button "All of it",
2923
+ width: width, height: height
2924
+
2925
+ # When clicked, show the styles
2926
+ @b.click { alert(@b.style.inspect) }
2927
+ end
2928
+ }}}
2929
+
2930
+ === style(styles) » styles ===
2931
+
2932
+ Changes the style of an element. This could include the `:width` and `:height`
2933
+ of an element, the font `:size` of some text, the `:stroke` and `:fill` of a
2934
+ shape. Or any other number of style settings.
2935
+
2936
+ === toggle() » self ===
2937
+
2938
+ Hides an element if it is shown. Or shows the element, if it is hidden.
2939
+
2940
+ === top() » a number ===
2941
+
2942
+ Gets the pixel position of the top edge of the element.
2943
+
2944
+ === width() » a number ===
2945
+
2946
+ Gets the pixel width for the full size of the element. This method always
2947
+ returns an exact pixel size. In the case of images, this is not the full width
2948
+ of the image, just the size it is shown at. See the [[Common.height]] method
2949
+ for more.
2950
+
2951
+ Also, if you create an element with a width of 1.0 and that element is inside
2952
+ a stack which is 120 pixels wide, you'll get back `120`. And, if you call
2953
+ `style[:width]`, you'll get `120`.
2954
+
2955
+ {{{
2956
+ #!ruby
2957
+ Shoes.app do
2958
+ stack width: 120 do
2959
+ @b = button "Click me", width: 1.0 do
2960
+ alert "button.width = #{@b.width}\n" +
2961
+ "button.style[:width] = " +
2962
+ "#{@b.style[:width]}"
2963
+ end
2964
+ end
2965
+ end
2966
+ }}}
2967
+
2968
+ In order to set the width, you'll have to go through the [[Common.style]]
2969
+ method again. So, to set the button to 150 pixels wide: `@b.style(width: 150)`.
2970
+
2971
+ == Background ==
2972
+
2973
+ A background is a color, a gradient or an image that is painted across an
2974
+ entire slot. Both backgrounds and borders are a type of Shoes::Pattern.
2975
+ !{:margin_left => 100}man-ele-background.png!
2976
+
2977
+ Even though it's called a ''background'', you may still place this element in
2978
+ front of other elements. If a background comes after something else painted on
2979
+ the slot (like a `rect` or an `oval`,) the background will be painted over that
2980
+ element.
2981
+
2982
+ The simplest background is just a plain color background, created with the
2983
+ [[Element.background]] method, such as this black background:
2984
+
2985
+ {{{
2986
+ #!ruby
2987
+ Shoes.app do
2988
+ background black
2989
+ end
2990
+ }}}
2991
+
2992
+ A simple background like that paints the entire slot that contains it. (In
2993
+ this case, the whole window is painted black.)
2994
+
2995
+ You can use styles to cut down the size or move around the background to your liking.
2996
+
2997
+ To paint a black background across the top fifty pixels of the window:
2998
+
2999
+ {{{
3000
+ #!ruby
3001
+ Shoes.app do
3002
+ background black, height: 50
3003
+ end
3004
+ }}}
3005
+
3006
+ Or, to paint a fifty pixel column on the left-side of the window:
3007
+
3008
+ {{{
3009
+ #!ruby
3010
+ Shoes.app do
3011
+ background black, width: 50
3012
+ end
3013
+ }}}
3014
+
3015
+ Since Backgrounds are normal elements as well, see also the start of the
3016
+ [[Elements]] section for all of its other methods.
3017
+
3018
+ === to_pattern() » a Shoes::Pattern ===
3019
+
3020
+ Yanks out the color, gradient or image used to paint this background and places
3021
+ it in a normal Shoes::Pattern object. You can then pass that object to other
3022
+ backgrounds and borders. Reuse it as you like.
3023
+
3024
+ '''Note:''' Purple Shoes doesn't support `to_pattern` method.
3025
+
3026
+ == Border ==
3027
+
3028
+ A border is a color, gradient or image painted in a line around the edge of any
3029
+ slot. Like the Background element in the last section, a Border is a kind of
3030
+ Shoes::Pattern. !{:margin_left => 100}man-ele-border.png!
3031
+
3032
+ The first, crucial thing to know about border is that all borders paint a line
3033
+ around the '''inside''' of a slot, not the outside. So, if you have a slot
3034
+ which is fifty pixels wide and you paint a five pixel border on it, that means
3035
+ there is a fourty pixel wide area inside the slot which is surrounded by the
3036
+ border.
3037
+
3038
+ This also means that if you paint a Border on top of a [[Background]], the
3039
+ edges of the background will be painted over by the border.
3040
+
3041
+ Here is just such a slot:
3042
+
3043
+ {{{
3044
+ #!ruby
3045
+ Shoes.app do
3046
+ stack width: 50 do
3047
+ border black, strokewidth: 5
3048
+ para fg "=^.^=", green
3049
+ end
3050
+ end
3051
+ }}}
3052
+
3053
+ If you want to paint a border around the outside of a slot, you'll need to wrap
3054
+ that slot in another slot. Then, place the border in the outside slot.
3055
+
3056
+ {{{
3057
+ #!ruby
3058
+ Shoes.app do
3059
+ stack width: 60 do
3060
+ border black, strokewidth: 5
3061
+ stack width: 50 do
3062
+ para fg "=^.^=", green
3063
+ end
3064
+ end
3065
+ end
3066
+ }}}
3067
+
3068
+ In HTML and many other languages, the border is painted on the outside of the
3069
+ box, thus increasing the overall width of the box. Purple Shoes was designed with
3070
+ consistency in mind, so that if you say that a box is fifty pixels wide, it
3071
+ stays fifty pixels wide regardless of its borders or margins or anything else.
3072
+
3073
+ Please also check out the [[Elements]] section for other methods used on borders.
3074
+
3075
+ === to_pattern() » a Shoes::Pattern ===
3076
+
3077
+ Creates a basic pattern object based on the color, gradient or image used to
3078
+ paint this border. The pattern may then be re-used in new borders and
3079
+ backgrounds.
3080
+
3081
+ '''Note:''' Purple Shoes doesn't support `to_pattern` method.
3082
+
3083
+ == Button ==
3084
+
3085
+ Buttons are, you know, push buttons. You click them and they do something.
3086
+ Buttons are known to say "OK" or "Are you sure?" And, then, if you're sure,
3087
+ you click the button. !{:margin_left => 100}man-ele-button.png!
3088
+
3089
+ {{{
3090
+ #!ruby
3091
+ Shoes.app do
3092
+ button "OK!"
3093
+ button "Are you sure?"
3094
+ end
3095
+ }}}
3096
+
3097
+ The buttons in the example above don't do anything when you click them. In
3098
+ order to get them to work, you've got to hook up a block to each button.
3099
+
3100
+ {{{
3101
+ #!ruby
3102
+ Shoes.app do
3103
+ button "OK!" do
3104
+ append { para "Well okay then." }
3105
+ end
3106
+ button "Are you sure?" do
3107
+ append { para "Your confidence is inspiring." }
3108
+ end
3109
+ end
3110
+ }}}
3111
+
3112
+ So now we've got blocks for the buttons. Each block appends a new paragraph to
3113
+ the page. The more you click, the more paragraphs get added.
3114
+
3115
+ It doesn't go much deeper than that. A button is just a clickable phrase.
3116
+
3117
+ Just to be pedantic, though, here's another way to write that last example.
3118
+
3119
+ {{{
3120
+ #!ruby
3121
+ Shoes.app do
3122
+ @b1 = button "OK!"
3123
+ @b1.click{para "Well okay then."}
3124
+ @b2 = button "Are you sure?"
3125
+ @b2.click{para "Your confidence is inspiring."}
3126
+ end
3127
+ }}}
3128
+
3129
+ This looks dramatically different, but it does the same thing. The first
3130
+ difference: rather than attaching the block directly to the button, the block
3131
+ is attached later, through the `click` method.
3132
+
3133
+ The second change isn't related to buttons at all. The `append` block was
3134
+ dropped since Purple Shoes allows you to add new elements directly to the slot. So we
3135
+ can just call `para` directly. (This isn't the case with the `prepend`,
3136
+ `before` or `after` methods.)
3137
+
3138
+ Beside the methods below, buttons also inherit all of the methods that are
3139
+ [[Common]].
3140
+
3141
+ === click() { |self| ... } » self ===
3142
+
3143
+ When a button is clicked, its `click` block is called. The block is handed
3144
+ `self`. Meaning: the button which was clicked.
3145
+
3146
+ === focus() » self ===
3147
+
3148
+ Moves focus to the button. The button will be highlighted and, if the user
3149
+ hits Enter, the button will be clicked.
3150
+
3151
+ == Check ==
3152
+
3153
+ Check boxes are clickable square boxes than can be either checked or unchecked.
3154
+ A single checkbox usually asks a "yes" or "no" question. Sets of checkboxes
3155
+ are also seen in to-do lists. !{:margin_left => 100}man-ele-check.png!
3156
+
3157
+ Here's a sample checklist.
3158
+
3159
+ {{{
3160
+ #!ruby
3161
+ Shoes.app do
3162
+ stack do
3163
+ flow do
3164
+ check; para "Frances Johnson", width: 200
3165
+ end
3166
+ flow do
3167
+ check; para "Ignatius J. Reilly", width: 200
3168
+ end
3169
+ flow do
3170
+ check
3171
+ para "Winston Niles Rumfoord", width: 200
3172
+ end
3173
+ end
3174
+ end
3175
+ }}}
3176
+
3177
+ You basically have two ways to use a check. You can attach a block to the
3178
+ check and it'll get called when the check gets clicked. And/or you can just
3179
+ use the `checked?` method to go back and see if a box has been checked or not.
3180
+
3181
+ Okay, let's add to the above example.
3182
+
3183
+ {{{
3184
+ #!ruby
3185
+ Shoes.app do
3186
+ @list = ['Frances Johnson', 'Ignatius J. Reilly',
3187
+ 'Winston Niles Rumfoord']
3188
+
3189
+ stack do
3190
+ @list.map! do |name|
3191
+ flow { @c = check; para name, width: 200 }
3192
+ [@c, name]
3193
+ end
3194
+
3195
+ button "What's been checked?" do
3196
+ selected =
3197
+ @list.map{|c, n| n if c.checked?}.compact
3198
+ alert("You selected: " + selected.join(', '))
3199
+ end
3200
+ end
3201
+ end
3202
+ }}}
3203
+
3204
+ So, when the button gets pressed, each of the checks gets asked for its status,
3205
+ using the `checked?` method.
3206
+
3207
+ Button methods are listed below, but also see the list of [[Common]] methods,
3208
+ which all elements respond to.
3209
+
3210
+ === checked?() » true or false ===
3211
+
3212
+ Returns whether the box is checked or not. So, `true` means "yes, the box is checked!"
3213
+
3214
+ === checked = true or false ===
3215
+
3216
+ Marks or unmarks the check box. Using `checked = false`, for instance,
3217
+ unchecks the box.
3218
+
3219
+ === click() { |self| ... } » self ===
3220
+
3221
+ When the check is clicked, its `click` block is called. The block is handed
3222
+ `self`, which is the check object which was clicked.
3223
+
3224
+ Clicks are sent for both checking and unchecking the box.
3225
+
3226
+ === focus() » self ===
3227
+
3228
+ Moves focus to the check. The check will be highlighted and, if the user hits
3229
+ Enter, the check will be toggled between its checked and unchecked states.
3230
+
3231
+ == EditBox ==
3232
+
3233
+ Edit boxes are wide, rectangular boxes for entering text. On the web, they
3234
+ call these textareas. These are multi-line edit boxes for entering longer
3235
+ descriptions. Essays, even! !{:margin_left => 100}man-ele-editbox.png!
3236
+
3237
+ Without any other styling, edit boxes are sized 200 pixels by 108 pixels. You
3238
+ can also use `:width` and `:height` styles to set specific sizes.
3239
+
3240
+ {{{
3241
+ #!ruby
3242
+ Shoes.app do
3243
+ edit_box
3244
+ edit_box width: 100, height: 100
3245
+ end
3246
+ }}}
3247
+
3248
+ Other controls (like [[Button]] and [[Check]]) have only click events, but both
3249
+ [[EditLine]] and EditBox have a `change` event. The `change` block is called
3250
+ every time someone types into or deletes from the box.
3251
+
3252
+ {{{
3253
+ #!ruby
3254
+ Shoes.app do
3255
+ edit_box do |e|
3256
+ @counter.text =
3257
+ strong("#{e.text.size}") + " characters"
3258
+ end
3259
+ @counter = para strong("0"), " characters"
3260
+ end
3261
+ }}}
3262
+
3263
+ Notice that the example also uses the [[EditBox.text]] method inside the block.
3264
+ That method gives you a string of all the characters typed into the box.
3265
+
3266
+ More edit box methods are listed below, but also see the list of [[Common]]
3267
+ methods, which all elements respond to.
3268
+
3269
+ === change() { |self| ... } » self ===
3270
+
3271
+ Each time a character is added to or removed from the edit box, its `change`
3272
+ block is called. The block is given `self`, which is the edit box object which
3273
+ has changed.
3274
+
3275
+ === focus() » self ===
3276
+
3277
+ Moves focus to the edit box. The edit box will be highlighted and the user will
3278
+ be able to type into the edit box.
3279
+
3280
+ === text() » self ===
3281
+
3282
+ Return a string of characters which have been typed into the box.
3283
+
3284
+ === text = a string ===
3285
+
3286
+ Fills the edit box with the characters of `a string`.
3287
+
3288
+ == EditLine ==
3289
+
3290
+ Edit lines are a slender, little box for entering text. While the EditBox is
3291
+ multi-line, an edit line is just one. Line, that is. Horizontal, in fact.
3292
+ !{:margin_left => 100}man-ele-editline.png!
3293
+
3294
+ The unstyled edit line is 200 pixels wide and 28 pixels wide. Roughly. The
3295
+ height may vary on some platforms.
3296
+
3297
+ {{{
3298
+ #!ruby
3299
+ Shoes.app do
3300
+ stack do
3301
+ edit_line
3302
+ edit_line width: 400
3303
+ end
3304
+ end
3305
+ }}}
3306
+
3307
+ You can change the size by styling both the `:width` and the `:height`.
3308
+ However, you generally only want to style the `:width`, as the height will be
3309
+ sized to fit the font. (And, in current versions of Purple Shoes, the font for edit
3310
+ lines and edit boxes cannot be altered anyway.)
3311
+
3312
+ If a block is given to an edit line, it receives `change` events. Check out the
3313
+ [[EditBox]] page for an example of using a change block. In fact, the edit box
3314
+ has all the same methods as an edit line. Also see the list of [[Common]]
3315
+ methods, which all elements respond to.
3316
+
3317
+ === change() { |self| ... } » self ===
3318
+
3319
+ Each time a character is added to or removed from the edit line, its `change`
3320
+ block is called. The block is given `self`, which is the edit line object which
3321
+ has changed.
3322
+
3323
+ === focus() » self ===
3324
+
3325
+ Moves focus to the edit line. The edit line will be highlighted and the user
3326
+ will be able to type into the edit line.
3327
+
3328
+ === text() » self ===
3329
+
3330
+ Return a string of characters which have been typed into the box.
3331
+
3332
+ === text = a string ===
3333
+
3334
+ Fills the edit line with the characters of `a string`.
3335
+
3336
+ == Image ==
3337
+
3338
+ An image is a picture in PNG, JPEG or GIF format. Purple Shoes can resize images or
3339
+ flow them in with text. Images can be loaded from a file or directly off the
3340
+ web. !{:margin_left => 100}man-ele-image.png!
3341
+
3342
+ To create an image, use the `image` method in a slot:
3343
+
3344
+ {{{
3345
+ #!ruby
3346
+ Shoes.app do
3347
+ para "Nice, nice, very nice. Busy, busy, busy."
3348
+ image File.join DIR,
3349
+ "../static/shoes-manual-apps.png"
3350
+ end
3351
+ }}}
3352
+
3353
+ When you load any image into Purple Shoes, it is cached in memory. This means that if
3354
+ you load up many image elements from the same file, it'll only really load the
3355
+ file once.
3356
+
3357
+ You can use web URLs directly as well.
3358
+
3359
+ {{{
3360
+ #!ruby
3361
+ Shoes.app do
3362
+ image "http://is.gd/c0mBtb"
3363
+ end
3364
+ }}}
3365
+
3366
+ When an image is loaded from the web, it's cached on the hard drive as well as
3367
+ in memory. This prevents a repeat download unless the image has changed. (In
3368
+ case you're wondering: Shoes keeps track of modification times and etags just
3369
+ like a browser would.)
3370
+
3371
+ '''Note:''' Purple Shoes doesn't support the hard drive cache management feature like Red Shoes.
3372
+
3373
+ Purple Shoes also loads remote images in the background using system threads. So,
3374
+ using remote images will not block Ruby or any intense graphical displays you
3375
+ may have going on.
3376
+
3377
+ === full_height() » a number ===
3378
+
3379
+ The full pixel height of the image. Normally, you can just use the
3380
+ [[Common.height]] method to figure out how many pixels high the image is. But
3381
+ if you've resized the image or styled it to be larger or something, then
3382
+ `height` will return the scaled size.
3383
+
3384
+ The `full_height` method gives you the height of image (in pixels) as it was
3385
+ stored in the original file.
3386
+
3387
+ === full_width() » a number ===
3388
+
3389
+ The full pixel width of the image. See the [[Image.full_height]] method for an
3390
+ explanation of why you might use this method rather than [[Common.width]].
3391
+
3392
+ === path() » a string ===
3393
+
3394
+ The URL or file name of the image.
3395
+
3396
+ === path = a string ===
3397
+
3398
+ Swaps the image with a different one, loaded from a file or URL.
3399
+
3400
+ === rotate(degrees: a number) » self ===
3401
+
3402
+ Rotates the Image element by a certain number of `degrees`.
3403
+
3404
+ {{{
3405
+ Shoes.app do
3406
+ img = image File.join(DIR, '../samples/cy.png')
3407
+ img.move 200, 200
3408
+ animate do |i|
3409
+ img.rotate i*10
3410
+ end
3411
+ end
3412
+ }}}
3413
+
3414
+ == ListBox ==
3415
+
3416
+ List boxes (also called "combo boxes" or "drop-down boxes" or "select boxes" in
3417
+ some places) are a list of options that drop down when you click on the box.
3418
+ !{:margin_left => 100}man-ele-listbox.png!
3419
+
3420
+ A list box gets its options from an array. An array (a list) of strings,
3421
+ passed into the `:items` style.
3422
+
3423
+ {{{
3424
+ #!ruby
3425
+ Shoes.app do
3426
+ para "Choose a fruit:"
3427
+ list_box items: ["Grapes", "Pears", "Apricots"]
3428
+ end
3429
+ }}}
3430
+
3431
+ So, the basic size of a list box is about 200 pixels wide and 28 pixels high.
3432
+ You can adjust this length using the `:width` style.
3433
+
3434
+ {{{
3435
+ #!ruby
3436
+ Shoes.app do
3437
+ para "Choose a fruit:"
3438
+ list_box items: ["Grapes", "Pears", "Apricots"],
3439
+ width: 120, choose: "Apricots" do |list|
3440
+ @fruit.text = list.text
3441
+ end
3442
+
3443
+ @fruit = para "No fruit selected"
3444
+ end
3445
+ }}}
3446
+
3447
+ Next to the `:width` style, the example uses another useful option. The
3448
+ `:choose` option tells the list box which of the items should be highlighted
3449
+ from the beginning. (There's also a [[ListBox.choose]] method for highlighting
3450
+ an item after the box is created.)
3451
+
3452
+ List boxes also have a [[ListBox.change]] event. In the last example, we've got
3453
+ a block hooked up to the list box. Well, okay, see, that's a `change` block.
3454
+ The block is called each time someone changes the selected item.
3455
+
3456
+ Those are the basics. Might you also be persuaded to look at the [[Common]]
3457
+ methods page, a complete list of the methods that all elements have?
3458
+
3459
+ === change() { |self| ... } » self ===
3460
+
3461
+ Whenever someone highlights a new option in the list box (by clicking on an
3462
+ item, for instance,) its `change` block is called. The block is given `self`,
3463
+ which is the list box object which has changed.
3464
+
3465
+ === choose(item: a string) » self ===
3466
+
3467
+ Selects the option in the list box that matches the string given by `item`.
3468
+
3469
+ === focus() » self ===
3470
+
3471
+ Moves focus to the list box. The list box will be highlighted and, if the user
3472
+ hits the up and down arrow keys, other options in the list will be selected.
3473
+
3474
+ === items() » an array of strings ===
3475
+
3476
+ Returns the complete list of strings that the list box presently shows as its options.
3477
+
3478
+ === items = an array of strings ===
3479
+
3480
+ Replaces the list box's options with a new list of strings.
3481
+
3482
+ === text() » a string ===
3483
+
3484
+ A string containing whatever text is shown highlighted in the list box right
3485
+ now. If nothing is selected, `nil` will be the reply.
3486
+
3487
+ == Progress ==
3488
+
3489
+ Progress bars show you how far along you are in an activity. Usually, a
3490
+ progress bar represents a percentage (from 0% to 100%.) Purple Shoes thinks of
3491
+ progress in terms of the decimal numbers 0.0 to 1.0. !{:margin_left =>
3492
+ 100}man-ele-progress.png!
3493
+
3494
+ A simple progress bar is 150 pixels wide, but you can use the `:width` style
3495
+ (as with all Purple Shoes elements) to lengthen it.
3496
+
3497
+ '''Note:''' The minimum size is 150 pixels wide in Purple Shoes.
3498
+
3499
+ {{{
3500
+ Shoes.app do
3501
+ title "Progress example"
3502
+ @p = progress left: 10, top: 100, width: width-20
3503
+
3504
+ animate do |i|
3505
+ @p.fraction = (i % 100) / 100.0
3506
+ end
3507
+ end
3508
+ }}}
3509
+
3510
+ Take a look at the [[Common]] methods page for a list of methods found an all
3511
+ elements, including progress bars.
3512
+
3513
+ === fraction() » a decimal number ===
3514
+
3515
+ Returns a decimal number from 0.0 to 1.0, indicating how far along the progress bar is.
3516
+
3517
+ === fraction = a decimal number ===
3518
+
3519
+ Sets the progress to a decimal number between 0.0 and 1.0.
3520
+
3521
+ == Radio ==
3522
+
3523
+ Radio buttons are a group of clickable circles. Click a circle and it'll be
3524
+ marked. Only one radio button can be marked at a time. (This is similar to the
3525
+ ListBox, where only one option can be selected at a time.) !{:margin_left =>
3526
+ 100}man-ele-radio.png!
3527
+
3528
+ So, how do you decide when to use radio buttons and when to use list boxes?
3529
+ Well, list boxes only show one highlighted item unless you click on the box and
3530
+ the drop-down appears. But radio buttons are all shown, regardless of which is
3531
+ marked.
3532
+
3533
+ {{{
3534
+ #!ruby
3535
+ Shoes.app do
3536
+ para "Among these films, which do you prefer?\n"
3537
+ radio
3538
+ para strong("The Taste of Tea"),
3539
+ " by Katsuhito Ishii\n", width: 570
3540
+ radio
3541
+ para strong("Kin-Dza-Dza"),
3542
+ " by Georgi Danelia\n", width: 570
3543
+ radio
3544
+ para strong("Children of Heaven"),
3545
+ " by Majid Majidi\n", width: 570
3546
+ end
3547
+ }}}
3548
+
3549
+ Only one of these three radios can be checked at a time, since they are grouped
3550
+ together in the same slot (along with a bunch of `para`.)
3551
+
3552
+ If we move them each into their own slot, the example breaks.
3553
+
3554
+ {{{
3555
+ #!ruby
3556
+ Shoes.app do
3557
+ stack do
3558
+ para "Among these films, which do you prefer?"
3559
+ flow do
3560
+ radio
3561
+ para "The Taste of Tea by Katsuhito Ishii",
3562
+ width: 300
3563
+ end
3564
+ flow do
3565
+ radio
3566
+ para "Kin-Dza-Dza by Georgi Danelia",
3567
+ width: 300
3568
+ end
3569
+ flow do
3570
+ radio
3571
+ para "Children of Heaven by Majid Majidi",
3572
+ width: 300
3573
+ end
3574
+ end
3575
+ end
3576
+ }}}
3577
+
3578
+ This can be fixed, though. You can group together radios from different slots,
3579
+ you just have to give them all the same group name.
3580
+
3581
+ Here, let's group all these radios in the `:films` group.
3582
+
3583
+ {{{
3584
+ #!ruby
3585
+ Shoes.app do
3586
+ stack do
3587
+ para "Among these films, which do you prefer?"
3588
+ flow do
3589
+ radio :films
3590
+ para "The Taste of Tea by Katsuhito Ishii",
3591
+ width: 300
3592
+ end
3593
+ flow do
3594
+ radio :films
3595
+ para "Kin-Dza-Dza by Georgi Danelia",
3596
+ width: 300
3597
+ end
3598
+ flow do
3599
+ radio :films
3600
+ para "Children of Heaven by Majid Majidi",
3601
+ width: 300
3602
+ end
3603
+ end
3604
+ end
3605
+ }}}
3606
+
3607
+ For more methods beyond those listed below, also look into the [[Common]]
3608
+ methods page. Because you get those methods on every radio as well.
3609
+
3610
+ === checked?() » true or false ===
3611
+
3612
+ Returns whether the radio button is checked or not. So, `true` means "yes, it
3613
+ is checked!"
3614
+
3615
+ === checked = true or false ===
3616
+
3617
+ Marks or unmarks the radio button. Using `checked = false`, for instance,
3618
+ clears the radio.
3619
+
3620
+ === click() { |self| ... } » self ===
3621
+
3622
+ When the radio button is clicked, its `click` block is called. The block is
3623
+ handed `self`, which is an object representing the radio which was clicked.
3624
+
3625
+ Clicks are sent for both marking and unmarking the radio.
3626
+
3627
+ === focus() » self ===
3628
+
3629
+ Moves focus to the radio. The radio will be highlighted.
3630
+
3631
+ == Shape ==
3632
+
3633
+ A shape is a path outline usually created by drawing methods like `oval` and
3634
+ `rect`. !{:margin_left => 100}man-ele-shape.png!
3635
+
3636
+ See the [[Common]] methods page. Shapes respond to all of those methods.
3637
+
3638
+ == TextBlock ==
3639
+
3640
+ The TextBlock object represents a group of text organized as a single element.
3641
+ A paragraph containing bolded text, for example. A caption containing links and
3642
+ bolded text. (So, a `caption` is a TextBlock type. However, `link` and
3643
+ `strong` are Text types.) !{:margin_left => 100}man-ele-textblock.png!
3644
+
3645
+ All of the various types of TextBlock are found on the [[Element Element
3646
+ Creation]] page.
3647
+
3648
+ * [[Element.banner]], a 48 pixel font.
3649
+ * [[Element.title]], a 34 pixel font.
3650
+ * [[Element.subtitle]], a 26 pixel font.
3651
+ * [[Element.tagline]], an 18 pixel font.
3652
+ * [[Element.caption]], a 14 pixel font.
3653
+ * [[Element.para]], a 12 pixel font.
3654
+ * [[Element.inscription]], a 10 pixel font.
3655
+
3656
+ === contents() » an array of elements ===
3657
+
3658
+ Lists all of the strings and styled text objects inside this block.
3659
+
3660
+ '''Note:''' Purple Shoes doesn't support `contents` method.
3661
+
3662
+ === cursor() » an index ===
3663
+
3664
+ Return a text cursor position. That is an index of the text which is a string
3665
+ of all of the characters in this text box.
3666
+
3667
+ === cursor = an index or nil ===
3668
+
3669
+ Shows or hides the text cursor.
3670
+ Using `cursor = 3`, for instance, shows the text cursor at index 3 from the front.
3671
+ Using `cursor = -1` shows the text cursor at the end of the text.
3672
+ Using `cursor = nil` hides the text cursor.
3673
+
3674
+ {{{
3675
+ Shoes.app do
3676
+ msg = para 'hello ' * 20
3677
+ msg.cursor = -1
3678
+ keypress do |k|
3679
+ n = case k
3680
+ when 'Left'; -1
3681
+ when 'Right'; 1
3682
+ else
3683
+ next
3684
+ end
3685
+ n += msg.cursor
3686
+ len = msg.text.length
3687
+ n = len unless n > -1
3688
+ msg.cursor = n % (len+1)
3689
+ flush
3690
+ end
3691
+ end
3692
+ }}}
3693
+
3694
+ === highlight() » an array ===
3695
+
3696
+ Return an array which includes a text marker start position and highlighted length.
3697
+
3698
+ === hit(left, top) » an index or nil ===
3699
+
3700
+ Return an index of the text at which the mouse cursor points on.
3701
+ The `left` and `top` are the mouse coordinates.
3702
+
3703
+ {{{
3704
+ Shoes.app do
3705
+ para 'index: ', width: 50
3706
+ index = para '', width: 20
3707
+ msg = title 'hello ' * 5
3708
+ click do |b, x, y|
3709
+ index.text = msg.hit x, y
3710
+ end
3711
+ end
3712
+ }}}
3713
+
3714
+ === marker() » an index ===
3715
+
3716
+ Return a text marker start position.
3717
+
3718
+ === marker = an index ===
3719
+
3720
+ Highlight a part of text from marker start position to cursor position.
3721
+
3722
+ {{{
3723
+ Shoes.app do
3724
+ background gainsboro
3725
+ extend HH::Markup
3726
+ code = 'alert "Hello Purple Shoes! " * 5'
3727
+ msg = para highlight code, nil
3728
+ button 'marker' do
3729
+ msg.cursor = 17
3730
+ msg.marker = 14
3731
+ msg.text = highlight msg.markup, nil
3732
+ para msg.highlight
3733
+ flush
3734
+ end
3735
+ end
3736
+ }}}
3737
+
3738
+ === markup() » a text ===
3739
+
3740
+ Return some marked-up text for Pango.
3741
+
3742
+ === replace(a string) ===
3743
+
3744
+ Replaces the text of the entire block with the characters of `a string`.
3745
+
3746
+ === text() » a string ===
3747
+
3748
+ Return a string of all of the characters in this text box. This will strip off
3749
+ any style or text classes and just return the actual characters, as if seen on
3750
+ the screen.
3751
+
3752
+ === text = a string ===
3753
+
3754
+ Replaces the text of the entire block with the characters of `a string`.
3755
+
3756
+ === to_s() » a string ===
3757
+
3758
+ An alias for [[TextBlock.text]]. Returns a flattened string of all of this
3759
+ TextBlock's contents.
3760
+
3761
+ '''Note:''' Purple Shoes doesn't support `to_s` method.
3762
+
3763
+ == Timers ==
3764
+
3765
+ Purple Shoes contains three timers: the animate, every and
3766
+ timer. Both animate and every loop over and over after they
3767
+ start. The timer happens once. A one-shot timer.
3768
+
3769
+ The animate and every are basically the same thing. The difference is that
3770
+ the animate usually happen many, many times per second. And the every happens only
3771
+ once every few seconds or rarely.
3772
+
3773
+ The animate and every automatically start themselves.
3774
+
3775
+ === start() » self ===
3776
+
3777
+ Both types of timers automatically start themselves, so there's no need to use
3778
+ this normally. But if you [[Timers.stop]] a timer and would like to start it up
3779
+ again, then by all means: use this!
3780
+
3781
+ '''Note:''' Purple Shoes doesn't support `start` method.
3782
+
3783
+ === stop() » self ===
3784
+
3785
+ Stops the animate or every loop.
3786
+
3787
+ === pause() » self ===
3788
+
3789
+ Pauses the animate or every loop. If the animate or every loop is stopped, it is started. Otherwise, if it is
3790
+ already running, it is stopped.
3791
+
3792
+ == Video ==
3793
+
3794
+ Purple Shoes supports embedding of MP4, AVI, WMV, QuickTime and various other popular video formats.
3795
+ This is all thanks to Ruby/GStreamer. Use the `video` method to setup a Shoes::Video object. !{:margin_left => 70}man-ele-video.png!
3796
+
3797
+ {{{
3798
+ Shoes.app width: 400, height: 300 do
3799
+ background gold..cyan, angle: 90
3800
+ space = ' ' * 3
3801
+ v = video 'http://is.gd/xZ6Jih'
3802
+ links = para space,
3803
+ link('play'){v.play; links.move(0, 300)},
3804
+ space, link('pause'){v.pause},
3805
+ space, link('-1sec'){v.time -= 1000},
3806
+ space, link('+1sec'){v.time += 1000},
3807
+ top: 250
3808
+ msg = para left: 250, top: 300
3809
+ every do
3810
+ msg.text = fg("#{(v.position*100).to_i}% " +
3811
+ "(#{v.time/1000}/#{v.length.to_i/1000}sec)",
3812
+ darkcyan)
3813
+ end
3814
+ end
3815
+ }}}
3816
+
3817
+ In addition to video formats, some audio formats are also supported, such as MP3, WAV and Ogg Vorbis.
3818
+
3819
+ === hide() » self ===
3820
+
3821
+ Hides the video. If already playing, the video will continue to play. This just
3822
+ turns off display of the video. One possible use of this method is to collapse
3823
+ the video area when it is playing an audio file, such as an MP3.
3824
+
3825
+ '''Note:''' Purple Shoes doesn't support hide method so far.
3826
+
3827
+ === length() » a number ===
3828
+
3829
+ The full length of the video in milliseconds. Returns nil if the video is not
3830
+ yet loaded.
3831
+
3832
+ === move(left, top) » self ===
3833
+
3834
+ Moves the video to specific coordinates, the (left, top) being the upper left
3835
+ hand corner of the video.
3836
+
3837
+ '''Note:''' Purple Shoes doesn't support move method so far.
3838
+
3839
+ === pause() » self ===
3840
+
3841
+ Pauses the video, if it is playing.
3842
+
3843
+ === playing?() » true of false ===
3844
+
3845
+ Returns true if the video is currently playing. Or, false if the video is
3846
+ paused or stopped.
3847
+
3848
+ === play() » self ===
3849
+
3850
+ Starts playing the video, if it isn't already playing. If already playing, the
3851
+ video is restarted from the beginning.
3852
+
3853
+ === position() » a decimal ===
3854
+
3855
+ The position of the video as a decimanl number (a Float) between the beginning
3856
+ (0.0) and the end (1.0). For instance, a Float value of 0.5 indicates the
3857
+ halfway point of the video.
3858
+
3859
+ === position = a decimal ===
3860
+
3861
+ Sets the position of the video using a Float value. To move the video to its
3862
+ 25% position: `@video.position = 0.25`.
3863
+
3864
+ === remove() » self ===
3865
+
3866
+ Removes the video from its slot. This will stop the video as well.
3867
+
3868
+ '''Note:''' Purple Shoes doesn't support remove method so far.
3869
+
3870
+ === show() » self ===
3871
+
3872
+ Reveals the video, if it has been hidden by the `hide()` method.
3873
+
3874
+ '''Note:''' Purple Shoes doesn't support show method so far.
3875
+
3876
+ === stop() » self ===
3877
+
3878
+ Stops the video, if it is playing.
3879
+
3880
+ === time() » a number ===
3881
+
3882
+ The time position of the video in milliseconds. So, if the video is 10 seconds
3883
+ into play, this method would return the number 10000.
3884
+
3885
+ === time = a number ===
3886
+
3887
+ Set the position of the video to a time in milliseconds.
3888
+
3889
+ === toggle() » self ===
3890
+
3891
+ Toggles the visibility of the video. If the video can be seen, then `hide` is
3892
+ called. Otherwise, `show` is called.
3893
+
3894
+ '''Note:''' Purple Shoes doesn't support tobble method so far.
3895
+
3896
+ = AndSoForth =
3897
+
3898
+ A place for some other information.
3899
+
3900
+ == Sample Apps ==
3901
+
3902
+ Have fun!
3903
+
3904
+ {SAMPLES}
3905
+
3906
+ == FAQ ==
3907
+
3908
+ Hope this helps:
3909
+
3910
+ * You can join [[http://librelist.com/browser/shoes/ Shoes ML]] and feel free ask your questions.
3911
+ * [[https://github.com/ashbb/purple_shoes/ Current Source Code]] is on GitHub.
3912
+ * Purple Shoes Gem is on [[http://rubygems.org/gems/purple_shoes RubyGems.org]].
3913
+
3914
+ == vs.RedShoes ==
3915
+
3916
+ Purple Shoes is following Red Shoes, but not fully compatible.
3917
+
3918
+ ==== TextBlock ====
3919
+
3920
+ The following two snippets are same in Red Shoes.
3921
+
3922
+ {{{
3923
+ Shoes.app do
3924
+ para 'hello ' * 20
3925
+ end
3926
+ }}}
3927
+
3928
+ {{{
3929
+ Shoes.app do
3930
+ 20.times{para 'hello '}
3931
+ end
3932
+ }}}
3933
+
3934
+ But in Purple Shoes, need to add `:width` size explicitly.
3935
+
3936
+ {{{
3937
+ Shoes.app do
3938
+ 20.times{para 'hello ', width: 40}
3939
+ end
3940
+ }}}
3941
+
3942
+ If you don't specify the `:width` size, Purple Shoes makes a TextBlock object with
3943
+ the `parent.width`.
3944
+
3945
+ For more information, go to [[http://ashbb.github.com/green_shoes/Red_Shoes_and_Green_Shoes.html Red Shoes and Green Shoes]].
3946
+
3947
+ == gshoes ==
3948
+
3949
+ '''gshoes''' is a gem executable command which has some options. Just open console window and try to run `gshoes (options or app.rb or app.gsy)`.
3950
+
3951
+ === -m, -men ===
3952
+
3953
+ Open the built-in English manual.
3954
+
3955
+ === -mjp ===
3956
+
3957
+ Open the built-in Japanese manual.
3958
+
3959
+ === -p ===
3960
+
3961
+ Package a Purple Shoes app as a .gsy file. GSY, which stands for Purple Shoes YAML.
3962
+
3963
+ === -v ===
3964
+
3965
+ Display the version info.
3966
+
3967
+ === -h ===
3968
+
3969
+ Show the help message.