glimmer-dsl-libui 0.0.7 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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.7
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.11
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,7 +26,7 @@ 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)
@@ -43,7 +43,7 @@ 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.7](#-glimmer-dsl-for-libui-007)
46
+ - [Glimmer DSL for LibUI 0.0.11](#-glimmer-dsl-for-libui-0011)
47
47
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
48
48
  - [Usage](#usage)
49
49
  - [API](#api)
@@ -54,6 +54,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
54
54
  - [Extra Operations](#extra-operations)
55
55
  - [Smart Defaults and Conventions](#smart-defaults-and-conventions)
56
56
  - [Original API](#original-api)
57
+ - [Glimmer Style Guide](#glimmer-style-guide)
57
58
  - [Girb (Glimmer IRB)](#girb-glimmer-irb)
58
59
  - [Examples](#examples)
59
60
  - [Basic Window](#basic-window)
@@ -62,6 +63,8 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
62
63
  - [Simple Notepad](#simple-notepad)
63
64
  - [Midi Player](#midi-player)
64
65
  - [Control Gallery](#control-gallery)
66
+ - [Font Button](#font-button)
67
+ - [Color Button](#color-button)
65
68
  - [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
66
69
  - [Help](#help)
67
70
  - [Issues](#issues)
@@ -76,14 +79,14 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
76
79
 
77
80
  The Glimmer GUI DSL provides object-oriented declarative hierarchical syntax for [LibUI](https://github.com/kojix2/LibUI) that:
78
81
  - Supports smart defaults (e.g. automatic `on_closing` listener that quits `window`)
79
- - Automates wiring of widgets (e.g. `button` is automatically set as child of `window`)
82
+ - Automates wiring of controls (e.g. `button` is automatically set as child of `window`)
80
83
  - Hides lower-level details (e.g. `LibUI.main` loop is started automatically when triggering `show` on `window`)
81
- - Nests widgets according to their visual hierarchy
84
+ - Nests controls according to their visual hierarchy
82
85
  - Requires the minimum amount of syntax needed to describe an app's GUI
83
86
 
84
87
  The Glimmer GUI DSL follows these simple concepts in mapping from [LibUI](https://github.com/kojix2/LibUI) syntax:
85
- - **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)`).
86
- - **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}}`)
88
+ - **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)`).
89
+ - **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}}`)
87
90
  - **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.
88
91
  - **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.
89
92
 
@@ -125,7 +128,7 @@ require 'glimmer-dsl-libui'
125
128
 
126
129
  include Glimmer
127
130
 
128
- window('hello world', 300, 200, 1) { |w|
131
+ window('hello world', 300, 200) { |w|
129
132
  button('Button') {
130
133
  on_clicked do
131
134
  msg_box(w, 'Information', 'You clicked the button')
@@ -149,7 +152,7 @@ gem install glimmer-dsl-libui
149
152
  Or install via Bundler `Gemfile`:
150
153
 
151
154
  ```ruby
152
- gem 'glimmer-dsl-libui', '~> 0.0.7'
155
+ gem 'glimmer-dsl-libui', '~> 0.0.11'
153
156
  ```
154
157
 
155
158
  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.
@@ -163,7 +166,7 @@ class Application
163
166
  include Glimmer
164
167
 
165
168
  def launch
166
- window('hello world', 300, 200, 1) {
169
+ window('hello world', 300, 200) {
167
170
  button('Button') {
168
171
  on_clicked do
169
172
  puts 'Button Clicked'
@@ -206,44 +209,44 @@ Control(Args) | Properties | Listeners
206
209
  ------------- | ---------- | ---------
207
210
  `about_menu_item` | None | `on_clicked`
208
211
  `button(text as String)` | `text` (`String`) | `on_clicked`
209
- `checkbox(text as String)` | `checked` (`1` or `0`), `text` (`String`) | `on_toggled`
210
- `combobox` | `items` (`Array` of `String`), `selected` (`1` or `0`) | `on_selected`
211
- `color_button` | `color` (r `Numeric`, g `Numeric`, b `Numeric`, a `Numeric`), `selected` (`1` or `0`) | `on_selected`
212
- `date_picker` | None | None
212
+ `checkbox(text as String)` | `checked` (Boolean), `text` (`String`) | `on_toggled`
213
+ `combobox` | `items` (`Array` of `String`), `selected` (`Integer`) | `on_selected`
214
+ `color_button` | `color` (Array of `red` as `Float`, `green` as `Float`, `blue` as `Float`, `alpha` as `Float`), `red` as `Float`, `green` as `Float`, `blue` as `Float`, `alpha` as `Float` | `on_changed`
215
+ `date_picker` | `time` (`LibUI::FFI::TM`) | `on_changed`
213
216
  `date_time_picker` | `time` (`LibUI::FFI::TM`) | `on_changed`
214
217
  `editable_combobox` | `items` (`Array` of `String`), `text` (`String`) | `on_changed`
215
- `entry` | `read_only` (`1` or `0`), `text` (`String`) | `on_changed`
216
- `font_button` | `font` (`LibUI::FFI::FontDescriptor`) | `on_changed`
217
- `group(text as String)` | `margined` (`1` or `0`), `title` (`String`) | None
218
- `horizontal_box` | `padded` (`1` or `0`) | None
218
+ `entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
219
+ `font_button` | `font` [read-only] (`Hash` of keys: `:family`, `:size`, `:weight`, `:italic`, `:stretch`), `family` as `String`, `size` as `Float`, `weight` as `Integer`, `italic` as `Integer`, `stretch` as `Integer` | `on_changed`
220
+ `group(text as String)` | `margined` (Boolean), `title` (`String`) | None
221
+ `horizontal_box` | `padded` (Boolean) | None
219
222
  `horizontal_separator` | None | None
220
223
  `label(text as String)` | `text` (`String`) | None
221
224
  `menu(text as String)` | None | None
222
- `menu_item(text as String)` | `checked` (`1` or `0`) | `on_clicked`
223
- `multiline_entry` | `read_only` (`1` or `0`), `text` (`String`) | `on_changed`
225
+ `menu_item(text as String)` | `checked` (Boolean) | `on_clicked`
226
+ `multiline_entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
224
227
  `msg_box(window as Glimmer::LibUI::WindowProxy, title as String, description as String)` | None | None
225
228
  `msg_box_error(window as Glimmer::LibUI::WindowProxy, title as String, description as String)` | None | None
226
- `non_wrapping_multiline_entry` | `read_only` (`1` or `0`), `text` (`String`) | `on_changed`
229
+ `non_wrapping_multiline_entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
227
230
  `preferences_menu_item` | None | `on_clicked`
228
231
  `progress_bar` | `value` (`Numeric`) | None
229
232
  `quit_menu_item` | None | `on_clicked`
230
- `radio_buttons` | `selected` (`1` or `0`) | `on_selected`
233
+ `radio_buttons` | `selected` (`Integer`) | `on_selected`
231
234
  `slider(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
232
235
  `spinbox(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
233
- `tab` | `margined` (`1` or `0`), `num_pages` (`Integer`) | None
234
- `tab_item(name as String)` | `index` [read-only] (`Integer`), `margined` (`1` or `0`), `name` [read-only] (`String`) | None
235
- `time_picker` | None | None
236
- `vertical_box` | `padded` (`1` or `0`) | None
237
- `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`
236
+ `tab` | `margined` (Boolean), `num_pages` (`Integer`) | None
237
+ `tab_item(name as String)` | `index` [read-only] (`Integer`), `margined` (Boolean), `name` [read-only] (`String`) | None
238
+ `time_picker` | `time` (`LibUI::FFI::TM`) | `on_changed`
239
+ `vertical_box` | `padded` (Boolean) | None
240
+ `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`
238
241
 
239
242
  ### Common Control Properties
240
- - `enabled` (`1` or `0`)
243
+ - `enabled` (Boolean)
241
244
  - `libui` (`Fiddle::Pointer`): returns wrapped [LibUI](https://github.com/kojix2/LibUI) object
242
245
  - `parent_proxy` (`Glimmer::LibUI::ControlProxy` or subclass)
243
246
  - `parent` (`Fiddle::Pointer`)
244
- - `toplevel` [read-only] (`1` or `0`)
245
- - `visible` (`1` or `0`)
246
- - `stretchy` [dsl-only] (`1` or `0`): available in [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) when nested under `horizontal_box` or `vertical_box`
247
+ - `toplevel` [read-only] (Boolean)
248
+ - `visible` (Boolean)
249
+ - `stretchy` [dsl-only] (Boolean): available in [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) when nested under `horizontal_box` or `vertical_box`
247
250
 
248
251
  ### Common Control Operations
249
252
  - `destroy`
@@ -265,19 +268,37 @@ Control(Args) | Properties | Listeners
265
268
 
266
269
  ### Smart Defaults and Conventions
267
270
 
268
- - `horizontal_box` and `vertical_box` controls have `padded` as `1` upon instantiation to ensure more user-friendly GUI by default
269
- - `group` controls have `margined` as `1` upon instantiation to ensure more user-friendly GUI by default
270
- - All controls nested under a `horizontal_box` or `vertical_box` have `stretchy` property (passed to `box_append` method) as `1` by default (filling maximum space)
271
+ - `horizontal_box` and `vertical_box` controls have `padded` as `true` upon instantiation to ensure more user-friendly GUI by default
272
+ - `group` controls have `margined` as `true` upon instantiation to ensure more user-friendly GUI by default
273
+ - 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)
274
+ - `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`)
271
275
  - `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)
272
276
  - `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)
273
277
  - 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`).
274
278
  - 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`).
279
+ - 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.
280
+ - All boolean property writers accept `true`/`false` in addition to `1`/`0` in Ruby
281
+ - All string property readers return a `String` object in Ruby instead of the [libui](https://github.com/andlabs/libui) Fiddle pointer object.
282
+ - Automatically allocate font descriptors upon instantiating `font_button` controls and free them when destorying `font_button` controls
283
+ - Automatically allocate color value pointers upon instantiating `color_button` controls and free them when destorying `color_button` controls
284
+ - On the Mac, if no `menu` items were added, an automatic `quit_menu_item` is added to enable quitting with CTRL+Q
285
+ - When destroying a control nested under a `horizontal_box` or `vertical_box`, it is automatically deleted from the box's children
286
+ - When destroying a control nested under a `window` or `group`, it is automatically unset as their child to allow successful destruction
275
287
 
276
288
  ### Original API
277
289
 
278
290
  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),
279
291
  check out the [libui C headers](https://github.com/andlabs/libui/blob/master/ui.h)
280
292
 
293
+ ## Glimmer Style Guide
294
+
295
+ - Control arguments are always wrapped by parentheses
296
+ - Control blocks are always declared with curly braces to clearly visualize hierarchical view code and separate from logic code
297
+ - Control property declarations always have arguments and never take a block
298
+ - Control property arguments are never wrapped inside parentheses
299
+ - 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.
300
+ - 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.
301
+
281
302
  ## Girb (Glimmer IRB)
282
303
 
283
304
  You can run the `girb` command (`bin/girb` if you cloned the project locally):
@@ -292,7 +313,96 @@ Gotcha: On the Mac, when you close a window opened in `girb`, it remains open un
292
313
 
293
314
  ## Examples
294
315
 
295
- These examples reimplement the ones in the [LibUI](https://github.com/kojix2/LibUI) project utilizing the [Glimmer GUI DSL](#glimmer-gui-dsl-concepts).
316
+ 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) as well as brand new examples.
317
+
318
+ 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.
319
+
320
+ [examples/meta_example.rb](examples/meta_example.rb)
321
+
322
+ Run with this command from the root of the project if you cloned the project:
323
+
324
+ ```
325
+ ruby -r './lib/glimmer-dsl-libui' examples/meta_example.rb
326
+ ```
327
+
328
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
329
+
330
+ ```
331
+ ruby -r glimmer-dsl-libui -e "require 'examples/meta_example'"
332
+ ```
333
+
334
+ Mac
335
+
336
+ ![glimmer-dsl-libui-mac-meta-example.png](images/glimmer-dsl-libui-mac-meta-example.png)
337
+
338
+ Linux
339
+
340
+ ![glimmer-dsl-libui-linux-meta-example.png](images/glimmer-dsl-libui-linux-meta-example.png)
341
+
342
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
343
+
344
+ ```ruby
345
+ require 'glimmer-dsl-libui'
346
+ require 'facets'
347
+
348
+ class MetaExample
349
+ include Glimmer
350
+
351
+ def examples
352
+ if @examples.nil?
353
+ example_files = Dir.glob(File.join(File.expand_path('.', __dir__), '**', '*.rb'))
354
+ example_file_names = example_files.map { |f| File.basename(f, '.rb') }
355
+ example_file_names = example_file_names.reject { |f| f == 'meta_example' }
356
+ @examples = example_file_names.map { |f| f.underscore.titlecase }
357
+ end
358
+ @examples
359
+ end
360
+
361
+ def file_path_for(example)
362
+ File.join(File.expand_path('.', __dir__), "#{example.underscore}.rb")
363
+ end
364
+
365
+ def launch
366
+ menu('File') {
367
+ quit_menu_item
368
+ }
369
+
370
+ window('Meta-Example', 700, 500) { |w|
371
+ margined true
372
+
373
+ horizontal_box {
374
+ vertical_box {
375
+ @rbs = radio_buttons {
376
+ stretchy false
377
+ items examples
378
+ selected 0
379
+
380
+ on_selected do
381
+ @nwme.text = File.read(file_path_for(@examples[@rbs.selected]))
382
+ end
383
+ }
384
+ button('Launch') {
385
+ stretchy false
386
+
387
+ on_clicked do
388
+ system "ruby -r puts_debuggerer -r #{File.expand_path('../lib/glimmer-dsl-libui', __dir__)} #{file_path_for(@examples[@rbs.selected])}"
389
+ end
390
+ }
391
+ }
392
+ vertical_box {
393
+ @nwme = non_wrapping_multiline_entry {
394
+ read_only true
395
+ text File.read(file_path_for(@examples[@rbs.selected]))
396
+ }
397
+ }
398
+ }
399
+ }.show
400
+ end
401
+ end
402
+
403
+ MetaExample.new.launch
404
+ ```
405
+
296
406
 
297
407
  ### Basic Window
298
408
 
@@ -349,7 +459,7 @@ require 'glimmer-dsl-libui'
349
459
 
350
460
  include Glimmer
351
461
 
352
- window('hello world', 300, 200, 1) {
462
+ window('hello world', 300, 200, true) {
353
463
  on_closing do
354
464
  puts 'Bye Bye'
355
465
  end
@@ -375,7 +485,7 @@ ruby -r glimmer-dsl-libui -e "require 'examples/basic_button'"
375
485
  Mac
376
486
 
377
487
  ![glimmer-dsl-libui-mac-basic-button.png](images/glimmer-dsl-libui-mac-basic-button.png)
378
- ![glimmer-dsl-libui-mac-basic-button-msg-box.png](images/glimmer-dsl-libui-basic-button-msg-box.png)
488
+ ![glimmer-dsl-libui-mac-basic-button-msg-box.png](images/glimmer-dsl-libui-mac-basic-button-msg-box.png)
379
489
 
380
490
  Linux
381
491
 
@@ -420,7 +530,7 @@ require 'glimmer-dsl-libui'
420
530
 
421
531
  include Glimmer
422
532
 
423
- window('hello world', 300, 200, 1) { |w|
533
+ window('hello world', 300, 200, true) { |w|
424
534
  button('Button') {
425
535
  on_clicked do
426
536
  msg_box(w, 'Information', 'You clicked the button')
@@ -433,6 +543,23 @@ window('hello world', 300, 200, 1) { |w|
433
543
  }.show
434
544
  ```
435
545
 
546
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
547
+
548
+ ```ruby
549
+ require 'glimmer-dsl-libui'
550
+
551
+ include Glimmer
552
+
553
+ window { # first 3 args can be set via properties with 4th arg has_menubar=true by default
554
+ title 'hello world'
555
+ content_size 300, 200
556
+
557
+ on_closing do
558
+ puts 'Bye Bye'
559
+ end
560
+ }.show
561
+ ```
562
+
436
563
  ### Basic Entry
437
564
 
438
565
  [examples/basic_entry.rb](examples/basic_entry.rb)
@@ -507,10 +634,10 @@ require 'glimmer-dsl-libui'
507
634
 
508
635
  include Glimmer
509
636
 
510
- window('Basic Entry', 300, 50, 1) { |w|
637
+ window('Basic Entry', 300, 50) { |w|
511
638
  horizontal_box {
512
639
  e = entry {
513
- # stretchy 1 # Smart default option for appending to horizontal_box
640
+ # stretchy true # Smart default option for appending to horizontal_box
514
641
 
515
642
  on_changed do
516
643
  puts e.text
@@ -519,7 +646,7 @@ window('Basic Entry', 300, 50, 1) { |w|
519
646
  }
520
647
 
521
648
  button('Button') {
522
- stretchy 0
649
+ stretchy false
523
650
 
524
651
  on_clicked do
525
652
  text = e.text
@@ -593,7 +720,7 @@ require 'glimmer-dsl-libui'
593
720
 
594
721
  include Glimmer
595
722
 
596
- window('Notepad', 500, 300, 1) {
723
+ window('Notepad', 500, 300) {
597
724
  on_closing do
598
725
  puts 'Bye Bye'
599
726
  end
@@ -794,10 +921,10 @@ class TinyMidiPlayer
794
921
  end
795
922
  }
796
923
  }
797
- @main_window = window('Tiny Midi Player', 200, 50, 1) {
924
+ @main_window = window('Tiny Midi Player', 200, 50) {
798
925
  horizontal_box {
799
926
  vertical_box {
800
- stretchy 0
927
+ stretchy false
801
928
 
802
929
  button('▶') {
803
930
  on_clicked do
@@ -1082,7 +1209,7 @@ menu('Edit') {
1082
1209
  check_menu_item('Checkable Item_')
1083
1210
  separator_menu_item
1084
1211
  menu_item('Disabled Item_') {
1085
- enabled 0
1212
+ enabled false
1086
1213
  }
1087
1214
  }
1088
1215
 
@@ -1092,8 +1219,8 @@ menu('Help') {
1092
1219
  about_menu_item # Can optionally contain an on_clicked listener
1093
1220
  }
1094
1221
 
1095
- MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1096
- margined 1
1222
+ MAIN_WINDOW = window('Control Gallery', 600, 500) {
1223
+ margined true
1097
1224
 
1098
1225
  on_closing do
1099
1226
  puts 'Bye Bye'
@@ -1104,7 +1231,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1104
1231
  group('Basic Controls') {
1105
1232
  vertical_box {
1106
1233
  button('Button') {
1107
- stretchy 0
1234
+ stretchy false
1108
1235
 
1109
1236
  on_clicked do
1110
1237
  msg_box(MAIN_WINDOW, 'Information', 'You clicked the button')
@@ -1112,7 +1239,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1112
1239
  }
1113
1240
 
1114
1241
  checkbox('Checkbox') {
1115
- stretchy 0
1242
+ stretchy false
1116
1243
 
1117
1244
  on_toggled do |c|
1118
1245
  checked = c.checked == 1
@@ -1121,29 +1248,29 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1121
1248
  end
1122
1249
  }
1123
1250
 
1124
- label('Label') { stretchy 0 }
1251
+ label('Label') { stretchy false }
1125
1252
 
1126
- horizontal_separator { stretchy 0 }
1253
+ horizontal_separator { stretchy false }
1127
1254
 
1128
- date_picker { stretchy 0 }
1255
+ date_picker { stretchy false }
1129
1256
 
1130
- time_picker { stretchy 0 }
1257
+ time_picker { stretchy false }
1131
1258
 
1132
- date_time_picker { stretchy 0 }
1259
+ date_time_picker { stretchy false }
1133
1260
 
1134
- font_button { stretchy 0 }
1261
+ font_button { stretchy false }
1135
1262
 
1136
- color_button { stretchy 0 }
1263
+ color_button { stretchy false }
1137
1264
  }
1138
1265
  }
1139
1266
 
1140
1267
  vertical_box {
1141
1268
  group('Numbers') {
1142
- stretchy 0
1269
+ stretchy false
1143
1270
 
1144
1271
  vertical_box {
1145
1272
  spinbox(0, 100) {
1146
- stretchy 0
1273
+ stretchy false
1147
1274
  value 42
1148
1275
 
1149
1276
  on_changed do |s|
@@ -1152,7 +1279,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1152
1279
  }
1153
1280
 
1154
1281
  slider(0, 100) {
1155
- stretchy 0
1282
+ stretchy false
1156
1283
 
1157
1284
  on_changed do |s|
1158
1285
  v = s.value
@@ -1161,16 +1288,16 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1161
1288
  end
1162
1289
  }
1163
1290
 
1164
- @progress_bar = progress_bar { stretchy 0 }
1291
+ @progress_bar = progress_bar { stretchy false }
1165
1292
  }
1166
1293
  }
1167
1294
 
1168
1295
  group('Lists') {
1169
- stretchy 0
1296
+ stretchy false
1170
1297
 
1171
1298
  vertical_box {
1172
1299
  combobox {
1173
- stretchy 0
1300
+ stretchy false
1174
1301
  items 'combobox Item 1', 'combobox Item 2', 'combobox Item 3' # also accepts a single array argument
1175
1302
 
1176
1303
  on_selected do |c|
@@ -1179,7 +1306,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1179
1306
  }
1180
1307
 
1181
1308
  editable_combobox {
1182
- stretchy 0
1309
+ stretchy false
1183
1310
  items 'Editable Item 1', 'Editable Item 2', 'Editable Item 3' # also accepts a single array argument
1184
1311
  }
1185
1312
 
@@ -1218,6 +1345,135 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
1218
1345
  MAIN_WINDOW.show
1219
1346
  ```
1220
1347
 
1348
+ ### Font Button
1349
+
1350
+ [examples/font_button.rb](examples/font_button.rb)
1351
+
1352
+ Run with this command from the root of the project if you cloned the project:
1353
+
1354
+ ```
1355
+ ruby -r './lib/glimmer-dsl-libui' examples/font_button.rb
1356
+ ```
1357
+
1358
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1359
+
1360
+ ```
1361
+ ruby -r glimmer-dsl-libui -e "require 'examples/font_button'"
1362
+ ```
1363
+
1364
+ Mac
1365
+
1366
+ ![glimmer-dsl-libui-mac-font-button.png](images/glimmer-dsl-libui-mac-font-button.png)
1367
+ ![glimmer-dsl-libui-mac-font-button-selection.png](images/glimmer-dsl-libui-mac-font-button-selection.png)
1368
+
1369
+ Linux
1370
+
1371
+ ![glimmer-dsl-libui-linux-font-button.png](images/glimmer-dsl-libui-linux-font-button.png)
1372
+ ![glimmer-dsl-libui-linux-font-button-selection.png](images/glimmer-dsl-libui-linux-font-button-selection.png)
1373
+
1374
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
1375
+
1376
+ ```ruby
1377
+ require 'libui'
1378
+
1379
+ UI = LibUI
1380
+
1381
+ UI.init
1382
+
1383
+ main_window = UI.new_window('hello world', 300, 200, 1)
1384
+
1385
+ font_button = UI.new_font_button
1386
+ font_descriptor = UI::FFI::FontDescriptor.malloc
1387
+ UI.font_button_on_changed(font_button) do
1388
+ UI.font_button_font(font_button, font_descriptor)
1389
+ p family: font_descriptor.Family.to_s,
1390
+ size: font_descriptor.Size,
1391
+ weight: font_descriptor.Weight,
1392
+ italic: font_descriptor.Italic,
1393
+ stretch: font_descriptor.Stretch
1394
+ end
1395
+
1396
+ UI.window_on_closing(main_window) do
1397
+ puts 'Bye Bye'
1398
+ UI.control_destroy(main_window)
1399
+ UI.quit
1400
+ 0
1401
+ end
1402
+
1403
+ UI.window_set_child(main_window, font_button)
1404
+ UI.control_show(main_window)
1405
+
1406
+ UI.main
1407
+ UI.quit
1408
+
1409
+ ```
1410
+
1411
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1412
+
1413
+ ```ruby
1414
+ require 'glimmer-dsl-libui'
1415
+
1416
+ include Glimmer
1417
+
1418
+ window('hello world', 300, 200) {
1419
+ font_button { |fb|
1420
+ on_changed do
1421
+ font_descriptor = fb.font
1422
+ p font_descriptor
1423
+ end
1424
+ }
1425
+
1426
+ on_closing do
1427
+ puts 'Bye Bye'
1428
+ end
1429
+ }.show
1430
+ ```
1431
+
1432
+ ### Color Button
1433
+
1434
+ [examples/color_button.rb](examples/color_button.rb)
1435
+
1436
+ Run with this command from the root of the project if you cloned the project:
1437
+
1438
+ ```
1439
+ ruby -r './lib/glimmer-dsl-libui' examples/color_button.rb
1440
+ ```
1441
+
1442
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1443
+
1444
+ ```
1445
+ ruby -r glimmer-dsl-libui -e "require 'examples/color_button'"
1446
+ ```
1447
+
1448
+ Mac
1449
+
1450
+ ![glimmer-dsl-libui-mac-color-button.png](images/glimmer-dsl-libui-mac-color-button.png)
1451
+ ![glimmer-dsl-libui-mac-color-button-selection.png](images/glimmer-dsl-libui-mac-color-button-selection.png)
1452
+
1453
+ Linux
1454
+
1455
+ ![glimmer-dsl-libui-linux-color-button.png](images/glimmer-dsl-libui-linux-color-button.png)
1456
+ ![glimmer-dsl-libui-linux-color-button-selection.png](images/glimmer-dsl-libui-linux-color-button-selection.png)
1457
+
1458
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1459
+
1460
+ ```ruby
1461
+ # frozen_string_literal: true
1462
+
1463
+ require 'glimmer-dsl-libui'
1464
+
1465
+ include Glimmer
1466
+
1467
+ window('color button', 230) {
1468
+ color_button { |cb|
1469
+ on_changed do
1470
+ rgba = cb.color
1471
+ p rgba
1472
+ end
1473
+ }
1474
+ }.show
1475
+ ```
1476
+
1221
1477
  ## Contributing to glimmer-dsl-libui
1222
1478
 
1223
1479
  - Check out the latest master to make sure the feature hasn't been
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.11
@@ -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')