glimmer-dsl-libui 0.0.27 → 0.1.2

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: 1014e0c2243936dc61a783c96c3f5760faf93692f8d60535667b29f5a0378cf9
4
- data.tar.gz: 4176b09e4f89d5cdf2d182f1dceb9ae67aab71b3b28696d1a77e191708b931d8
3
+ metadata.gz: 588ece65aa562fd337018de00f5e60156926cb6d9ee6144f5f89e2e8dfaa2d74
4
+ data.tar.gz: f50f57a58f6b7915f5e9fc123eecf9e982be5f18ff93833a8d0603ce3955063d
5
5
  SHA512:
6
- metadata.gz: 7080a17729c2059e0b7459a6087466d38a7fda9aa91be1964109418ec2bb8c55187d45fa75f6b2c83fa9c30d886c8efb84ca1c1714cf73e5e02b6a6a51741559
7
- data.tar.gz: 9f21040ea200f827efcb235541fe28565361819aae0005653778d480b80b6e9d43e6ec7008e5512199abeb2e5832f2776beacda806cf260b73795bf5bfa7e9e5
6
+ metadata.gz: 6b0d02fde1567c4be008e81b91fc67df319fd2c46bf44466da6e4ff2e8a49f31bd239a78ed69be43f1338fa51dd4fcd648d6c5ecbe2aafe41fb345911df327bf
7
+ data.tar.gz: cfe32a98fddb52c1cf320e4e8d7651d0b083172ada4dd4b43441f0fdb839cde207841c96e39d9e47c7cffeb536a7d6620aed3abe869c790ce595c4361ac2988c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.1.2
4
+
5
+ - Support re-opening a control by using `#content {...}`
6
+ - Ensure destroying `path`/`rectangle` after drawing if it is declared inside `on_draw`
7
+ - Observe `path` `fill` and `stroke` hashes for changes and automatically redraw area accordingly
8
+ - New examples/dynamic_area2.rb (using stable paths)
9
+
10
+ ## 0.1.1
11
+
12
+ - Support `area` listener: `on_draw`
13
+ - New examples/basic_area2.rb
14
+
15
+ ## 0.1.0
16
+
17
+ - Support examples/basic_area.rb
18
+ - Support `area` control
19
+ - Support `path(fill_mode)` control
20
+ - Support `rectangle(x, y, width, height)` figure
21
+ - Support `path` `fill` property
22
+ - Support `path` `stroke` property
23
+
24
+ ## 0.0.28
25
+
26
+ - Support automatic table row change when updating a row in `cell_rows` (e.g. `data[3] = ['new', 'row', 'cell', 'values']`)
27
+ - Support `editable` property for `checkbox_column` (checkbox editing only works in Windows due to a [libui](https://github.com/andlabs/libui) limitation)
28
+ - Support `editable`, `editable_checkbox`, and `editable_text` properties for `checkbox_text_column` (checkbox editing only works in Windows due to a [libui](https://github.com/andlabs/libui) limitation)
29
+ - Fix examples/basic_table_checkbox_text.rb by removing `editable` property
30
+
3
31
  ## 0.0.27
4
32
 
5
33
  - New examples/form_table.rb
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.27
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.1.2
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)
@@ -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.27](#-glimmer-dsl-for-libui-0027)
46
+ - [Glimmer DSL for LibUI 0.1.2](#-glimmer-dsl-for-libui-012)
47
47
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
48
48
  - [Usage](#usage)
49
49
  - [API](#api)
@@ -52,6 +52,8 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
52
52
  - [Common Control Operations](#common-control-operations)
53
53
  - [Extra Dialogs](#extra-dialogs)
54
54
  - [Extra Operations](#extra-operations)
55
+ - [Table API](#table-api)
56
+ - [Area API](#area-api)
55
57
  - [Smart Defaults and Conventions](#smart-defaults-and-conventions)
56
58
  - [API Gotchas](#api-gotchas)
57
59
  - [Original API](#original-api)
@@ -79,6 +81,8 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
79
81
  - [Basic Table Checkbox Text](#basic-table-checkbox-text)
80
82
  - [Basic Table Progress Bar](#basic-table-progress-bar)
81
83
  - [Form Table](#form-table)
84
+ - [Basic Area](#basic-area)
85
+ - [Dynamic Area](#dynamic-area)
82
86
  - [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
83
87
  - [Help](#help)
84
88
  - [Issues](#issues)
@@ -166,7 +170,7 @@ gem install glimmer-dsl-libui
166
170
  Or install via Bundler `Gemfile`:
167
171
 
168
172
  ```ruby
169
- gem 'glimmer-dsl-libui', '~> 0.0.27'
173
+ gem 'glimmer-dsl-libui', '~> 0.1.2'
170
174
  ```
171
175
 
172
176
  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.
@@ -222,11 +226,12 @@ w.libui # => #<Fiddle::Pointer:0x00007fde53997980 ptr=0x00007fde51352a60 size=0
222
226
  Control(Args) | Properties | Listeners
223
227
  ------------- | ---------- | ---------
224
228
  `about_menu_item` | None | `on_clicked`
229
+ `area` | None | `on_draw`
225
230
  `button(text as String)` | `text` (`String`) | `on_clicked`
226
231
  `button_column(name as String)` | `enabled` (Boolean) | None
227
232
  `checkbox(text as String)` | `checked` (Boolean), `text` (`String`) | `on_toggled`
228
- `checkbox_column(name as String)` | None | None
229
- `checkbox_text_column(name as String)` | `editable` (Boolean) | None
233
+ `checkbox_column(name as String)` | `editable` (Boolean) | None
234
+ `checkbox_text_column(name as String)` | `editable` (Boolean), `editable_checkbox` (Boolean), `editable_text` (Boolean) | None
230
235
  `combobox` | `items` (`Array` of `String`), `selected` (`Integer`) | `on_selected`
231
236
  `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`
232
237
  `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`
@@ -250,11 +255,13 @@ Control(Args) | Properties | Listeners
250
255
  `msg_box(window as Glimmer::LibUI::WindowProxy, title as String, description as String)` | None | None
251
256
  `msg_box_error(window as Glimmer::LibUI::WindowProxy, title as String, description as String)` | None | None
252
257
  `non_wrapping_multiline_entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
258
+ `path` | `fill` (`Hash` of `:r` as `0`-`255`, `:g` as `0`-`255`, `:b` as `0`-`255`, `:a` as `0.0`-`1.0`), `stroke` (`Hash` of `:r` as `0`-`255`, `:g` as `0`-`255`, `:b` as `0`-`255`, `:a` as `0.0`-`1.0`, `:cap` as `Numeric`, `:join` as `Numeric`, `:thickness` as `Numeric`, `:miter_limit` as `Numeric` ) | None
253
259
  `preferences_menu_item` | None | `on_clicked`
254
260
  `progress_bar` | `value` (`Numeric`) | None
255
261
  `progress_bar_column(name as String)` | None | None
256
262
  `quit_menu_item` | None | `on_clicked`
257
263
  `radio_buttons` | `selected` (`Integer`) | `on_selected`
264
+ `rectangle(x as Numeric, y as Numeric, width as Numeric, height as Numeric)` | None | None
258
265
  `slider(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
259
266
  `spinbox(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
260
267
  `tab` | `margined` (Boolean), `num_pages` (`Integer`) | None
@@ -301,6 +308,85 @@ Control(Args) | Properties | Listeners
301
308
  - `ControlProxy::image_proxies`: returns all instantiated `image` proxies in the application
302
309
  - `ControlProxy::main_window_proxy`: returns the first window proxy instantiated in the application
303
310
  - `ControlProxy#window_proxy`: returns the window proxy parent for a control
311
+ - `ControlProxy#content {...}`: re-opens control's content to add more nested controls or properties
312
+
313
+ ### Table API
314
+
315
+ The `table` control must first declare its columns via one of these column keywords (mentioned in [Supported Controls](#supported-controls)):
316
+ - `button_column`: expects `String` cell values
317
+ - `checkbox_column`: expects Boolean cell values
318
+ - `checkbox_text_column`: expects dual-element `Array` of Boolean and `String` cell values
319
+ - `image_column`: expects `image` cell values (produced by `image` and `image_part` keywords as per [Supported Controls](#supported-controls))
320
+ - `image_text_column`: expects dual-element `Array` of `image` and `String` cell values
321
+ - `text_column`: expects `String` cell values
322
+ - `progress_bar_column`: expects `Integer` cell values
323
+
324
+ Afterwards, it must declare its `cell_rows` array (`Array` of `Array`s of column cell values) and whether it is `editable` (Boolean) for all its columns.
325
+
326
+ Note that the `cell_rows` property declaration results in "implicit data-binding" between the `table` control and `Array` of `Arrays` (a new innovation) to provide convenience automatic support for:
327
+ - Deleting cell rows: Calling `Array#delete`, `Array#delete_at`, `Array#delete_if`, or any filtering/deletion `Array` method automatically deletes rows in actual `table` control
328
+ - Inserting cell rows: Calling `Array#<<`, `Array#push`, `Array#prepend`, or any insertion/addition `Array` method automatically inserts rows in actual `table` control
329
+ - Changing cell rows: Calling `Array#[]=`, `Array#map!`, or any update `Array` method automatically updates rows in actual `table` control
330
+
331
+ ### Area API
332
+
333
+ The `area` control can be used in one of two ways:
334
+ - Declaratively via stable paths: useful for stable paths that will not change later on. Simply nest `path` and figures like `rectangle` and all drawing logic is generated automatically. Paths proxy objects are preserved across redraws assuming there would be few stable paths (mostly for decorative reasons).
335
+ - Semi-declaratively via on_draw listener dynamic paths: useful for more dynamic paths that will definitely change. Open an `on_draw` listener block and nest `path(area_draw_params)` and figures like `rectangle` and all drawing logic is generated automatically. Path proxy objects are destroyed (thrown-away) at the end of drawing, thus having less memory overhead for drawing thousands of dynamic paths.
336
+
337
+ Here is an example of a declarative `area` with a stable path (you may copy/paste in [`girb`](#girb-glimmer-irb)):
338
+
339
+ ```ruby
340
+ require 'glimmer-dsl-libui'
341
+
342
+ include Glimmer
343
+
344
+ window('Basic Area', 400, 400) {
345
+ margined true
346
+
347
+ vertical_box {
348
+ area {
349
+ path { # a stable path is added declaratively
350
+ rectangle(0, 0, 400, 400)
351
+
352
+ fill r: 102, g: 102, b: 204, a: 1.0
353
+ }
354
+ }
355
+ }
356
+ }.show
357
+ ```
358
+
359
+ ![glimmer-dsl-libui-mac-basic-area.png](images/glimmer-dsl-libui-mac-basic-area.png)
360
+
361
+ Here is the same example using a semi-declarative `area` with `on_draw` listener and a dynamic path (you may copy/paste in [`girb`](#girb-glimmer-irb)):
362
+
363
+ ```ruby
364
+ require 'glimmer-dsl-libui'
365
+
366
+ include Glimmer
367
+
368
+ window('Basic Area', 400, 400) {
369
+ margined true
370
+
371
+ vertical_box {
372
+ area {
373
+ on_draw do |area_draw_params|
374
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
375
+ rectangle(0, 0, 400, 400)
376
+
377
+ fill r: 102, g: 102, b: 204, a: 1.0
378
+ }
379
+ end
380
+ }
381
+ }
382
+ }.show
383
+ ```
384
+
385
+ Check [examples/dynamic_area.rb](#dynamic-area) for a more detailed semi-declarative example.
386
+
387
+ In general, it is recommended to use declarative stable paths whenever feasible since they require less code and simpler maintenance. But, in more advanced cases, semi-declarative dynamic paths could be used instead, especially if there are thousands of paths.
388
+
389
+ To redraw an `area`, you may call `#queue_redraw_all` method.
304
390
 
305
391
  ### Smart Defaults and Conventions
306
392
 
@@ -327,13 +413,17 @@ Control(Args) | Properties | Listeners
327
413
  - Smart defaults for `grid` child attributes are `left` (`0`), `top` (`0`), `xspan` (`1`), `yspan` (`1`), `hexpand` (`false`), `halign` (`0`), `vexpand` (`false`), and `valign` (`0`)
328
414
  - The `table` control automatically constructs required `TableModelHandler`, `TableModel`, and `TableParams`, calculating all their arguments from `cell_rows` and `editable` properties (e.g. `NumRows`) as well as nested columns (e.g. `text_column`)
329
415
  - Table model instances are automatically freed from memory after `window` is destroyed.
330
- - Table `cell_rows` data has implicit data-binding to table cell values for deletion and insertion (done by diffing `cell_rows` value before and after change and auto-informing `table` of deletions [`::LibUI.table_model_row_deleted`] and insertions [`::LibUI.table_model_row_deleted`]). When deleting data rows from `cell_rows` array, then actual rows from the `table` are automatically deleted. When inserting data rows into `cell_rows` array, then actual `table` rows are automatically inserted.
416
+ - Table `cell_rows` data has implicit data-binding to table cell values for deletion, insertion, and change (done by diffing `cell_rows` value before and after change and auto-informing `table` of deletions [`LibUI.table_model_row_deleted`], insertions [`LibUI.table_model_row_deleted`], and changes [`LibUI.table_model_row_changed`]). When deleting data rows from `cell_rows` array, then actual rows from the `table` are automatically deleted. When inserting data rows into `cell_rows` array, then actual `table` rows are automatically inserted. When updating data rows in `cell_rows` array, then actual `table` rows are automatically updated.
331
417
  - `image` instances are automatically freed from memory after `window` is destroyed.
332
418
  - `image` `width` and `height` can be left off if it has one `image_part` only as they default to the same `width` and `height` of the `image_part`
419
+ - `area` paths are specified declaratively with figures underneath (e.g. `rectangle`) and `area` draw listener is automatically generated
420
+ - Observe figure properties (e.g. `rectangle` `width`) for changes and automatically redraw containing area accordingly
421
+ - Observe `path` `fill` and `stroke` hashes for changes and automatically redraw containing area accordingly
333
422
 
334
423
  ### API Gotchas
335
424
 
336
- There is no proper way to destroy `grid` children due to [libui](https://github.com/andlabs/libui) not offering any API for deleting them from `grid` (no `grid_delete` similar to `box_delete` for `horizontal_box` and `vertical_box`)
425
+ - There is no proper way to destroy `grid` children due to [libui](https://github.com/andlabs/libui) not offering any API for deleting them from `grid` (no `grid_delete` similar to `box_delete` for `horizontal_box` and `vertical_box`).
426
+ - `table` `checkbox_column` and `checkbox_text_column` checkbox editing only works on Windows and Linux (not Mac) due to a current limitation in [libui](https://github.com/andlabs/ui/issues/357).
337
427
 
338
428
  ### Original API
339
429
 
@@ -2561,6 +2651,360 @@ window('Contacts', 600, 600) { |w|
2561
2651
  }.show
2562
2652
  ```
2563
2653
 
2654
+ ### Basic Area
2655
+
2656
+ [examples/basic_area.rb](examples/basic_area.rb)
2657
+
2658
+ Run with this command from the root of the project if you cloned the project:
2659
+
2660
+ ```
2661
+ ruby -r './lib/glimmer-dsl-libui' examples/basic_area.rb
2662
+ ```
2663
+
2664
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
2665
+
2666
+ ```
2667
+ ruby -r glimmer-dsl-libui -e "require 'examples/basic_area'"
2668
+ ```
2669
+
2670
+ Mac
2671
+
2672
+ ![glimmer-dsl-libui-mac-basic-area.png](images/glimmer-dsl-libui-mac-basic-area.png)
2673
+
2674
+ Linux
2675
+
2676
+ ![glimmer-dsl-libui-linux-basic-area.png](images/glimmer-dsl-libui-linux-basic-area.png)
2677
+
2678
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
2679
+
2680
+ ```ruby
2681
+ require 'libui'
2682
+
2683
+ UI = LibUI
2684
+
2685
+ UI.init
2686
+
2687
+ handler = UI::FFI::AreaHandler.malloc
2688
+ area = UI.new_area(handler)
2689
+ brush = UI::FFI::DrawBrush.malloc
2690
+
2691
+ handler_draw_event = Fiddle::Closure::BlockCaller.new(0, [1, 1, 1]) do |_, _, area_draw_params|
2692
+ path = UI.draw_new_path(0)
2693
+ UI.draw_path_add_rectangle(path, 0, 0, 400, 400)
2694
+ UI.draw_path_end(path)
2695
+ brush.Type = 0
2696
+ brush.R = 0.4
2697
+ brush.G = 0.4
2698
+ brush.B = 0.8
2699
+ brush.A = 1.0
2700
+ area_draw_params = UI::FFI::AreaDrawParams.new(area_draw_params)
2701
+ UI.draw_fill(area_draw_params.Context, path, brush.to_ptr)
2702
+ UI.draw_free_path(path)
2703
+ end
2704
+
2705
+ handler.Draw = handler_draw_event
2706
+ handler.MouseEvent = Fiddle::Closure::BlockCaller.new(0, [0]) {}
2707
+ handler.MouseCrossed = Fiddle::Closure::BlockCaller.new(0, [0]) {}
2708
+ handler.DragBroken = Fiddle::Closure::BlockCaller.new(0, [0]) {}
2709
+ handler.KeyEvent = Fiddle::Closure::BlockCaller.new(0, [0]) {}
2710
+
2711
+ box = UI.new_vertical_box
2712
+ UI.box_set_padded(box, 1)
2713
+ UI.box_append(box, area, 1)
2714
+
2715
+ main_window = UI.new_window('Basic Area', 400, 400, 1)
2716
+ UI.window_set_margined(main_window, 1)
2717
+ UI.window_set_child(main_window, box)
2718
+
2719
+ UI.window_on_closing(main_window) do
2720
+ UI.control_destroy(main_window)
2721
+ UI.quit
2722
+ 0
2723
+ end
2724
+ UI.control_show(main_window)
2725
+
2726
+ UI.main
2727
+ UI.quit
2728
+ ```
2729
+
2730
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
2731
+
2732
+ ```ruby
2733
+ require 'glimmer-dsl-libui'
2734
+
2735
+ include Glimmer
2736
+
2737
+ window('Basic Area', 400, 400) {
2738
+ margined true
2739
+
2740
+ vertical_box {
2741
+ area {
2742
+ path { # a stable path is added declaratively
2743
+ rectangle(0, 0, 400, 400)
2744
+
2745
+ fill r: 102, g: 102, b: 204, a: 1.0
2746
+ }
2747
+ }
2748
+ }
2749
+ }.show
2750
+ ```
2751
+
2752
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
2753
+
2754
+ ```ruby
2755
+ require 'glimmer-dsl-libui'
2756
+
2757
+ include Glimmer
2758
+
2759
+ window('Basic Area', 400, 400) {
2760
+ margined true
2761
+
2762
+ vertical_box {
2763
+ area {
2764
+ on_draw do |area_draw_params|
2765
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
2766
+ rectangle(0, 0, 400, 400)
2767
+
2768
+ fill r: 102, g: 102, b: 204, a: 1.0
2769
+ }
2770
+ end
2771
+ }
2772
+ }
2773
+ }.show
2774
+ ```
2775
+
2776
+ ### Dynamic Area
2777
+
2778
+ [examples/dynamic_area.rb](examples/dynamic_area.rb)
2779
+
2780
+ Run with this command from the root of the project if you cloned the project:
2781
+
2782
+ ```
2783
+ ruby -r './lib/glimmer-dsl-libui' examples/dynamic_area.rb
2784
+ ```
2785
+
2786
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
2787
+
2788
+ ```
2789
+ ruby -r glimmer-dsl-libui -e "require 'examples/dynamic_area'"
2790
+ ```
2791
+
2792
+ Mac
2793
+
2794
+ ![glimmer-dsl-libui-mac-dynamic-area.png](images/glimmer-dsl-libui-mac-dynamic-area.png)
2795
+ ![glimmer-dsl-libui-mac-dynamic-area-updated.png](images/glimmer-dsl-libui-mac-dynamic-area-updated.png)
2796
+
2797
+ Linux
2798
+
2799
+ ![glimmer-dsl-libui-linux-dynamic-area.png](images/glimmer-dsl-libui-linux-dynamic-area.png)
2800
+ ![glimmer-dsl-libui-linux-dynamic-area-updated.png](images/glimmer-dsl-libui-linux-dynamic-area-updated.png)
2801
+
2802
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
2803
+
2804
+ ```ruby
2805
+ require 'glimmer-dsl-libui'
2806
+
2807
+ include Glimmer
2808
+
2809
+ window('Dynamic Area', 240, 500) {
2810
+ margined true
2811
+
2812
+ vertical_box {
2813
+ label('Rectangle Properties') {
2814
+ stretchy false
2815
+ }
2816
+
2817
+ form {
2818
+ stretchy false
2819
+
2820
+ @x_spinbox = spinbox(0, 1000) {
2821
+ label 'x'
2822
+ value 25
2823
+
2824
+ on_changed do
2825
+ @area.queue_redraw_all
2826
+ end
2827
+ }
2828
+
2829
+ @y_spinbox = spinbox(0, 1000) {
2830
+ label 'y'
2831
+ value 25
2832
+
2833
+ on_changed do
2834
+ @area.queue_redraw_all
2835
+ end
2836
+ }
2837
+
2838
+ @width_spinbox = spinbox(0, 1000) {
2839
+ label 'width'
2840
+ value 150
2841
+
2842
+ on_changed do
2843
+ @area.queue_redraw_all
2844
+ end
2845
+ }
2846
+
2847
+ @height_spinbox = spinbox(0, 1000) {
2848
+ label 'height'
2849
+ value 150
2850
+
2851
+ on_changed do
2852
+ @area.queue_redraw_all
2853
+ end
2854
+ }
2855
+
2856
+ @red_spinbox = spinbox(0, 255) {
2857
+ label 'red'
2858
+ value 102
2859
+
2860
+ on_changed do
2861
+ @area.queue_redraw_all
2862
+ end
2863
+ }
2864
+
2865
+ @green_spinbox = spinbox(0, 255) {
2866
+ label 'green'
2867
+ value 102
2868
+
2869
+ on_changed do
2870
+ @area.queue_redraw_all
2871
+ end
2872
+ }
2873
+
2874
+ @blue_spinbox = spinbox(0, 255) {
2875
+ label 'blue'
2876
+ value 204
2877
+
2878
+ on_changed do
2879
+ @area.queue_redraw_all
2880
+ end
2881
+ }
2882
+
2883
+ @alpha_spinbox = spinbox(0, 100) {
2884
+ label 'alpha'
2885
+ value 100
2886
+
2887
+ on_changed do
2888
+ @area.queue_redraw_all
2889
+ end
2890
+ }
2891
+ }
2892
+
2893
+ @area = area {
2894
+ on_draw do |area_draw_params|
2895
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
2896
+ rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value)
2897
+
2898
+ fill r: @red_spinbox.value, g: @green_spinbox.value, b: @blue_spinbox.value, a: @alpha_spinbox.value / 100.0
2899
+ }
2900
+ end
2901
+ }
2902
+ }
2903
+ }.show
2904
+ ```
2905
+
2906
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
2907
+
2908
+ ```ruby
2909
+ require 'glimmer-dsl-libui'
2910
+
2911
+ include Glimmer
2912
+
2913
+ window('Dynamic Area', 240, 600) {
2914
+ margined true
2915
+
2916
+ vertical_box {
2917
+ label('Rectangle Properties') {
2918
+ stretchy false
2919
+ }
2920
+
2921
+ form {
2922
+ stretchy false
2923
+
2924
+ @x_spinbox = spinbox(0, 1000) {
2925
+ label 'x'
2926
+ value 25
2927
+
2928
+ on_changed do
2929
+ @rectangle.x = @x_spinbox.value # updating properties automatically triggers area.queue_redraw_all
2930
+ end
2931
+ }
2932
+
2933
+ @y_spinbox = spinbox(0, 1000) {
2934
+ label 'y'
2935
+ value 25
2936
+
2937
+ on_changed do
2938
+ @rectangle.y = @y_spinbox.value # updating properties automatically triggers area.queue_redraw_all
2939
+ end
2940
+ }
2941
+
2942
+ @width_spinbox = spinbox(0, 1000) {
2943
+ label 'width'
2944
+ value 150
2945
+
2946
+ on_changed do
2947
+ @rectangle.width = @width_spinbox.value # updating properties automatically triggers area.queue_redraw_all
2948
+ end
2949
+ }
2950
+
2951
+ @height_spinbox = spinbox(0, 1000) {
2952
+ label 'height'
2953
+ value 150
2954
+
2955
+ on_changed do
2956
+ @rectangle.height = @height_spinbox.value # updating properties automatically triggers area.queue_redraw_all
2957
+ end
2958
+ }
2959
+
2960
+ @red_spinbox = spinbox(0, 255) {
2961
+ label 'red'
2962
+ value 102
2963
+
2964
+ on_changed do
2965
+ @path.fill[:r] = @red_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
2966
+ end
2967
+ }
2968
+
2969
+ @green_spinbox = spinbox(0, 255) {
2970
+ label 'green'
2971
+ value 102
2972
+
2973
+ on_changed do
2974
+ @path.fill[:g] = @green_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
2975
+ end
2976
+ }
2977
+
2978
+ @blue_spinbox = spinbox(0, 255) {
2979
+ label 'blue'
2980
+ value 204
2981
+
2982
+ on_changed do
2983
+ @path.fill[:b] = @blue_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
2984
+ end
2985
+ }
2986
+
2987
+ @alpha_spinbox = spinbox(0, 100) {
2988
+ label 'alpha'
2989
+ value 100
2990
+
2991
+ on_changed do
2992
+ @path.fill[:a] = @alpha_spinbox.value / 100.0 # updating hash properties automatically triggers area.queue_redraw_all
2993
+ end
2994
+ }
2995
+ }
2996
+
2997
+ area {
2998
+ @path = path { # stable path
2999
+ @rectangle = rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value)
3000
+
3001
+ fill r: @red_spinbox.value, g: @green_spinbox.value, b: @blue_spinbox.value, a: @alpha_spinbox.value / 100.0
3002
+ }
3003
+ }
3004
+ }
3005
+ }.show
3006
+ ```
3007
+
2564
3008
  ## Contributing to glimmer-dsl-libui
2565
3009
 
2566
3010
  - Check out the latest master to make sure the feature hasn't been
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.27
1
+ 0.1.2
@@ -0,0 +1,17 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ include Glimmer
4
+
5
+ window('Basic Area', 400, 400) {
6
+ margined true
7
+
8
+ vertical_box {
9
+ area {
10
+ path { # a stable path is added declaratively
11
+ rectangle(0, 0, 400, 400)
12
+
13
+ fill r: 102, g: 102, b: 204, a: 1.0
14
+ }
15
+ }
16
+ }
17
+ }.show
@@ -0,0 +1,19 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ include Glimmer
4
+
5
+ window('Basic Area', 400, 400) {
6
+ margined true
7
+
8
+ vertical_box {
9
+ area {
10
+ on_draw do |area_draw_params|
11
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
12
+ rectangle(0, 0, 400, 400)
13
+
14
+ fill r: 102, g: 102, b: 204, a: 1.0
15
+ }
16
+ end
17
+ }
18
+ }
19
+ }.show
@@ -17,9 +17,7 @@ window('Animal sounds', 400, 200) {
17
17
  table {
18
18
  text_column('Animal')
19
19
  text_column('Sound')
20
- checkbox_text_column('Description') {
21
- editable true
22
- }
20
+ checkbox_text_column('Description')
23
21
 
24
22
  cell_rows data
25
23
  }