glimmer-dsl-libui 0.0.9 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4aa989bad8bba6c9e59285e38a699b7842eb7f089a976782ac75363debfd829e
4
- data.tar.gz: '081812a749e0ab795dfafcac60b58ab639f50933580f5ed3e404354691dd3d94'
3
+ metadata.gz: 19ebb3b2df3f14388664e392c4fbac8b121c6adf5638e78ddf308c7455c76c02
4
+ data.tar.gz: a631ed4518643c2d05ff39568f3fad815aa8729b01e1ee45ace9162bc9cf93be
5
5
  SHA512:
6
- metadata.gz: 2e189f2db6399f9f718a06ca68b82665c7d9b54031dc62a76af1a4bb056f1299f40fe9993940163594157bdfcd649635cc27967aaadb7b709286d0b630d9b584
7
- data.tar.gz: 5289461f384cf3237add39dba3fba83448c117d63ca53ac8e5dcc0af33cb4683179e077a712e927615825fc226bf94b234b4088e45b3f8de6c7b97a0d480c3a4
6
+ metadata.gz: 9e0fccb89ce28c472c65cabc9ff1a6044cb19c3277e960e726ea7f642ccc2861f12b6c4ec1d31a562f7d05ce64a92dcb5696a544b9dd4a2ebad25e2cd82dd61b
7
+ data.tar.gz: 4429a478c94b4105c079ddcda93b247271bae083a5b6c3b91e9c76c895a3273b27fced8d37262555b5139a0a19c98e63224eee3eb9ac44d89d379db151fa72ae
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.13
4
+
5
+ - Support examples/date_time_picker.rb
6
+ - Support `date_time_picker`, `date_picker`, and `time_picker` controls having `time`/`time=`/`set_time` property
7
+
8
+ ## 0.0.12
9
+
10
+ - Have examples/meta_example.rb allow code editing to enable experimentation and learning
11
+ - Fix issue with examples/meta_example using puts_debuggerer (a development gem)
12
+
13
+ ## 0.0.11
14
+
15
+ - New examples/basic_color.rb
16
+ - Support `color_button` `color` property
17
+ - Proper destroy of controls (deleting from parent `box`, `window`, or `group` first)
18
+ - On the Mac only, if no menu is specified, add a Quit menu item automatically to allow quitting with CMD+Q
19
+
20
+ ## 0.0.10
21
+
22
+ - Support examples/font_button.rb
23
+ - Support `font_button` control
24
+ - Add File -> Quit menu item to examples/meta_example.rb
25
+ - Glimmer Style Guide added to README.md
26
+
3
27
  ## 0.0.9
4
28
 
5
29
  - Build a meta-example (example of examples)
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.9
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.13
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,17 +6,17 @@
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
18
+ - Custom Control support
19
+ - Scaffolding for new custom controls, apps, and gems
20
20
  - Native-Executable packaging on Mac, Windows, and Linux.
21
21
 
22
22
  Example:
