glimmer-dsl-libui 0.0.6 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for LibUI 0.0.6
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for LibUI 0.0.10
2
2
  ## Prerequisite-Free Ruby Desktop Development GUI Library
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-libui.svg)](http://badge.fury.io/rb/glimmer-dsl-libui)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/ce2853efdbecf6ebdc73/maintainability)](https://codeclimate.com/github/AndyObtiva/glimmer-dsl-libui/maintainability)
@@ -6,18 +6,18 @@
6
6
 
7
7
  [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [LibUI](https://github.com/kojix2/LibUI) is a prerequisite-free Ruby desktop development GUI library. No need to pre-install any prerequisites. Just install the gem and have platform-independent native GUI that just works!
8
8
 
9
- [LibUI](https://github.com/kojix2/LibUI) is a thin [Ruby](https://www.ruby-lang.org/en/) wrapper around [libui](https://github.com/andlabs/libui), a relatively new C GUI library that renders native widgets on every platform (similar to [SWT](https://www.eclipse.org/swt/), but without the heavy weight of the [Java Virtual Machine](https://www.java.com/en/)).
9
+ [LibUI](https://github.com/kojix2/LibUI) is a thin [Ruby](https://www.ruby-lang.org/en/) wrapper around [libui](https://github.com/andlabs/libui), a relatively new C GUI library that renders native controls on every platform (similar to [SWT](https://www.eclipse.org/swt/), but without the heavy weight of the [Java Virtual Machine](https://www.java.com/en/)).
10
10
 
11
11
  The main trade-off in using [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) as opposed to [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) or [Glimmer DSL for Tk](https://github.com/AndyObtiva/glimmer-dsl-tk) is the fact that [SWT](https://www.eclipse.org/swt/) and [Tk](https://www.tcl.tk/) are more mature than mid-alpha [libui](https://github.com/andlabs/libui) as GUI toolkits. Still, if there is only a need to build a small simple application, [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) could be a good convenient choice due to having zero prerequisites beyond the dependencies included in the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui). Also, just like [Glimmer DSL for Tk](https://github.com/AndyObtiva/glimmer-dsl-tk), its apps start instantly and have a small memory footprint. [LibUI](https://github.com/kojix2/LibUI) is a promising new GUI toolkit that might prove quite worthy in the future.
12
12
 
13
13
  [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) aims to provide a DSL similar to the [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) to enable more productive desktop development in Ruby with:
14
- - Declarative DSL syntax that visually maps to the GUI widget hierarchy
14
+ - Declarative DSL syntax that visually maps to the GUI control hierarchy
15
15
  - Convention over configuration via smart defaults and automation of low-level details
16
16
  - Requiring the least amount of syntax possible to build GUI
17
17
  - Bidirectional Data-Binding to declaratively wire and automatically synchronize GUI with Business Models
18
- - Custom Widget support
19
- - Scaffolding for new custom widgets, apps, and gems
20
- - Native-Executable packaging on Mac, Windows, and Linux
18
+ - Custom Control support
19
+ - Scaffolding for new custom controls, apps, and gems
20
+ - Native-Executable packaging on Mac, Windows, and Linux.
21
21
 
22
22
  Example:
23
23
 
@@ -26,13 +26,13 @@ require 'glimmer-dsl-libui'
26
26
 
27
27
  include Glimmer
28
28
 
29
- window('hello world', 300, 200, 1).show
29
+ window('hello world').show
30
30
  ```
31
31
 
32
32
  ![glimmer-dsl-libui-mac-basic-window.png](images/glimmer-dsl-libui-mac-basic-window.png)
33
33
  ![glimmer-dsl-libui-linux-basic-window.png](images/glimmer-dsl-libui-linux-basic-window.png)
34
34
 
35
- NOTE: [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) is in early alpha mode (only supports included examples). Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
35
+ NOTE: [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) is in early alpha mode (only supports included [examples](#examples)). Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
36
36
 
37
37
  Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interested in:
38
38
  - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
@@ -43,14 +43,18 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
43
43
 
44
44
  ## Table of Contents
45
45
 
46
- - [Glimmer DSL for LibUI 0.0.6](#-glimmer-dsl-for-libui-006)
46
+ - [Glimmer DSL for LibUI 0.0.10](#-glimmer-dsl-for-libui-0010)
47
47
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
48
48
  - [Usage](#usage)
49
49
  - [API](#api)
50
50
  - [Supported Controls](#supported-controls)
51
51
  - [Common Control Properties](#common-control-properties)
52
52
  - [Common Control Operations](#common-control-operations)
53
+ - [Extra Dialogs](#extra-dialogs)
53
54
  - [Extra Operations](#extra-operations)
55
+ - [Smart Defaults and Conventions](#smart-defaults-and-conventions)
56
+ - [Original API](#original-api)
57
+ - [Glimmer Style Guide](#glimmer-style-guide)
54
58
  - [Girb (Glimmer IRB)](#girb-glimmer-irb)
55
59
  - [Examples](#examples)
56
60
  - [Basic Window](#basic-window)
@@ -59,6 +63,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
59
63
  - [Simple Notepad](#simple-notepad)
60
64
  - [Midi Player](#midi-player)
61
65
  - [Control Gallery](#control-gallery)
66
+ - [Font Button](#font-button)
62
67
  - [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
63
68
  - [Help](#help)
64
69
  - [Issues](#issues)
@@ -73,14 +78,14 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
73
78
 
74
79
  The Glimmer GUI DSL provides object-oriented declarative hierarchical syntax for [LibUI](https://github.com/kojix2/LibUI) that:
75
80
  - Supports smart defaults (e.g. automatic `on_closing` listener that quits `window`)
76
- - Automates wiring of widgets (e.g. `button` is automatically set as child of `window`)
81
+ - Automates wiring of controls (e.g. `button` is automatically set as child of `window`)
77
82
  - Hides lower-level details (e.g. `LibUI.main` loop is started automatically when triggering `show` on `window`)
78
- - Nests widgets according to their visual hierarchy
83
+ - Nests controls according to their visual hierarchy
79
84
  - Requires the minimum amount of syntax needed to describe an app's GUI
80
85
 
81
86
  The Glimmer GUI DSL follows these simple concepts in mapping from [LibUI](https://github.com/kojix2/LibUI) syntax:
82
- - **Control**: [LibUI](https://github.com/kojix2/LibUI) controls may be declared by lower-case underscored name (aka keyword) (e.g. `window` or `button`). Behind the scenes, they are represented by keyword methods that map to corresponding `LibUI.new_keyword` methods receiving args (e.g. `window('hello world', 300, 200, 1)`).
83
- - **Content/Properties/Listeners Block**: Any keyword may be optionally followed by a Ruby curly-brace multi-line-block containing nested controls (content) and/or properties (attributes) (e.g. `window('hello world', 300, 200, 1) {button('greet')}`). It optionally recives one arg representing the control (e.g. `button('greet') {|b| on_clicked { puts b.text}}`)
87
+ - **Control**: [LibUI](https://github.com/kojix2/LibUI) controls may be declared by lower-case underscored name (aka keyword) (e.g. `window` or `button`). Behind the scenes, they are represented by keyword methods that map to corresponding `LibUI.new_keyword` methods receiving args (e.g. `window('hello world', 300, 200, true)`).
88
+ - **Content/Properties/Listeners Block**: Any keyword may be optionally followed by a Ruby curly-brace multi-line-block containing nested controls (content) and/or properties (attributes) (e.g. `window('hello world', 300, 200, true) {button('greet')}`). It optionally receives one arg representing the control (e.g. `button('greet') {|b| on_clicked { puts b.text}}`)
84
89
  - **Property**: Control properties may be declared inside keyword blocks with lower-case underscored name followed by property value args (e.g. `title "hello world"` inside `group`). Behind the scenes, properties correspond to `control_set_property` methods.
85
90
  - **Listener**: Control listeners may be declared inside keyword blocks with listener lower-case underscored name beginning with `on_` and receiving required block handler (e.g. `on_clicked {puts 'clicked'}` inside `button`). Behind the scenes, listeners correspond to `control_on_event` methods.
86
91
 
@@ -122,7 +127,7 @@ require 'glimmer-dsl-libui'
122
127
 
123
128
  include Glimmer
124
129
 
125
- window('hello world', 300, 200, 1) { |w|
130
+ window('hello world', 300, 200) { |w|
126
131
  button('Button') {
127
132
  on_clicked do
128
133
  msg_box(w, 'Information', 'You clicked the button')
@@ -146,7 +151,7 @@ gem install glimmer-dsl-libui
146
151
  Or install via Bundler `Gemfile`:
147
152
 
148
153
  ```ruby
149
- gem 'glimmer-dsl-libui', '~> 0.0.6'
154
+ gem 'glimmer-dsl-libui', '~> 0.0.10'
150
155
  ```
151
156
 
152
157
  Add `require 'glimmer-dsl-libui'` at the top, and then `include Glimmer` into the top-level main object for testing or into an actual class for serious usage.
@@ -160,7 +165,7 @@ class Application
160
165
  include Glimmer
161
166
 
162
167
  def launch
163
- window('hello world', 300, 200, 1) {
168
+ window('hello world', 300, 200) {
164
169
  button('Button') {
165
170
  on_clicked do
166
171
  puts 'Button Clicked'
@@ -203,44 +208,44 @@ Control(Args) | Properties | Listeners
203
208
  ------------- | ---------- | ---------
204
209
  `about_menu_item` | None | `on_clicked`
205
210
  `button(text as String)` | `text` (`String`) | `on_clicked`
206
- `checkbox(text as String)` | `checked` (`1` or `0`), `text` (`String`) | `on_toggled`
207
- `combobox` | `items` (`Array` of `String`), `selected` (`1` or `0`) | `on_selected`
208
- `color_button` | `color` (r `Numeric`, g `Numeric`, b `Numeric`, a `Numeric`), `selected` (`1` or `0`) | `on_selected`
209
- `date_picker` | None | None
210
- `date_time_picker` | `time` (`UI::FFI::TM`) | `on_changed`
211
+ `checkbox(text as String)` | `checked` (Boolean), `text` (`String`) | `on_toggled`
212
+ `combobox` | `items` (`Array` of `String`), `selected` (`Integer`) | `on_selected`
213
+ `color_button` | `color` (r `Numeric`, g `Numeric`, b `Numeric`, a `Numeric`) | `on_changed`
214
+ `date_picker` | `time` (`LibUI::FFI::TM`) | `on_changed`
215
+ `date_time_picker` | `time` (`LibUI::FFI::TM`) | `on_changed`
211
216
  `editable_combobox` | `items` (`Array` of `String`), `text` (`String`) | `on_changed`
212
- `entry` | `read_only` (`1` or `0`), `text` (`String`) | `on_changed`
213
- `font_button` | `font` (`UI::FFI::FontDescriptor`) | `on_changed`
214
- `group(text as String)` | `margined` (`1` or `0`), `title` (`String`) | None
215
- `horizontal_box` | `padded` (`1` or `0`) | None
217
+ `entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
218
+ `font_button` | `font` [read-only] (`Hash` of keys: `:family`, `:size`, `:weight`, `:italic`, `:stretch`) | `on_changed`
219
+ `group(text as String)` | `margined` (Boolean), `title` (`String`) | None
220
+ `horizontal_box` | `padded` (Boolean) | None
216
221
  `horizontal_separator` | None | None
217
222
  `label(text as String)` | `text` (`String`) | None
218
223
  `menu(text as String)` | None | None
219
- `menu_item(text as String)` | `checked` (`1` or `0`) | `on_clicked`
220
- `multiline_entry` | `read_only` (`1` or `0`), `text` (`String`) | `on_changed`
224
+ `menu_item(text as String)` | `checked` (Boolean) | `on_clicked`
225
+ `multiline_entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
221
226
  `msg_box(window as Glimmer::LibUI::WindowProxy, title as String, description as String)` | None | None
222
227
  `msg_box_error(window as Glimmer::LibUI::WindowProxy, title as String, description as String)` | None | None
223
- `non_wrapping_multiline_entry` | `read_only` (`1` or `0`), `text` (`String`) | `on_changed`
228
+ `non_wrapping_multiline_entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
224
229
  `preferences_menu_item` | None | `on_clicked`
225
230
  `progress_bar` | `value` (`Numeric`) | None
226
231
  `quit_menu_item` | None | `on_clicked`
227
- `radio_buttons` | `selected` (`1` or `0`) | `on_selected`
232
+ `radio_buttons` | `selected` (`Integer`) | `on_selected`
228
233
  `slider(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
229
234
  `spinbox(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
230
- `tab` | `margined` (`1` or `0`), `num_pages` (`Integer`) | None
231
- `tab_item(name as String)` | `index` [read-only] (`Integer`), `margined` (`1` or `0`), `name` [read-only] (`String`) | None
232
- `time_picker` | None | None
233
- `vertical_box` | `padded` (`1` or `0`) | None
234
- `window(title as String, width as Integer, height as Integer, has_menubar as 1 or 0)` | `borderless` (`1` or `0`), `content_size` (width `Numeric`, height `Numeric`), `fullscreen` (`1` or `0`), `margined` (`1` or `0`), `title` (`String`) | `on_closing`, `on_content_size_changed`
235
+ `tab` | `margined` (Boolean), `num_pages` (`Integer`) | None
236
+ `tab_item(name as String)` | `index` [read-only] (`Integer`), `margined` (Boolean), `name` [read-only] (`String`) | None
237
+ `time_picker` | `time` (`LibUI::FFI::TM`) | `on_changed`
238
+ `vertical_box` | `padded` (Boolean) | None
239
+ `window(title as String, width as Integer, height as Integer, has_menubar as Boolean)` | `borderless` (Boolean), `content_size` (width `Numeric`, height `Numeric`), `fullscreen` (Boolean), `margined` (Boolean), `title` (`String`) | `on_closing`, `on_content_size_changed`
235
240
 
236
241
  ### Common Control Properties
237
- - `enabled` (`1` or `0`)
242
+ - `enabled` (Boolean)
238
243
  - `libui` (`Fiddle::Pointer`): returns wrapped [LibUI](https://github.com/kojix2/LibUI) object
239
244
  - `parent_proxy` (`Glimmer::LibUI::ControlProxy` or subclass)
240
245
  - `parent` (`Fiddle::Pointer`)
241
- - `toplevel` [read-only] (`1` or `0`)
242
- - `visible` (`1` or `0`)
243
- - `stretchy` [dsl-only] (`1` or `0`): available in [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) when nested under `horizontal_box` or `vertical_box`
246
+ - `toplevel` [read-only] (Boolean)
247
+ - `visible` (Boolean)
248
+ - `stretchy` [dsl-only] (Boolean): available in [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) when nested under `horizontal_box` or `vertical_box`
244
249
 
245
250
  ### Common Control Operations
246
251
  - `destroy`
@@ -249,11 +254,45 @@ Control(Args) | Properties | Listeners
249
254
  - `hide`
250
255
  - `show`
251
256
 
252
- ### Extra Operations
257
+ ### Extra Dialogs
258
+
253
259
  - `open_file(window as Glimmer::LibUI::WindowProxy)`: returns selected file (`String`) or `nil` if cancelled
254
260
  - `save_file(window as Glimmer::LibUI::WindowProxy)`: returns selected file (`String`) or `nil` if cancelled
255
261
 
256
- To learn more about the [LibUI](https://github.com/kojix2/LibUI) API exposed through [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui), check out the [libui C headers](https://github.com/andlabs/libui/blob/master/ui.h)
262
+ ### Extra Operations
263
+
264
+ - `ControlProxy::all_control_proxies`: returns all instantiated control proxies in the application
265
+ - `ControlProxy::main_window_proxy`: returns the first window proxy instantiated in the application
266
+ - `ControlProxy#window_proxy`: returns the window proxy parent for a control
267
+
268
+ ### Smart Defaults and Conventions
269
+
270
+ - `horizontal_box` and `vertical_box` controls have `padded` as `true` upon instantiation to ensure more user-friendly GUI by default
271
+ - `group` controls have `margined` as `true` upon instantiation to ensure more user-friendly GUI by default
272
+ - All controls nested under a `horizontal_box` or `vertical_box` have `stretchy` property (passed to `box_append` method) as `true` by default (filling maximum space)
273
+ - `window` constructor args can be left off and have the following defaults when unspecified: `title` as `'Glimmer'`, `width` as `150`, `height` as `150`, and `has_menubar` as `true`)
274
+ - `window` has an `on_closing` listener by default that quits application upon hitting the close button (can be overridden with a manual `on_closing` implementation that returns integer `0` for success)
275
+ - `quit_menu_item` has an `on_clicked` listener by default that quits application upon selecting the quit menu item (can be overridden with a manual `on_clicked` implementation that returns integer `0` for success)
276
+ - If an `on_closing` listener was defined on `window` and it does not return an integer, default exit behavior is assumed (`window.destroy` is called followed by `LibUI.quit`, returning `0`).
277
+ - If an `on_clicked` listener was defined on `quit_menu_item` and it does not return an integer, default exit behavior is assumed (`main_window.destroy` is called followed by `LibUI.quit`, returning `0`).
278
+ - All boolean property readers return `true` or `false` in Ruby instead of the [libui](https://github.com/andlabs/libui) original `0` or `1` in C.
279
+ - All boolean property writers accept `true`/`false` in addition to `1`/`0` in Ruby
280
+ - All string property readers return a `String` object in Ruby instead of the [libui](https://github.com/andlabs/libui) Fiddle pointer object.
281
+ - Automatically allocate font descriptors upon instantiating `font_button` controls and free font descriptors when destorying `font_button` controls
282
+
283
+ ### Original API
284
+
285
+ To learn more about the [LibUI](https://github.com/kojix2/LibUI) API exposed through [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui),
286
+ check out the [libui C headers](https://github.com/andlabs/libui/blob/master/ui.h)
287
+
288
+ ## Glimmer Style Guide
289
+
290
+ - Control arguments are always wrapped inside parentheses
291
+ - Control blocks are always declared with curly braces to clearly visualize hierarchical view code and separate from logic code
292
+ - Control property declarations always have arguments and never take a block
293
+ - Control property arguments are never wrapped inside parentheses
294
+ - Control listeners are always declared starting with on_ prefix and affixing listener event method name afterwards in underscored lowercase form. Their multi-line blocks have a `do; end` style.
295
+ - Pure logic multi-line blocks that do not constitute GUI DSL view elements have `do; end` style to clearly separate logic code from view code.
257
296
 
258
297
  ## Girb (Glimmer IRB)
259
298
 
@@ -269,7 +308,96 @@ Gotcha: On the Mac, when you close a window opened in `girb`, it remains open un
269
308
 
270
309
  ## Examples
271
310
 
272
- These examples reimplement the ones in the [LibUI](https://github.com/kojix2/LibUI) project utilizing the [Glimmer GUI DSL](#glimmer-gui-dsl-concepts).
311
+ These examples include reimplementions of the examples in the [LibUI](https://github.com/kojix2/LibUI) project utilizing the [Glimmer GUI DSL](#glimmer-gui-dsl-concepts).
312
+
313
+ To browse all examples, simply launch the [Meta-Example](examples/meta_example.rb), which lists all examples and displays each example's code when selected.
314
+
315
+ [examples/meta_example.rb](examples/meta_example.rb)
316
+
317
+ Run with this command from the root of the project if you cloned the project:
318
+
319
+ ```
320
+ ruby -r './lib/glimmer-dsl-libui' examples/meta_example.rb
321
+ ```
322
+
323
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
324
+
325
+ ```
326
+ ruby -r glimmer-dsl-libui -e "require 'examples/meta_example'"
327
+ ```
328
+
329
+ Mac
330
+
331
+ ![glimmer-dsl-libui-mac-meta-example.png](images/glimmer-dsl-libui-mac-meta-example.png)
332
+
333
+ Linux
334
+
335
+ ![glimmer-dsl-libui-linux-meta-example.png](images/glimmer-dsl-libui-linux-meta-example.png)
336
+
337
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
338
+
339
+ ```ruby
340
+ require 'glimmer-dsl-libui'
341
+ require 'facets'
342
+
343
+ class MetaExample
344
+ include Glimmer
345
+
346
+ def examples
347
+ if @examples.nil?
348
+ example_files = Dir.glob(File.join(File.expand_path('.', __dir__), '**', '*.rb'))
349
+ example_file_names = example_files.map { |f| File.basename(f, '.rb') }
350
+ example_file_names = example_file_names.reject { |f| f == 'meta_example' }
351
+ @examples = example_file_names.map { |f| f.underscore.titlecase }
352
+ end
353
+ @examples
354
+ end
355
+
356
+ def file_path_for(example)
357
+ File.join(File.expand_path('.', __dir__), "#{example.underscore}.rb")
358
+ end
359
+
360
+ def launch
361
+ menu('File') {
362
+ quit_menu_item
363
+ }
364
+
365
+ window('Meta-Example', 700, 500) { |w|
366
+ margined true
367
+
368
+ horizontal_box {
369
+ vertical_box {
370
+ @rbs = radio_buttons {
371
+ stretchy false
372
+ items examples
373
+ selected 0
374
+
375
+ on_selected do
376
+ @nwme.text = File.read(file_path_for(@examples[@rbs.selected]))
377
+ end
378
+ }
379
+ button('Launch') {
380
+ stretchy false
381
+
382
+ on_clicked do
383
+ system "ruby -r puts_debuggerer -r #{File.expand_path('../lib/glimmer-dsl-libui', __dir__)} #{file_path_for(@examples[@rbs.selected])}"
384
+ end
385
+ }
386
+ }
387
+ vertical_box {
388
+ @nwme = non_wrapping_multiline_entry {
389
+ read_only true
390
+ text File.read(file_path_for(@examples[@rbs.selected]))
391
+ }
392
+ }
393
+ }
394
+ }.show
395
+ end
396
+ end
397
+
398
+ MetaExample.new.launch
399
+ ```
400
+
273
401
 
274
402
  ### Basic Window
275
403
 
@@ -326,7 +454,7 @@ require 'glimmer-dsl-libui'
326
454
 
327
455
  include Glimmer
328
456
 
329
- window('hello world', 300, 200, 1) {
457
+ window('hello world', 300, 200, true) {
330
458
  on_closing do
331
459
  puts 'Bye Bye'
332
460
  end
@@ -397,7 +525,7 @@ require 'glimmer-dsl-libui'
397
525
 
398
526
  include Glimmer
399
527
 
400
- window('hello world', 300, 200, 1) { |w|
528
+ window('hello world', 300, 200, true) { |w|
401
529
  button('Button') {
402
530
  on_clicked do
403
531
  msg_box(w, 'Information', 'You clicked the button')
@@ -410,6 +538,23 @@ window('hello world', 300, 200, 1) { |w|
410
538
  }.show
411
539
  ```
412
540
 
541
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
542
+
543
+ ```ruby
544
+ require 'glimmer-dsl-libui'
545
+
546
+ include Glimmer
547
+
548
+ window { # first 3 args can be set via properties with 4th arg has_menubar=true by default
549
+ title 'hello world'
550
+ content_size 300, 200
551
+
552
+ on_closing do
553
+ puts 'Bye Bye'
554
+ end
555
+ }.show
556
+ ```
557
+
413
558
  ### Basic Entry
414
559
 
415
560
  [examples/basic_entry.rb](examples/basic_entry.rb)
@@ -484,10 +629,10 @@ require 'glimmer-dsl-libui'
484
629
 
485
630
  include Glimmer
486
631
 
487
- window('Basic Entry', 300, 50, 1) { |w|
632
+ window('Basic Entry', 300, 50) { |w|
488
633
  horizontal_box {
489
634
  e = entry {
490
- # stretchy 1 # Smart default option for appending to horizontal_box
635
+ # stretchy true # Smart default option for appending to horizontal_box
491
636
 
492
637
  on_changed do
493
638
  puts e.text
@@ -496,7 +641,7 @@ window('Basic Entry', 300, 50, 1) { |w|
496
641
  }
497
642
 
498
643
  button('Button') {
499
- stretchy 0
644
+ stretchy false
500
645
 
501
646
  on_clicked do
502
647
  text = e.text
@@ -570,7 +715,7 @@ require 'glimmer-dsl-libui'
570
715
 
571
716
  include Glimmer
572
717
 
573
- window('Notepad', 500, 300, 1) {
718
+ window('Notepad', 500, 300) {
574
719
  on_closing do
575
720
  puts 'Bye Bye'
576
721
  end
@@ -771,10 +916,10 @@ class TinyMidiPlayer
771
916
  end
772
917
  }
773
918
  }
774
- @main_window = window('Tiny Midi Player', 200, 50, 1) {
919
+ @main_window = window('Tiny Midi Player', 200, 50) {
775
920
  horizontal_box {
776
921
  vertical_box {
777
- stretchy 0
922
+ stretchy false
778
923
 
779
924
  button('▶') {
780
925
  on_clicked do
@@ -1059,7 +1204,7 @@ menu('Edit') {
1059
1204
  check_menu_item('Checkable Item_')
1060
1205
  separator_menu_item
1061
1206
  menu_item('Disabled Item_') {
1062
- enabled 0
1207
+ enabled false
1063
1208
  }
1064
1209
  }
1065
1210
 
@@ -1069,27 +1214,19 @@ menu('Help') {
1069
1214
  about_menu_item # Can optionally contain an on_clicked listener
1070
1215
  }
1071
1216
 
1072
- MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1073
- margined 1
1217
+ MAIN_WINDOW = window('Control Gallery', 600, 500) {
1218
+ margined true
1074
1219
 
1075
1220
  on_closing do
1076
1221
  puts 'Bye Bye'
1077
1222
  end
1078
1223
 
1079
1224
  vertical_box {
1080
- padded 1
1081
-
1082
1225
  horizontal_box {
1083
- padded 1
1084
-
1085
1226
  group('Basic Controls') {
1086
- margined 1
1087
-
1088
1227
  vertical_box {
1089
- padded 1
1090
-
1091
1228
  button('Button') {
1092
- stretchy 0
1229
+ stretchy false
1093
1230
 
1094
1231
  on_clicked do
1095
1232
  msg_box(MAIN_WINDOW, 'Information', 'You clicked the button')
@@ -1097,7 +1234,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1097
1234
  }
1098
1235
 
1099
1236
  checkbox('Checkbox') {
1100
- stretchy 0
1237
+ stretchy false
1101
1238
 
1102
1239
  on_toggled do |c|
1103
1240
  checked = c.checked == 1
@@ -1106,34 +1243,29 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1106
1243
  end
1107
1244
  }
1108
1245
 
1109
- label('Label') { stretchy 0 }
1246
+ label('Label') { stretchy false }
1110
1247
 
1111
- horizontal_separator { stretchy 0 }
1248
+ horizontal_separator { stretchy false }
1112
1249
 
1113
- date_picker { stretchy 0 }
1250
+ date_picker { stretchy false }
1114
1251
 
1115
- time_picker { stretchy 0 }
1252
+ time_picker { stretchy false }
1116
1253
 
1117
- date_time_picker { stretchy 0 }
1254
+ date_time_picker { stretchy false }
1118
1255
 
1119
- font_button { stretchy 0 }
1256
+ font_button { stretchy false }
1120
1257
 
1121
- color_button { stretchy 0 }
1258
+ color_button { stretchy false }
1122
1259
  }
1123
1260
  }
1124
1261
 
1125
1262
  vertical_box {
1126
- padded 1
1127
-
1128
1263
  group('Numbers') {
1129
- stretchy 0
1130
- margined 1
1264
+ stretchy false
1131
1265
 
1132
1266
  vertical_box {
1133
- padded 1
1134
-
1135
1267
  spinbox(0, 100) {
1136
- stretchy 0
1268
+ stretchy false
1137
1269
  value 42
1138
1270
 
1139
1271
  on_changed do |s|
@@ -1142,7 +1274,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1142
1274
  }
1143
1275
 
1144
1276
  slider(0, 100) {
1145
- stretchy 0
1277
+ stretchy false
1146
1278
 
1147
1279
  on_changed do |s|
1148
1280
  v = s.value
@@ -1151,19 +1283,16 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1151
1283
  end
1152
1284
  }
1153
1285
 
1154
- @progress_bar = progress_bar { stretchy 0 }
1286
+ @progress_bar = progress_bar { stretchy false }
1155
1287
  }
1156
1288
  }
1157
1289
 
1158
1290
  group('Lists') {
1159
- stretchy 0
1160
- margined 1
1291
+ stretchy false
1161
1292
 
1162
1293
  vertical_box {
1163
- padded 1
1164
-
1165
1294
  combobox {
1166
- stretchy 0
1295
+ stretchy false
1167
1296
  items 'combobox Item 1', 'combobox Item 2', 'combobox Item 3' # also accepts a single array argument
1168
1297
 
1169
1298
  on_selected do |c|
@@ -1172,7 +1301,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1172
1301
  }
1173
1302
 
1174
1303
  editable_combobox {
1175
- stretchy 0
1304
+ stretchy false
1176
1305
  items 'Editable Item 1', 'Editable Item 2', 'Editable Item 3' # also accepts a single array argument
1177
1306
  }
1178
1307
 
@@ -1211,6 +1340,91 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1211
1340
  MAIN_WINDOW.show
1212
1341
  ```
1213
1342
 
1343
+ ### Font Button
1344
+
1345
+ [examples/font_button.rb](examples/font_button.rb)
1346
+
1347
+ Run with this command from the root of the project if you cloned the project:
1348
+
1349
+ ```
1350
+ ruby -r './lib/glimmer-dsl-libui' examples/font_button.rb
1351
+ ```
1352
+
1353
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1354
+
1355
+ ```
1356
+ ruby -r glimmer-dsl-libui -e "require 'examples/font_button'"
1357
+ ```
1358
+
1359
+ Mac
1360
+
1361
+ ![glimmer-dsl-libui-mac-font-button.png](images/glimmer-dsl-libui-mac-font-button.png)
1362
+ ![glimmer-dsl-libui-mac-font-button-selection.png](images/glimmer-dsl-libui-mac-font-button-selection.png)
1363
+
1364
+ Linux
1365
+
1366
+ ![glimmer-dsl-libui-linux-font-button.png](images/glimmer-dsl-libui-linux-font-button.png)
1367
+ ![glimmer-dsl-libui-linux-font-button-selection.png](images/glimmer-dsl-libui-linux-font-button-selection.png)
1368
+
1369
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
1370
+
1371
+ ```ruby
1372
+ require 'libui'
1373
+
1374
+ UI = LibUI
1375
+
1376
+ UI.init
1377
+
1378
+ main_window = UI.new_window('hello world', 300, 200, 1)
1379
+
1380
+ font_button = UI.new_font_button
1381
+ font_descriptor = UI::FFI::FontDescriptor.malloc
1382
+ UI.font_button_on_changed(font_button) do
1383
+ UI.font_button_font(font_button, font_descriptor)
1384
+ p family: font_descriptor.Family.to_s,
1385
+ size: font_descriptor.Size,
1386
+ weight: font_descriptor.Weight,
1387
+ italic: font_descriptor.Italic,
1388
+ stretch: font_descriptor.Stretch
1389
+ end
1390
+
1391
+ UI.window_on_closing(main_window) do
1392
+ puts 'Bye Bye'
1393
+ UI.control_destroy(main_window)
1394
+ UI.quit
1395
+ 0
1396
+ end
1397
+
1398
+ UI.window_set_child(main_window, font_button)
1399
+ UI.control_show(main_window)
1400
+
1401
+ UI.main
1402
+ UI.quit
1403
+
1404
+ ```
1405
+
1406
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1407
+
1408
+ ```ruby
1409
+ require 'glimmer-dsl-libui'
1410
+
1411
+ include Glimmer
1412
+
1413
+ window('hello world', 300, 200) {
1414
+ font_button { |fb|
1415
+ on_changed do
1416
+ font_descriptor = fb.font
1417
+ p font_descriptor
1418
+ end
1419
+ }
1420
+
1421
+ on_closing do
1422
+ puts 'Bye Bye'
1423
+ end
1424
+ }.show
1425
+
1426
+ ```
1427
+
1214
1428
  ## Contributing to glimmer-dsl-libui
1215
1429
 
1216
1430
  - Check out the latest master to make sure the feature hasn't been
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.10
@@ -4,7 +4,7 @@ require 'glimmer-dsl-libui'
4
4
 
5
5
  include Glimmer
6
6
 
7
- window('hello world', 300, 200, 1) { |w|
7
+ window('hello world', 300, 200) { |w|
8
8
  button('Button') {
9
9
  on_clicked do
10
10
  msg_box(w, 'Information', 'You clicked the button')
@@ -4,10 +4,10 @@ require 'glimmer-dsl-libui'
4
4
 
5
5
  include Glimmer
6
6
 
7
- window('Basic Entry', 300, 50, 1) { |w|
7
+ window('Basic Entry', 300, 50) { |w|
8
8
  horizontal_box {
9
9
  e = entry {
10
- # stretchy 1 # Smart default option for appending to horizontal_box
10
+ # stretchy true # Smart default option for appending to horizontal_box
11
11
 
12
12
  on_changed do
13
13
  puts e.text
@@ -16,7 +16,7 @@ window('Basic Entry', 300, 50, 1) { |w|
16
16
  }
17
17
 
18
18
  button('Button') {
19
- stretchy 0
19
+ stretchy false
20
20
 
21
21
  on_clicked do
22
22
  text = e.text