@@ -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.9](#-glimmer-dsl-for-libui-009)
46
+ - [Glimmer DSL for LibUI 0.0.13](#-glimmer-dsl-for-libui-0013)
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,9 @@ 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)
68
+ - [Date Time Picker](#date-time-picker)
65
69
  - [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
66
70
  - [Help](#help)
67
71
  - [Issues](#issues)
@@ -76,9 +80,9 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
76
80
 
77
81
  The Glimmer GUI DSL provides object-oriented declarative hierarchical syntax for [LibUI](https://github.com/kojix2/LibUI) that:
78
82
  - 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`)
83
+ - Automates wiring of controls (e.g. `button` is automatically set as child of `window`)
80
84
  - 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
85
+ - Nests controls according to their visual hierarchy
82
86
  - Requires the minimum amount of syntax needed to describe an app's GUI
83
87
 
84
88
  The Glimmer GUI DSL follows these simple concepts in mapping from [LibUI](https://github.com/kojix2/LibUI) syntax:
@@ -149,7 +153,7 @@ gem install glimmer-dsl-libui
149
153
  Or install via Bundler `Gemfile`:
150
154
 
151
155
  ```ruby
152
- gem 'glimmer-dsl-libui', '~> 0.0.9'
156
+ gem 'glimmer-dsl-libui', '~> 0.0.13'
153
157
  ```
154
158
 
155
159
  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.
@@ -183,7 +187,7 @@ Any control returned by a [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) keyword d
183
187
  Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
184
188
 
185
189
  ```ruby
186
- w = window('hello world', 300, 200, 1)
190
+ w = window('hello world')
187
191
  puts w.title # => hello world
188
192
  w.title = 'howdy'
189
193
  puts w.title # => howdy
@@ -196,7 +200,7 @@ Controls are wrapped as Ruby proxy objects, having a `#libui` method to obtain t
196
200
  Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
197
201
 
198
202
  ```ruby
199
- w = window('hello world', 300, 200, 1) # => #<Glimmer::LibUI::WindowProxy:0x00007fde4ea39fb0
203
+ w = window('hello world') # => #<Glimmer::LibUI::WindowProxy:0x00007fde4ea39fb0
200
204
  w.libui # => #<Fiddle::Pointer:0x00007fde53997980 ptr=0x00007fde51352a60 size=0 free=0x0000000000000000>
201
205
  ```
202
206
 
@@ -208,12 +212,12 @@ Control(Args) | Properties | Listeners
208
212
  `button(text as String)` | `text` (`String`) | `on_clicked`
209
213
  `checkbox(text as String)` | `checked` (Boolean), `text` (`String`) | `on_toggled`
210
214
  `combobox` | `items` (`Array` of `String`), `selected` (`Integer`) | `on_selected`
211
- `color_button` | `color` (r `Numeric`, g `Numeric`, b `Numeric`, a `Numeric`) | `on_changed`
212
- `date_picker` | `time` (`LibUI::FFI::TM`) | `on_changed`
213
- `date_time_picker` | `time` (`LibUI::FFI::TM`) | `on_changed`
215
+ `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`
216
+ `date_picker` | `time` (`Hash` of keys: `sec` as `Integer`, `min` as `Integer`, `hour` as `Integer`, `mday` as `Integer`, `mon` as `Integer`, `year` as `Integer`, `wday` as `Integer`, `yday` as `Integer`, `dst` as Boolean) | `on_changed`
217
+ `date_time_picker` | `time` (`Hash` of keys: `sec` as `Integer`, `min` as `Integer`, `hour` as `Integer`, `mday` as `Integer`, `mon` as `Integer`, `year` as `Integer`, `wday` as `Integer`, `yday` as `Integer`, `dst` as Boolean) | `on_changed`
214
218
  `editable_combobox` | `items` (`Array` of `String`), `text` (`String`) | `on_changed`
215
219
  `entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
216
- `font_button` | `font` (`LibUI::FFI::FontDescriptor`) | `on_changed`
220
+ `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`
217
221
  `group(text as String)` | `margined` (Boolean), `title` (`String`) | None
218
222
  `horizontal_box` | `padded` (Boolean) | None
219
223
  `horizontal_separator` | None | None
@@ -232,7 +236,7 @@ Control(Args) | Properties | Listeners
232
236
  `spinbox(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
233
237
  `tab` | `margined` (Boolean), `num_pages` (`Integer`) | None
234
238
  `tab_item(name as String)` | `index` [read-only] (`Integer`), `margined` (Boolean), `name` [read-only] (`String`) | None
235
- `time_picker` | `time` (`LibUI::FFI::TM`) | `on_changed`
239
+ `time_picker` | `time` (`Hash` of keys: `sec` as `Integer`, `min` as `Integer`, `hour` as `Integer`, `mday` as `Integer`, `mon` as `Integer`, `year` as `Integer`, `wday` as `Integer`, `yday` as `Integer`, `dst` as Boolean) | `on_changed`
236
240
  `vertical_box` | `padded` (Boolean) | None
237
241
  `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
242
 
@@ -276,12 +280,27 @@ Control(Args) | Properties | Listeners
276
280
  - 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.
277
281
  - All boolean property writers accept `true`/`false` in addition to `1`/`0` in Ruby
278
282
  - All string property readers return a `String` object in Ruby instead of the [libui](https://github.com/andlabs/libui) Fiddle pointer object.
283
+ - Automatically allocate font descriptors upon instantiating `font_button` controls and free them when destorying `font_button` controls
284
+ - Automatically allocate color value pointers upon instantiating `color_button` controls and free them when destorying `color_button` controls
285
+ - On the Mac, if no `menu` items were added, an automatic `quit_menu_item` is added to enable quitting with CTRL+Q
286
+ - When destroying a control nested under a `horizontal_box` or `vertical_box`, it is automatically deleted from the box's children
287
+ - When destroying a control nested under a `window` or `group`, it is automatically unset as their child to allow successful destruction
288
+ - For `date_time_picker`, `date_picker`, and `time_picker`, make sure `time` hash values for `mon`, `wday`, and `yday` are 1-based instead of [libui](https://github.com/andlabs/libui) original 0-based values, and return `dst` as Boolean instead of `isdst` as `1`/`0`
279
289
 
280
290
  ### Original API
281
291
 
282
292
  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),
283
293
  check out the [libui C headers](https://github.com/andlabs/libui/blob/master/ui.h)
284
294
 
295
+ ## Glimmer Style Guide
296
+
297
+ - Control arguments are always wrapped by parentheses
298
+ - Control blocks are always declared with curly braces to clearly visualize hierarchical view code and separate from logic code
299
+ - Control property declarations always have arguments and never take a block
300
+ - Control property arguments are never wrapped inside parentheses
301
+ - 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.
302
+ - 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.
303
+
285
304
  ## Girb (Glimmer IRB)
286
305
 
287
306
  You can run the `girb` command (`bin/girb` if you cloned the project locally):
@@ -296,9 +315,9 @@ Gotcha: On the Mac, when you close a window opened in `girb`, it remains open un
296
315
 
297
316
  ## Examples
298
317
 
299
- 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).
318
+ 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.
300
319
 
301
- 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.
320
+ 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. It also enables code editing to facilitate experimentation and learning.
302
321
 
303
322
  [examples/meta_example.rb](examples/meta_example.rb)
304
323
 
@@ -322,7 +341,7 @@ Linux
322
341
 
323
342
  ![glimmer-dsl-libui-linux-meta-example.png](images/glimmer-dsl-libui-linux-meta-example.png)
324
343
 
325
- [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
344
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
326
345
 
327
346
  ```ruby
328
347
  require 'glimmer-dsl-libui'
@@ -345,6 +364,10 @@ class MetaExample
345
364
  File.join(File.expand_path('.', __dir__), "#{example.underscore}.rb")
346
365
  end
347
366
 
367
+ def glimmer_dsl_libui_file
368
+ File.expand_path('../lib/glimmer-dsl-libui', __dir__)
369
+ end
370
+
348
371
  def launch
349
372
  window('Meta-Example', 700, 500) { |w|
350
373
  margined true
@@ -364,13 +387,20 @@ class MetaExample
364
387
  stretchy false
365
388
 
366
389
  on_clicked do
367
- system "ruby -r puts_debuggerer -r #{File.expand_path('../lib/glimmer-dsl-libui', __dir__)} #{file_path_for(@examples[@rbs.selected])}"
390
+ begin
391
+ meta_example_file = File.join(Dir.home, '.meta_example.rb')
392
+ File.write(meta_example_file, @nwme.text)
393
+ result = `ruby -r #{glimmer_dsl_libui_file} #{meta_example_file} 2>&1`
394
+ msg_box(w, 'Error Running Example', result) if result.include?('error')
395
+ rescue => e
396
+ puts 'Unable to write code changes! Running original example...'
397
+ system "ruby -r #{glimmer_dsl_libui_file} #{file_path_for(@examples[@rbs.selected])}"
398
+ end
368
399
  end
369
400
  }
370
401
  }
371
402
  vertical_box {
372
403
  @nwme = non_wrapping_multiline_entry {
373
- read_only true
374
404
  text File.read(file_path_for(@examples[@rbs.selected]))
375
405
  }
376
406
  }
@@ -464,7 +494,7 @@ ruby -r glimmer-dsl-libui -e "require 'examples/basic_button'"
464
494
  Mac
465
495
 
466
496
  ![glimmer-dsl-libui-mac-basic-button.png](images/glimmer-dsl-libui-mac-basic-button.png)
467
- ![glimmer-dsl-libui-mac-basic-button-msg-box.png](images/glimmer-dsl-libui-basic-button-msg-box.png)
497
+ ![glimmer-dsl-libui-mac-basic-button-msg-box.png](images/glimmer-dsl-libui-mac-basic-button-msg-box.png)
468
498
 
469
499
  Linux
470
500
 
@@ -1324,6 +1354,223 @@ MAIN_WINDOW = window('Control Gallery', 600, 500) {
1324
1354
  MAIN_WINDOW.show
1325
1355
  ```
1326
1356
 
1357
+ ### Font Button
1358
+
1359
+ [examples/font_button.rb](examples/font_button.rb)
1360
+
1361
+ Run with this command from the root of the project if you cloned the project:
1362
+
1363
+ ```
1364
+ ruby -r './lib/glimmer-dsl-libui' examples/font_button.rb
1365
+ ```
1366
+
1367
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1368
+
1369
+ ```
1370
+ ruby -r glimmer-dsl-libui -e "require 'examples/font_button'"
1371
+ ```
1372
+
1373
+ Mac
1374
+
1375
+ ![glimmer-dsl-libui-mac-font-button.png](images/glimmer-dsl-libui-mac-font-button.png)
1376
+ ![glimmer-dsl-libui-mac-font-button-selection.png](images/glimmer-dsl-libui-mac-font-button-selection.png)
1377
+
1378
+ Linux
1379
+
1380
+ ![glimmer-dsl-libui-linux-font-button.png](images/glimmer-dsl-libui-linux-font-button.png)
1381
+ ![glimmer-dsl-libui-linux-font-button-selection.png](images/glimmer-dsl-libui-linux-font-button-selection.png)
1382
+
1383
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
1384
+
1385
+ ```ruby
1386
+ require 'libui'
1387
+
1388
+ UI = LibUI
1389
+
1390
+ UI.init
1391
+
1392
+ main_window = UI.new_window('hello world', 300, 200, 1)
1393
+
1394
+ font_button = UI.new_font_button
1395
+ font_descriptor = UI::FFI::FontDescriptor.malloc
1396
+ UI.font_button_on_changed(font_button) do
1397
+ UI.font_button_font(font_button, font_descriptor)
1398
+ p family: font_descriptor.Family.to_s,
1399
+ size: font_descriptor.Size,
1400
+ weight: font_descriptor.Weight,
1401
+ italic: font_descriptor.Italic,
1402
+ stretch: font_descriptor.Stretch
1403
+ end
1404
+
1405
+ UI.window_on_closing(main_window) do
1406
+ puts 'Bye Bye'
1407
+ UI.control_destroy(main_window)
1408
+ UI.quit
1409
+ 0
1410
+ end
1411
+
1412
+ UI.window_set_child(main_window, font_button)
1413
+ UI.control_show(main_window)
1414
+
1415
+ UI.main
1416
+ UI.quit
1417
+
1418
+ ```
1419
+
1420
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1421
+
1422
+ ```ruby
1423
+ require 'glimmer-dsl-libui'
1424
+
1425
+ include Glimmer
1426
+
1427
+ window('hello world', 300, 200) {
1428
+ font_button { |fb|
1429
+ on_changed do
1430
+ font_descriptor = fb.font
1431
+ p font_descriptor
1432
+ end
1433
+ }
1434
+
1435
+ on_closing do
1436
+ puts 'Bye Bye'
1437
+ end
1438
+ }.show
1439
+ ```
1440
+
1441
+ ### Color Button
1442
+
1443
+ [examples/color_button.rb](examples/color_button.rb)
1444
+
1445
+ Run with this command from the root of the project if you cloned the project:
1446
+
1447
+ ```
1448
+ ruby -r './lib/glimmer-dsl-libui' examples/color_button.rb
1449
+ ```
1450
+
1451
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1452
+
1453
+ ```
1454
+ ruby -r glimmer-dsl-libui -e "require 'examples/color_button'"
1455
+ ```
1456
+
1457
+ Mac
1458
+
1459
+ ![glimmer-dsl-libui-mac-color-button.png](images/glimmer-dsl-libui-mac-color-button.png)
1460
+ ![glimmer-dsl-libui-mac-color-button-selection.png](images/glimmer-dsl-libui-mac-color-button-selection.png)
1461
+
1462
+ Linux
1463
+
1464
+ ![glimmer-dsl-libui-linux-color-button.png](images/glimmer-dsl-libui-linux-color-button.png)
1465
+ ![glimmer-dsl-libui-linux-color-button-selection.png](images/glimmer-dsl-libui-linux-color-button-selection.png)
1466
+
1467
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1468
+
1469
+ ```ruby
1470
+ require 'glimmer-dsl-libui'
1471
+
1472
+ include Glimmer
1473
+
1474
+ window('color button', 230) {
1475
+ color_button { |cb|
1476
+ on_changed do
1477
+ rgba = cb.color
1478
+ p rgba
1479
+ end
1480
+ }
1481
+ }.show
1482
+ ```
1483
+
1484
+ ### Date Time Picker
1485
+
1486
+ [examples/date_time_picker.rb](examples/date_time_picker.rb)
1487
+
1488
+ Run with this command from the root of the project if you cloned the project:
1489
+
1490
+ ```
1491
+ ruby -r './lib/glimmer-dsl-libui' examples/date_time_picker.rb
1492
+ ```
1493
+
1494
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1495
+
1496
+ ```
1497
+ ruby -r glimmer-dsl-libui -e "require 'examples/date_time_picker'"
1498
+ ```
1499
+
1500
+ Mac
1501
+
1502
+ ![glimmer-dsl-libui-mac-date-time-picker.png](images/glimmer-dsl-libui-mac-date-time-picker.png)
1503
+
1504
+ Linux
1505
+
1506
+ ![glimmer-dsl-libui-linux-date-time-picker.png](images/glimmer-dsl-libui-linux-date-time-picker.png)
1507
+
1508
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
1509
+
1510
+ ```ruby
1511
+ require 'libui'
1512
+
1513
+ UI = LibUI
1514
+
1515
+ UI.init
1516
+
1517
+ vbox = UI.new_vertical_box
1518
+
1519
+ date_time_picker = UI.new_date_time_picker
1520
+
1521
+ time = UI::FFI::TM.malloc
1522
+
1523
+ UI.date_time_picker_on_changed(date_time_picker) do
1524
+ UI.date_time_picker_time(date_time_picker, time)
1525
+ p sec: time.tm_sec,
1526
+ min: time.tm_min,
1527
+ hour: time.tm_hour,
1528
+ mday: time.tm_mday,
1529
+ mon: time.tm_mon,
1530
+ year: time.tm_year,
1531
+ wday: time.tm_wday,
1532
+ yday: time.tm_yday,
1533
+ isdst: time.tm_isdst
1534
+ end
1535
+ UI.box_append(vbox, date_time_picker, 1)
1536
+
1537
+ main_window = UI.new_window('Date Time Pickers', 300, 200, 1)
1538
+ UI.window_on_closing(main_window) do
1539
+ puts 'Bye Bye'
1540
+ UI.control_destroy(main_window)
1541
+ UI.quit
1542
+ 0
1543
+ end
1544
+ UI.window_set_child(main_window, vbox)
1545
+ UI.control_show(main_window)
1546
+
1547
+ UI.main
1548
+ UI.quit
1549
+ ```
1550
+
1551
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1552
+
1553
+ ```ruby
1554
+ require 'glimmer-dsl-libui'
1555
+
1556
+ include Glimmer
1557
+
1558
+ window('Date Time Pickers', 300, 200) {
1559
+ vertical_box {
1560
+ date_time_picker { |dtp|
1561
+ on_changed do
1562
+ time = dtp.time
1563
+ p time
1564
+ end
1565
+ }
1566
+ }
1567
+
1568
+ on_closing do
1569
+ puts 'Bye Bye'
1570
+ end
1571
+ }.show
1572
+ ```
1573
+
1327
1574
  ## Contributing to glimmer-dsl-libui
1328
1575
 
1329
1576
  - Check out the latest master to make sure the feature hasn't been
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.0.13
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'glimmer-dsl-libui'
4
+
5
+ include Glimmer
6
+
7
+ window('color button', 230) {
8
+ color_button { |cb|
9
+ on_changed do
10
+ rgba = cb.color
11
+ p rgba
12
+ end
13
+ }
14
+ }.show
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'glimmer-dsl-libui'
4
+
5
+ include Glimmer
6
+
7
+ window('Date Time Pickers', 300, 200) {
8
+ vertical_box {
9
+ date_time_picker { |dtp|
10
+ on_changed do
11
+ time = dtp.time
12
+ p time
13
+ end
14
+ }
15
+ }
16
+
17
+ on_closing do
18
+ puts 'Bye Bye'
19
+ end
20
+ }.show
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'glimmer-dsl-libui'
4
+
5
+ include Glimmer
6
+
7
+ window('hello world', 300, 200) {
8
+ font_button { |fb|
9
+ on_changed do
10
+ font_descriptor = fb.font
11
+ p font_descriptor
12
+ end
13
+ }
14
+
15
+ on_closing do
16
+ puts 'Bye Bye'
17
+ end
18
+ }.show
@@ -20,6 +20,10 @@ class MetaExample
20
20
  File.join(File.expand_path('.', __dir__), "#{example.underscore}.rb")
21
21
  end
22
22
 
23
+ def glimmer_dsl_libui_file
24
+ File.expand_path('../lib/glimmer-dsl-libui', __dir__)
25
+ end
26
+
23
27
  def launch
24
28
  window('Meta-Example', 700, 500) { |w|
25
29
  margined true
@@ -39,13 +43,20 @@ class MetaExample
39
43
  stretchy false
40
44
 
41
45
  on_clicked do
42
- system "ruby -r puts_debuggerer -r #{File.expand_path('../lib/glimmer-dsl-libui', __dir__)} #{file_path_for(@examples[@rbs.selected])}"
46
+ begin
47
+ meta_example_file = File.join(Dir.home, '.meta_example.rb')
48
+ File.write(meta_example_file, @nwme.text)
49
+ result = `ruby -r #{glimmer_dsl_libui_file} #{meta_example_file} 2>&1`
50
+ msg_box(w, 'Error Running Example', result) if result.include?('error')
51
+ rescue => e
52
+ puts 'Unable to write code changes! Running original example...'
53
+ system "ruby -r #{glimmer_dsl_libui_file} #{file_path_for(@examples[@rbs.selected])}"
54
+ end
43
55
  end
44
56
  }
45
57
  }
46
58
  vertical_box {
47
59
  @nwme = non_wrapping_multiline_entry {
48
- read_only true
49
60
  text File.read(file_path_for(@examples[@rbs.selected]))
50
61
  }
51
62
  }
Binary file
@@ -29,12 +29,22 @@ module Glimmer
29
29
  def post_initialize_child(child)
30
30
  child.stretchy = true if child.stretchy.nil?
31
31
  ::LibUI.box_append(@libui, child.libui, ControlProxy.boolean_to_integer(child.stretchy))
32
+ children << child
32
33
  end
33
34
 
34
35
  def libui_api_keyword
35
36
  'box'
36
37
  end
37
38
 
39
+ def children
40
+ @children ||= []
41
+ end
42
+
43
+ def destroy_child(child)
44
+ ::LibUI.send("box_delete", @libui, children.index(child))
45
+ ControlProxy.all_control_proxies.delete(child)
46
+ end
47
+
38
48
  private
39
49
 
40
50
  def build_control
@@ -0,0 +1,64 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI color button objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class ColorButtonProxy < ControlProxy
30
+ def color
31
+ @red ||= Fiddle::Pointer.malloc(8) # double
32
+ @green ||= Fiddle::Pointer.malloc(8) # double
33
+ @blue ||= Fiddle::Pointer.malloc(8) # double
34
+ @alpha ||= Fiddle::Pointer.malloc(8) # double
35
+ ::LibUI.color_button_color(@libui, @red, @green, @blue, @alpha)
36
+ [@red[0, 8].unpack1('d') * 255.0, @green[0, 8].unpack1('d') * 255.0, @blue[0, 8].unpack1('d') * 255.0, @alpha[0, 8].unpack1('d')]
37
+ end
38
+
39
+ def red
40
+ color[0]
41
+ end
42
+
43
+ def green
44
+ color[1]
45
+ end
46
+
47
+ def blue
48
+ color[2]
49
+ end
50
+
51
+ def alpha
52
+ color[3]
53
+ end
54
+
55
+ def destroy
56
+ Fiddle.free @red unless @red.nil?
57
+ Fiddle.free @green unless @green.nil?
58
+ Fiddle.free @blue unless @blue.nil?
59
+ Fiddle.free @alpha unless @alpha.nil?
60
+ super
61
+ end
62
+ end
63
+ end
64
+ end
@@ -52,7 +52,7 @@ module Glimmer
52
52
  end
53
53
 
54
54
  def main_window_proxy
55
- all_control_proxies.find {|c| c.is_a?(WindowProxy)}
55
+ all_control_proxies.find {|c| c.is_a?(Glimmer::LibUI::WindowProxy)}
56
56
  end
57
57
 
58
58
  def integer_to_boolean(int)
@@ -62,6 +62,10 @@ module Glimmer
62
62
  def boolean_to_integer(bool)
63
63
  bool.nil? ? nil : (bool ? 1 : 0)
64
64
  end
65
+
66
+ def menu_proxies
67
+ all_control_proxies.select {|c| c.keyword == 'menu' }
68
+ end
65
69
  end
66
70
 
67
71
  BOOLEAN_PROPERTIES = %w[
@@ -167,7 +171,7 @@ module Glimmer
167
171
  ::LibUI.send("#{libui_api_keyword}_#{method_name}", @libui, *args)
168
172
  elsif ::LibUI.respond_to?("control_#{method_name.to_s.sub(/\?$/, '')}") && args.empty?
169
173
  property = method_name.to_s.sub(/\?$/, '')
170
- value = ::LibUI.send("control_#{method_name.to_s.sub(/\?$/, '')}", @libui, *args)
174
+ value = ::LibUI.send("control_#{property}", @libui, *args)
171
175
  handle_string_property(property, handle_boolean_property(property, value))
172
176
  elsif ::LibUI.respond_to?("control_set_#{method_name.to_s.sub(/=$/, '')}")
173
177
  property = method_name.to_s.sub(/=$/, '')
@@ -198,6 +202,23 @@ module Glimmer
198
202
  @keyword
199
203
  end
200
204
 
205
+ def destroy
206
+ if parent_proxy.nil?
207
+ default_destroy
208
+ else
209
+ parent_proxy.destroy_child(self)
210
+ end
211
+ end
212
+
213
+ def destroy_child(child)
214
+ child.default_destroy
215
+ end
216
+
217
+ def default_destroy
218
+ send_to_libui('destroy')
219
+ ControlProxy.all_control_proxies.delete(self)
220
+ end
221
+
201
222
  def enabled(value = nil)
202
223
  if value.nil?
203
224
  @enabled
@@ -229,11 +250,6 @@ module Glimmer
229
250
  alias set_visible visible
230
251
  alias visible= visible
231
252
 
232
- def destroy
233
- send_to_libui('destroy')
234
- self.class.all_control_proxies.delete(self)
235
- end
236
-
237
253
  private
238
254
 
239
255
  def build_control
@@ -27,6 +27,13 @@ module Glimmer
27
27
  #
28
28
  # Follows the Proxy Design Pattern
29
29
  class DatePickerProxy < DateTimePickerProxy
30
+ def time(value = nil)
31
+ if value.nil?
32
+ super.slice(:mday, :mon, :year, :wday, :yday)
33
+ else
34
+ super
35
+ end
36
+ end
30
37
  end
31
38
  end
32
39
  end
@@ -30,6 +30,39 @@ module Glimmer
30
30
  def libui_api_keyword
31
31
  'date_time_picker'
32
32
  end
33
+
34
+ def time(value = nil)
35
+ @time ||= ::LibUI::FFI::TM.malloc
36
+ ::LibUI.date_time_picker_time(@libui, @time)
37
+ if value.nil?
38
+ {
39
+ sec: @time.tm_sec,
40
+ min: @time.tm_min,
41
+ hour: @time.tm_hour,
42
+ mday: @time.tm_mday,
43
+ mon: @time.tm_mon + 1,
44
+ year: @time.tm_year + 1900,
45
+ wday: @time.tm_wday + 1,
46
+ yday: @time.tm_yday + 1,
47
+ dst: @time.tm_isdst == 1
48
+ }
49
+ else
50
+ @time.tm_sec = value[:sec] unless value[:sec].nil?
51
+ @time.tm_min = value[:min] unless value[:min].nil?
52
+ @time.tm_hour = value[:hour] unless value[:hour].nil?
53
+ @time.tm_mday = value[:mday] unless value[:mday].nil?
54
+ @time.tm_mon = value[:mon] - 1 unless value[:mon].nil?
55
+ @time.tm_year = value[:year] - 1900 unless value[:year].nil?
56
+ ::LibUI.date_time_picker_set_time(@libui, @time)
57
+ end
58
+ end
59
+ alias set_time time
60
+ alias time= time
61
+
62
+ def destroy
63
+ Fiddle.free @time unless @time.nil?
64
+ super
65
+ end
33
66
  end
34
67
  end
35
68
  end
@@ -0,0 +1,68 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI font button objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class FontButtonProxy < ControlProxy
30
+ def font
31
+ @font_descriptor ||= ::LibUI::FFI::FontDescriptor.malloc
32
+ ::LibUI.font_button_font(@libui, @font_descriptor)
33
+ {
34
+ family: @font_descriptor.Family.to_s,
35
+ size: @font_descriptor.Size,
36
+ weight: @font_descriptor.Weight,
37
+ italic: @font_descriptor.Italic,
38
+ stretch: @font_descriptor.Stretch
39
+ }
40
+ end
41
+
42
+ def family
43
+ font[:family]
44
+ end
45
+
46
+ def size
47
+ font[:size]
48
+ end
49
+
50
+ def weight
51
+ font[:weight]
52
+ end
53
+
54
+ def italic
55
+ font[:italic]
56
+ end
57
+
58
+ def stretch
59
+ font[:stretch]
60
+ end
61
+
62
+ def destroy
63
+ ::LibUI.free_font_button_font(@font_descriptor) unless @font_descriptor.nil?
64
+ super
65
+ end
66
+ end
67
+ end
68
+ end
@@ -31,6 +31,11 @@ module Glimmer
31
31
  ::LibUI.group_set_child(@libui, child.libui)
32
32
  end
33
33
 
34
+ def destroy_child(child)
35
+ ::LibUI.send("group_set_child", @libui, nil)
36
+ super
37
+ end
38
+
34
39
  private
35
40
 
36
41
  def build_control
@@ -27,6 +27,13 @@ module Glimmer
27
27
  #
28
28
  # Follows the Proxy Design Pattern
29
29
  class TimePickerProxy < DateTimePickerProxy
30
+ def time(value = nil)
31
+ if value.nil?
32
+ super.slice(:sec, :min, :hour)
33
+ else
34
+ super
35
+ end
36
+ end
30
37
  end
31
38
  end
32
39
  end
@@ -35,9 +35,14 @@ module Glimmer
35
35
  def post_initialize_child(child)
36
36
  ::LibUI.window_set_child(@libui, child.libui)
37
37
  end
38
+
39
+ def destroy_child(child)
40
+ ::LibUI.send("window_set_child", @libui, nil)
41
+ super
42
+ end
38
43
 
39
44
  def show
40
- send_to_libui('show')
45
+ super
41
46
  unless @shown_at_least_once
42
47
  @shown_at_least_once = true
43
48
  ::LibUI.main
@@ -64,6 +69,10 @@ module Glimmer
64
69
  private
65
70
 
66
71
  def build_control
72
+ if OS.mac? && ControlProxy.menu_proxies.empty?
73
+ menu_proxy = ControlProxy.create('menu', nil, [''])
74
+ quit_menu_item_proxy = ControlProxy.create('quit_menu_item', menu_proxy, [])
75
+ end
67
76
  construction_args = @args.dup
68
77
  construction_args[0] = DEFAULT_TITLE if construction_args.size == 0
69
78
  construction_args[1] = DEFAULT_WIDTH if construction_args.size == 1
@@ -26,6 +26,7 @@ require 'glimmer'
26
26
  # require 'logging'
27
27
  # require 'puts_debuggerer' if ENV['pd'].to_s.downcase == 'true'
28
28
  # require 'super_module'
29
+ require 'os'
29
30
  require 'libui'
30
31
 
31
32
  # Internal requires
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-20 00:00:00.000000000 Z
11
+ date: 2021-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -24,6 +24,26 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: os
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 2.0.0
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: 2.0.0
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: libui
29
49
  requirement: !ruby/object:Gem::Requirement
@@ -164,7 +184,10 @@ files:
164
184
  - examples/basic_entry.rb
165
185
  - examples/basic_window.rb
166
186
  - examples/basic_window2.rb
187
+ - examples/color_button.rb
167
188
  - examples/control_gallery.rb
189
+ - examples/date_time_picker.rb
190
+ - examples/font_button.rb
168
191
  - examples/meta_example.rb
169
192
  - examples/midi_player.rb
170
193
  - examples/simple_notepad.rb
@@ -181,11 +204,13 @@ files:
181
204
  - lib/glimmer/libui/about_menu_item_proxy.rb
182
205
  - lib/glimmer/libui/box.rb
183
206
  - lib/glimmer/libui/check_menu_item_proxy.rb
207
+ - lib/glimmer/libui/color_button_proxy.rb
184
208
  - lib/glimmer/libui/combobox_proxy.rb
185
209
  - lib/glimmer/libui/control_proxy.rb
186
210
  - lib/glimmer/libui/date_picker_proxy.rb
187
211
  - lib/glimmer/libui/date_time_picker_proxy.rb
188
212
  - lib/glimmer/libui/editable_combobox_proxy.rb
213
+ - lib/glimmer/libui/font_button_proxy.rb
189
214
  - lib/glimmer/libui/group_proxy.rb
190
215
  - lib/glimmer/libui/horizontal_box_proxy.rb
191
216
  - lib/glimmer/libui/menu_item_proxy.rb