glimmer-dsl-libui 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/README.md +63 -55
  4. data/VERSION +1 -1
  5. data/examples/basic_button.rb +2 -2
  6. data/examples/basic_entry.rb +2 -2
  7. data/examples/basic_transform.rb +1 -1
  8. data/examples/control_gallery.rb +3 -3
  9. data/examples/form.rb +2 -2
  10. data/examples/histogram.rb +18 -19
  11. data/examples/meta_example.rb +71 -20
  12. data/examples/midi_player.rb +8 -10
  13. data/glimmer-dsl-libui.gemspec +0 -0
  14. data/lib/glimmer/dsl/libui/control_expression.rb +0 -2
  15. data/lib/glimmer/dsl/libui/file_expression.rb +5 -1
  16. data/lib/glimmer/dsl/libui/shape_expression.rb +2 -4
  17. data/lib/glimmer/dsl/libui/tab_item_expression.rb +2 -2
  18. data/lib/glimmer/libui/control_proxy/area_proxy.rb +117 -0
  19. data/lib/glimmer/libui/{menu_item_proxy.rb → control_proxy/box/horizontal_box_proxy.rb} +9 -12
  20. data/lib/glimmer/libui/{horizontal_box_proxy.rb → control_proxy/box/vertical_box_proxy.rb} +10 -6
  21. data/lib/glimmer/libui/{box.rb → control_proxy/box.rb} +31 -27
  22. data/lib/glimmer/libui/{button_proxy.rb → control_proxy/button_proxy.rb} +14 -12
  23. data/lib/glimmer/libui/{checkbox_proxy.rb → control_proxy/checkbox_proxy.rb} +14 -12
  24. data/lib/glimmer/libui/control_proxy/color_button_proxy.rb +118 -0
  25. data/lib/glimmer/libui/control_proxy/column/button_column_proxy.rb +76 -0
  26. data/lib/glimmer/libui/control_proxy/column/checkbox_column_proxy.rb +46 -0
  27. data/lib/glimmer/libui/control_proxy/column/checkbox_text_column_proxy.rb +80 -0
  28. data/lib/glimmer/libui/{radio_buttons_proxy.rb → control_proxy/column/image_column_proxy.rb} +14 -13
  29. data/lib/glimmer/libui/control_proxy/column/image_text_column_proxy.rb +48 -0
  30. data/lib/glimmer/libui/control_proxy/column/progress_bar_column_proxy.rb +44 -0
  31. data/lib/glimmer/libui/{checkbox_column_proxy.rb → control_proxy/column/text_column_proxy.rb} +17 -13
  32. data/lib/glimmer/libui/control_proxy/column.rb +55 -0
  33. data/lib/glimmer/libui/control_proxy/combobox_proxy.rb +45 -0
  34. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy/date_picker_proxy.rb +43 -0
  35. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy/time_picker_proxy.rb +43 -0
  36. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy.rb +72 -0
  37. data/lib/glimmer/libui/control_proxy/dual_column.rb +40 -0
  38. data/lib/glimmer/libui/control_proxy/editable_column.rb +46 -0
  39. data/lib/glimmer/libui/control_proxy/editable_combobox_proxy.rb +45 -0
  40. data/lib/glimmer/libui/{dual_column.rb → control_proxy/enableable_column.rb} +18 -10
  41. data/lib/glimmer/libui/control_proxy/font_button_proxy.rb +70 -0
  42. data/lib/glimmer/libui/{form_proxy.rb → control_proxy/form_proxy.rb} +26 -24
  43. data/lib/glimmer/libui/{grid_proxy.rb → control_proxy/grid_proxy.rb} +29 -27
  44. data/lib/glimmer/libui/{group_proxy.rb → control_proxy/group_proxy.rb} +24 -22
  45. data/lib/glimmer/libui/{image_part_proxy.rb → control_proxy/image_part_proxy.rb} +20 -18
  46. data/lib/glimmer/libui/{image_proxy.rb → control_proxy/image_proxy.rb} +32 -30
  47. data/lib/glimmer/libui/{combobox_proxy.rb → control_proxy/label_proxy.rb} +13 -13
  48. data/lib/glimmer/libui/control_proxy/matrix_proxy.rb +147 -0
  49. data/lib/glimmer/libui/{editable_column.rb → control_proxy/menu_item_proxy/about_menu_item_proxy.rb} +13 -16
  50. data/lib/glimmer/libui/{enableable_column.rb → control_proxy/menu_item_proxy/check_menu_item_proxy.rb} +13 -16
  51. data/lib/glimmer/libui/{date_picker_proxy.rb → control_proxy/menu_item_proxy/preferences_menu_item_proxy.rb} +10 -10
  52. data/lib/glimmer/libui/{quit_menu_item_proxy.rb → control_proxy/menu_item_proxy/quit_menu_item_proxy.rb} +33 -29
  53. data/lib/glimmer/libui/control_proxy/menu_item_proxy/separator_menu_item_proxy.rb +41 -0
  54. data/lib/glimmer/libui/control_proxy/menu_item_proxy.rb +45 -0
  55. data/lib/glimmer/libui/{editable_combobox_proxy.rb → control_proxy/menu_proxy.rb} +13 -13
  56. data/lib/glimmer/libui/{vertical_box_proxy.rb → control_proxy/message_box/msg_box_error_proxy.rb} +9 -6
  57. data/lib/glimmer/libui/{multiline_entry_proxy.rb → control_proxy/message_box/msg_box_proxy.rb} +8 -6
  58. data/lib/glimmer/libui/{time_picker_proxy.rb → control_proxy/message_box.rb} +9 -10
  59. data/lib/glimmer/libui/{rectangle.rb → control_proxy/multiline_entry_proxy/non_wrapping_multiline_entry_proxy.rb} +6 -8
  60. data/lib/glimmer/libui/{progress_bar_column_proxy.rb → control_proxy/multiline_entry_proxy.rb} +10 -11
  61. data/lib/glimmer/libui/control_proxy/path_proxy.rb +169 -0
  62. data/lib/glimmer/libui/control_proxy/radio_buttons_proxy.rb +45 -0
  63. data/lib/glimmer/libui/{button_column_proxy.rb → control_proxy/tab_item_proxy.rb} +37 -40
  64. data/lib/glimmer/libui/control_proxy/table_proxy.rb +182 -0
  65. data/lib/glimmer/libui/{transformable.rb → control_proxy/transformable.rb} +3 -1
  66. data/lib/glimmer/libui/control_proxy/window_proxy.rb +128 -0
  67. data/lib/glimmer/libui/control_proxy.rb +35 -8
  68. data/lib/glimmer/libui/{arc.rb → shape/arc.rb} +13 -11
  69. data/lib/glimmer/libui/shape/bezier.rb +38 -0
  70. data/lib/glimmer/libui/{figure.rb → shape/figure.rb} +23 -21
  71. data/lib/glimmer/libui/{line.rb → shape/line.rb} +9 -7
  72. data/lib/glimmer/libui/{bezier.rb → shape/rectangle.rb} +9 -7
  73. data/lib/glimmer/libui/{square.rb → shape/square.rb} +9 -7
  74. data/lib/glimmer/libui/shape.rb +8 -6
  75. data/lib/glimmer/libui.rb +43 -1
  76. data/lib/glimmer-dsl-libui.rb +1 -0
  77. metadata +72 -55
  78. data/lib/glimmer/libui/about_menu_item_proxy.rb +0 -37
  79. data/lib/glimmer/libui/area_proxy.rb +0 -115
  80. data/lib/glimmer/libui/check_menu_item_proxy.rb +0 -37
  81. data/lib/glimmer/libui/checkbox_text_column_proxy.rb +0 -76
  82. data/lib/glimmer/libui/color_button_proxy.rb +0 -116
  83. data/lib/glimmer/libui/column.rb +0 -51
  84. data/lib/glimmer/libui/date_time_picker_proxy.rb +0 -68
  85. data/lib/glimmer/libui/font_button_proxy.rb +0 -68
  86. data/lib/glimmer/libui/image_column_proxy.rb +0 -40
  87. data/lib/glimmer/libui/image_text_column_proxy.rb +0 -44
  88. data/lib/glimmer/libui/label_proxy.rb +0 -41
  89. data/lib/glimmer/libui/matrix_proxy.rb +0 -145
  90. data/lib/glimmer/libui/menu_proxy.rb +0 -41
  91. data/lib/glimmer/libui/non_wrapping_multiline_entry_proxy.rb +0 -32
  92. data/lib/glimmer/libui/path_proxy.rb +0 -166
  93. data/lib/glimmer/libui/preferences_menu_item_proxy.rb +0 -37
  94. data/lib/glimmer/libui/separator_menu_item_proxy.rb +0 -37
  95. data/lib/glimmer/libui/tab_item_proxy.rb +0 -67
  96. data/lib/glimmer/libui/table_proxy.rb +0 -180
  97. data/lib/glimmer/libui/text_column_proxy.rb +0 -42
  98. data/lib/glimmer/libui/window_proxy.rb +0 -126
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56c014bad471f47e7af8a1a36bd6e1642f613c5c5ff0371e16ccd037401831a0
4
- data.tar.gz: adcbb03e5e80604fac25a6c167aefca3b451f6b5a9bc29bbc2679a6e19fce4fc
3
+ metadata.gz: 94f447a302c22ea118d50c6d8f1b81c3a74cbd81fb7b6b6d61a7bb0cf22e9dd3
4
+ data.tar.gz: 50faeffb8a2e2efaece4464432ecb6a51080e9662b4778f606f872a8286332a9
5
5
  SHA512:
6
- metadata.gz: 65003a4c358b09c6ec0d2f5215245808af2f6510ea2901067b33363e918ee9b9713005546d0baf925a16ccb1ad490229217f1ed4ae8ec375085bb6d3770c1b5a
7
- data.tar.gz: d2c5824d177dc82351857efe565f151711f34034b8522bef1045224728b805c3e9645f4098a448458564f3417981eab3c354c6d61299d8a96cf97bf56fa4a776
6
+ metadata.gz: 570a7e4002cb5da3dcd49d6eb03c5554817036626c293faf3cbc2abc72063b83954e1c4795ad64a1b975ff6b8bca9d84b31a142914489777754ca5afb0d73cc0
7
+ data.tar.gz: 0bdfb434406fc6bb3b1dcc08562ca0507d3d58821306dafec68089248910cb4e325fb0dd3282f2424754980682d46595b8fae1e658a5e4636b680f1e9ce52fff
data/CHANGELOG.md CHANGED
@@ -1,8 +1,30 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.1.6
4
+
5
+ - Update default `window` `width` to `190`
6
+ - Improve layout of examples/meta_example.rb
7
+ - Enhance examples/meta_example.rb to enable choosing versions with a spinbox instead of adding them to examples list
8
+ - Nest control proxies under `Glimmer::LibUI::ControlProxy` namespace
9
+ - Nest shapes under `Glimmer::LibUI::Shape` namespace
10
+ - Nest `vertical_box` and `horizontal_box` under `Glimmer::LibUI::ControlProxy::Box` namespace
11
+ - Nest columns under `Glimmer::LibUI::ControlProxy::Column` namespace
12
+ - Nest menu item proxies under `Glimmer::LibUI::ControlProxy::MenuItemProxy` namespace
13
+ - Nest date time picker proxies under `Glimmer::LibUI::ControlProxy::DateTimePickerProxy` namespace
14
+ - Nest multiline entry proxies under `Glimmer::LibUI::ControlProxy::MultinlineEntryProxy` namespace
15
+ - Support `time_picker` control explicitly
16
+ - Support X11 color names (via [color](https://github.com/halostatue/color) gem)
17
+ - Support passing :red, :green, :blue, :alpha keys to fill/stroke (not just :r,:g,:b,:a)
18
+ - Support 3-number hex color shorthand
19
+ - Support ability to set fill/stroke to x11/Integer/String color directly (e.g. `fill 'steelblue'` , optionally with extra hash key/value pairs e.g. `fill 0x238232, a: 0.5`)
20
+ - Support ability to set color_button.color to {color: x11/Integer/String}
21
+ - Default main_window_proxy first argument for `msg_box`/`msg_box_error` (and empty strings for following args if not passed)
22
+ - Default main_window_proxy argument for `open_file` and `save_file`
23
+
3
24
  ## 0.1.5
4
25
 
5
26
  - Support examples/histogram.rb
27
+ - Support examples/basic_transform.rb
6
28
  - Support `color_button` `color=`/`set_color` setter
7
29
  - Switch `color_button` `color` API to return a hash of `{:r, :g, :b, :a}` instead of an array for consistency with other libui APIs (like fill and stroke brush)
8
30
  - Implement `color_button` fine-grained setters (e.g. `cg.red = 144`)
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.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.1.6
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)
@@ -143,7 +143,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
143
143
 
144
144
  ## Table of Contents
145
145
 
146
- - [Glimmer DSL for LibUI 0.1.4](#-glimmer-dsl-for-libui-014)
146
+ - [Glimmer DSL for LibUI 0.1.6](#-glimmer-dsl-for-libui-016)
147
147
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
148
148
  - [Usage](#usage)
149
149
  - [Girb (Glimmer IRB)](#girb-glimmer-irb)
@@ -249,10 +249,10 @@ require 'glimmer-dsl-libui'
249
249
 
250
250
  include Glimmer
251
251
 
252
- window('hello world', 300, 200) { |w|
252
+ window('hello world', 300, 200) {
253
253
  button('Button') {
254
254
  on_clicked do
255
- msg_box(w, 'Information', 'You clicked the button')
255
+ msg_box('Information', 'You clicked the button')
256
256
  end
257
257
  }
258
258
 
@@ -273,7 +273,7 @@ gem install glimmer-dsl-libui
273
273
  Or install via Bundler `Gemfile`:
274
274
 
275
275
  ```ruby
276
- gem 'glimmer-dsl-libui', '~> 0.1.4'
276
+ gem 'glimmer-dsl-libui', '~> 0.1.6'
277
277
  ```
278
278
 
279
279
  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.
@@ -378,8 +378,8 @@ Control(Args) | Properties | Listeners
378
378
  `menu(text as String)` | None | None
379
379
  `menu_item(text as String)` | `checked` (Boolean) | `on_clicked`
380
380
  `multiline_entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
381
- `msg_box(window as Glimmer::LibUI::WindowProxy, title as String, description as String)` | None | None
382
- `msg_box_error(window as Glimmer::LibUI::WindowProxy, title as String, description as String)` | None | None
381
+ `msg_box(window = main_window as Glimmer::LibUI::WindowProxy, title as String, description as String)` | None | None
382
+ `msg_box_error(window = main_window as Glimmer::LibUI::WindowProxy, title as String, description as String)` | None | None
383
383
  `non_wrapping_multiline_entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
384
384
  `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
385
385
  `preferences_menu_item` | None | `on_clicked`
@@ -395,7 +395,7 @@ Control(Args) | Properties | Listeners
395
395
  `tab_item(name as String)` | `index` [read-only] (`Integer`), `margined` (Boolean), `name` [read-only] (`String`) | None
396
396
  `table` | `cell_rows` (`Array` (rows) of `Arrays` (row columns) of cell values (e.g. `String` values for `text_column` cells or `Array` of `image`/`String` for `image_text_column`)), `editable` as Boolean | None
397
397
  `text_column(name as String)` | `editable` (Boolean) | None
398
- `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`
398
+ `time_picker` | `time` (`Hash` of keys: `sec` as `Integer`, `min` as `Integer`, `hour` as `Integer`) | `on_changed`
399
399
  `vertical_box` | `padded` (Boolean) | None
400
400
  `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`, `on_destroy`
401
401
 
@@ -606,6 +606,8 @@ The `area_draw_params` argument for `on_draw` block is a hash consisting of the
606
606
 
607
607
  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 dynamic paths that need maximum performance and low memory footprint.
608
608
 
609
+ Note that when nesting an `area` directly underneath `window` (without a layout control like `vertical_box`), it is automatically reparented with `vertical_box` in between the `window` and `area` since it would not show up on Linux otherwise.
610
+
609
611
  To redraw an `area`, you may call the `#queue_redraw_all` method, or simply `#redraw`.
610
612
 
611
613
  A transform `matrix` can be set on a path by building a `matrix(m11 = nil, m12 = nil, m21 = nil, m22 = nil, m31 = nil, m32 = nil) {operations}` proxy object and then setting via `transform` property, or alternatively by building and setting the matrix in one call to `transform(m11 = nil, m12 = nil, m21 = nil, m22 = nil, m31 = nil, m32 = nil) {operations}` passing it the matrix arguments and/or content operations.
@@ -638,7 +640,7 @@ window('Basic Transform', 350, 350) {
638
640
  square(0, 0, 100)
639
641
 
640
642
  fill r: [255 - n*5, 0].max, g: [n*5, 255].min, b: 0, a: 0.5
641
- stroke color: 0, thickness: 2
643
+ stroke :black, thickness: 2
642
644
  transform {
643
645
  skew 0.15, 0.15
644
646
  translate 50, 50
@@ -673,12 +675,18 @@ transform m1
673
675
 
674
676
  Note that `area`, `path`, and nested shapes are all truly declarative, meaning they do not care about the ordering of calls to `fill`, `stroke`, and `transform`. Furthermore, any transform that is applied is reversed at the end of the block, so you never have to worry about the ordering of `transform` calls among different paths. You simply set a transform on the `path`s that need it and it is guaranteed to be called before all its content is drawn, and then undone afterwards to avoid affecting later paths. Matrix `transform` can be set on an entire `area` too, applying to all nested `path`s.
675
677
 
678
+ `fill` and `stroke` accept [X11](https://en.wikipedia.org/wiki/X11_color_names) color `Symbol`s/`String`s like `:skyblue` and `'sandybrown'` or 6-number hex or 3-number hex-shorthand (as `Integer` or `String` with or without `0x` prefix)
679
+
680
+ Check [Basic Transform](#basic-transform) example for use of [X11](https://en.wikipedia.org/wiki/X11_color_names) colors.
681
+
682
+ Check [Histogram](#histogram) example for use of hex colors.
683
+
676
684
  ### Smart Defaults and Conventions
677
685
 
678
686
  - `horizontal_box`, `vertical_box`, `grid`, and `form` controls have `padded` as `true` upon instantiation to ensure more user-friendly GUI by default
679
687
  - `group` controls have `margined` as `true` upon instantiation to ensure more user-friendly GUI by default
680
688
  - All controls nested under a `horizontal_box`, `vertical_box`, and `form` have `stretchy` property (fill maximum space) as `true` by default (passed to `box_append`/`form_append` method)
681
- - `window` instatiation args can be left off, having the following defaults when unspecified: `title` as `''`, `width` as `150`, `height` as `150`, and `has_menubar` as `true`)
689
+ - `window` instatiation args can be left off, having the following defaults when unspecified: `title` as `''`, `width` as `190`, `height` as `150`, and `has_menubar` as `true`)
682
690
  - `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)
683
691
  - `group` has `title` property default to `''` if not specified in instantiation args, so it can be instantiated without args with `title` property specified in nested block (e.g. `group {title 'Address'; ...}`)
684
692
  - `button`, `checkbox`, and `label` have `text` default to `''` if not specified in instantiation args, so they can be instantiated without args with `text` property specified in nested block (e.g. `button {text 'Greet'; on_clicked {puts 'Hello'}}`)
@@ -706,6 +714,9 @@ Note that `area`, `path`, and nested shapes are all truly declarative, meaning t
706
714
  - Observe `path` `fill` and `stroke` hashes for changes and automatically redraw containing area accordingly
707
715
  - All controls are protected from garbage collection until no longer needed (explicitly destroyed), so there is no need to worry about surprises.
708
716
  - All resources are freed automatically once no longer needed or left to garbage collection.
717
+ - When nesting an `area` directly underneath `window` (without a layout control like `vertical_box`), it is automatically reparented with `vertical_box` in between the `window` and `area` since it would not show up on Linux otherwise.
718
+ - Colors may be passed in as a hash of `:r`, `:g`, `:b`, `:a`, or `:red`, `:green`, `:blue`, `:alpha`, or [X11](https://en.wikipedia.org/wiki/X11_color_names) color like `:skyblue`, or 6-number hex or 3-number hex (as `Integer` or `String` with or without `0x` prefix)
719
+ - Color alpha value defaults to `1.0` when not specified.
709
720
 
710
721
  ### API Gotchas
711
722
 
@@ -783,7 +794,7 @@ class MetaExample
783
794
  end
784
795
 
785
796
  def launch
786
- window('Meta-Example', 700, 500) { |w|
797
+ window('Meta-Example', 700, 500) {
787
798
  margined true
788
799
 
789
800
  horizontal_box {
@@ -805,7 +816,7 @@ class MetaExample
805
816
  meta_example_file = File.join(Dir.home, '.meta_example.rb')
806
817
  File.write(meta_example_file, @nwme.text)
807
818
  result = `ruby -r #{glimmer_dsl_libui_file} #{meta_example_file} 2>&1`
808
- msg_box(w, 'Error Running Example', result) if result.include?('error')
819
+ msg_box('Error Running Example', result) if result.include?('error')
809
820
  rescue => e
810
821
  puts 'Unable to write code changes! Running original example...'
811
822
  system "ruby -r #{glimmer_dsl_libui_file} #{file_path_for(@examples[@rbs.selected])}"
@@ -970,10 +981,10 @@ require 'glimmer-dsl-libui'
970
981
 
971
982
  include Glimmer
972
983
 
973
- window('hello world', 300, 200) { |w|
984
+ window('hello world', 300, 200) {
974
985
  button('Button') {
975
986
  on_clicked do
976
- msg_box(w, 'Information', 'You clicked the button')
987
+ msg_box('Information', 'You clicked the button')
977
988
  end
978
989
  }
979
990
 
@@ -1057,7 +1068,7 @@ require 'glimmer-dsl-libui'
1057
1068
 
1058
1069
  include Glimmer
1059
1070
 
1060
- window('Basic Entry', 300, 50) { |w|
1071
+ window('Basic Entry', 300, 50) {
1061
1072
  horizontal_box {
1062
1073
  e = entry {
1063
1074
  # stretchy true # Smart default option for appending to horizontal_box
@@ -1073,7 +1084,7 @@ window('Basic Entry', 300, 50) { |w|
1073
1084
 
1074
1085
  on_clicked do
1075
1086
  text = e.text
1076
- msg_box(w, 'You entered', text)
1087
+ msg_box('You entered', text)
1077
1088
  end
1078
1089
  }
1079
1090
  }
@@ -1177,12 +1188,12 @@ ruby -r glimmer-dsl-libui -e "require 'examples/midi_player'"
1177
1188
  Mac
1178
1189
 
1179
1190
  ![glimmer-dsl-libui-mac-midi-player.png](images/glimmer-dsl-libui-mac-midi-player.png)
1180
- ![glimmer-dsl-libui-mac-midi-player-version-msg-box.png](images/glimmer-dsl-libui-mac-midi-player-version-msg-box.png)
1191
+ ![glimmer-dsl-libui-mac-midi-player-msg-box.png](images/glimmer-dsl-libui-mac-midi-player-msg-box.png)
1181
1192
 
1182
1193
  Linux
1183
1194
 
1184
1195
  ![glimmer-dsl-libui-linux-midi-player.png](images/glimmer-dsl-libui-linux-midi-player.png)
1185
- ![glimmer-dsl-libui-linux-midi-player-version-msg-box.png](images/glimmer-dsl-libui-linux-midi-player-version-msg-box.png)
1196
+ ![glimmer-dsl-libui-linux-midi-player-msg-box.png](images/glimmer-dsl-libui-linux-midi-player-msg-box.png)
1186
1197
 
1187
1198
  [LibUI](https://github.com/kojix2/LibUI) Original Version:
1188
1199
 
@@ -1328,23 +1339,22 @@ class TinyMidiPlayer
1328
1339
  end
1329
1340
  end
1330
1341
 
1331
- def show_version(main_window)
1332
- msg_box(main_window,
1333
- 'Tiny Midi Player',
1334
- "Written in Ruby\n" \
1335
- "https://github.com/kojix2/libui\n" \
1336
- "Version #{VERSION}")
1342
+ def show_version
1343
+ msg_box('Tiny Midi Player',
1344
+ "Written in Ruby\n" \
1345
+ "https://github.com/kojix2/libui\n" \
1346
+ "Version #{VERSION}")
1337
1347
  end
1338
1348
 
1339
1349
  def create_gui
1340
1350
  menu('Help') { |m|
1341
1351
  menu_item('Version') {
1342
1352
  on_clicked do
1343
- show_version(@main_window)
1353
+ show_version
1344
1354
  end
1345
1355
  }
1346
1356
  }
1347
- @main_window = window('Tiny Midi Player', 200, 50) {
1357
+ window('Tiny Midi Player', 200, 50) {
1348
1358
  horizontal_box {
1349
1359
  vertical_box {
1350
1360
  stretchy false
@@ -1360,7 +1370,7 @@ class TinyMidiPlayer
1360
1370
  end
1361
1371
  }
1362
1372
  }
1363
-
1373
+
1364
1374
  combobox { |c|
1365
1375
  items @midi_files.map { |path| File.basename(path) }
1366
1376
 
@@ -1370,8 +1380,7 @@ class TinyMidiPlayer
1370
1380
  end
1371
1381
  }
1372
1382
  }
1373
- }
1374
- @main_window.show
1383
+ }.show
1375
1384
  end
1376
1385
  end
1377
1386
 
@@ -1607,14 +1616,14 @@ include Glimmer
1607
1616
  menu('File') {
1608
1617
  menu_item('Open') {
1609
1618
  on_clicked do
1610
- file = open_file(MAIN_WINDOW)
1619
+ file = open_file
1611
1620
  puts file unless file.nil?
1612
1621
  end
1613
1622
  }
1614
1623
 
1615
1624
  menu_item('Save') {
1616
1625
  on_clicked do
1617
- file = save_file(MAIN_WINDOW)
1626
+ file = save_file
1618
1627
  puts file unless file.nil?
1619
1628
  end
1620
1629
  }
@@ -1657,7 +1666,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500) {
1657
1666
  stretchy false
1658
1667
 
1659
1668
  on_clicked do
1660
- msg_box(MAIN_WINDOW, 'Information', 'You clicked the button')
1669
+ msg_box('Information', 'You clicked the button')
1661
1670
  end
1662
1671
  }
1663
1672
 
@@ -1665,7 +1674,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500) {
1665
1674
  stretchy false
1666
1675
 
1667
1676
  on_toggled do |c|
1668
- checked = c.checked == 1
1677
+ checked = c.checked?
1669
1678
  MAIN_WINDOW.title = "Checkbox is #{checked}"
1670
1679
  c.text = "I am the checkbox (#{checked})"
1671
1680
  end
@@ -2119,7 +2128,7 @@ require 'glimmer-dsl-libui'
2119
2128
 
2120
2129
  include Glimmer
2121
2130
 
2122
- window('Form') { |w|
2131
+ window('Form') {
2123
2132
  margined true
2124
2133
 
2125
2134
  vertical_box {
@@ -2135,7 +2144,7 @@ window('Form') { |w|
2135
2144
 
2136
2145
  button('Display Name') {
2137
2146
  on_clicked do
2138
- msg_box(w, 'Name', "#{@first_name_entry.text} #{@last_name_entry.text}")
2147
+ msg_box('Name', "#{@first_name_entry.text} #{@last_name_entry.text}")
2139
2148
  end
2140
2149
  }
2141
2150
  }
@@ -3893,31 +3902,29 @@ Y_OFF_TOP = 20
3893
3902
  X_OFF_RIGHT = 20
3894
3903
  Y_OFF_BOTTOM = 20
3895
3904
  POINT_RADIUS = 5
3896
-
3897
3905
  COLOR_BLUE = 0x1E90FF
3898
3906
 
3907
+ @datapoints = 10.times.map {Random.new.rand(90)}
3908
+
3899
3909
  def graph_size(area_width, area_height)
3900
3910
  graph_width = area_width - X_OFF_LEFT - X_OFF_RIGHT
3901
3911
  graph_height = area_height - Y_OFF_TOP - Y_OFF_BOTTOM
3902
3912
  [graph_width, graph_height]
3903
3913
  end
3904
3914
 
3905
- def point_locations(datapoints, width, height)
3915
+ def point_locations(width, height)
3906
3916
  xincr = width / 9.0 # 10 - 1 to make the last point be at the end
3907
3917
  yincr = height / 100.0
3908
3918
 
3909
- data = []
3910
- datapoints.each_with_index do |dp, i|
3911
- val = 100 - dp.value
3912
- data << [xincr * i, yincr * val]
3913
- i += 1
3919
+ @datapoints.each_with_index.map do |value, i|
3920
+ val = 100 - value
3921
+ [xincr * i, yincr * val]
3914
3922
  end
3915
-
3916
- data
3917
3923
  end
3918
3924
 
3919
- def graph_path(datapoints, width, height, should_extend, &block)
3920
- locations = point_locations(datapoints, width, height)
3925
+ # method-based custom control representing a graph path
3926
+ def graph_path(width, height, should_extend, &block)
3927
+ locations = point_locations(width, height)
3921
3928
  path {
3922
3929
  first_location = locations[0] # x and y
3923
3930
  figure(first_location[0], first_location[1]) {
@@ -3932,7 +3939,7 @@ def graph_path(datapoints, width, height, should_extend, &block)
3932
3939
  end
3933
3940
  }
3934
3941
 
3935
- # now transform the coordinate space so (0, 0) is the top-left corner of the graph
3942
+ # apply a transform to the coordinate space for this path so (0, 0) is the top-left corner of the graph
3936
3943
  transform {
3937
3944
  translate X_OFF_LEFT, Y_OFF_TOP
3938
3945
  }
@@ -3948,12 +3955,13 @@ window('histogram example', 640, 480) {
3948
3955
  vertical_box {
3949
3956
  stretchy false
3950
3957
 
3951
- @datapoints = 10.times.map do
3952
- spinbox(0, 100) { |datapoint|
3958
+ 10.times do |i|
3959
+ spinbox(0, 100) { |sb|
3953
3960
  stretchy false
3954
- value Random.new.rand(90)
3961
+ value @datapoints[i]
3955
3962
 
3956
3963
  on_changed do
3964
+ @datapoints[i] = sb.value
3957
3965
  @area.queue_redraw_all
3958
3966
  end
3959
3967
  }
@@ -3974,7 +3982,7 @@ window('histogram example', 640, 480) {
3974
3982
  path {
3975
3983
  rectangle(0, 0, area_draw_params[:area_width], area_draw_params[:area_height])
3976
3984
 
3977
- fill color: 0xFFFFFF
3985
+ fill 0xFFFFFF
3978
3986
  }
3979
3987
 
3980
3988
  graph_width, graph_height = *graph_size(area_draw_params[:area_width], area_draw_params[:area_height])
@@ -3985,16 +3993,16 @@ window('histogram example', 640, 480) {
3985
3993
  line(X_OFF_LEFT + graph_width, Y_OFF_TOP + graph_height)
3986
3994
  }
3987
3995
 
3988
- stroke color: 0x000000, thickness: 2, miter_limit: 10
3996
+ stroke 0x000000, thickness: 2, miter_limit: 10
3989
3997
  }
3990
3998
 
3991
3999
  # now create the fill for the graph below the graph line
3992
- graph_path(@datapoints, graph_width, graph_height, true) {
4000
+ graph_path(graph_width, graph_height, true) {
3993
4001
  fill @color_button.color.merge(a: 0.5)
3994
4002
  }
3995
4003
 
3996
4004
  # now draw the histogram line
3997
- graph_path(@datapoints, graph_width, graph_height, false) {
4005
+ graph_path(graph_width, graph_height, false) {
3998
4006
  stroke @color_button.color.merge(thickness: 2, miter_limit: 10)
3999
4007
  }
4000
4008
  end
@@ -4046,7 +4054,7 @@ window('Basic Transform', 350, 350) {
4046
4054
  square(0, 0, 100)
4047
4055
 
4048
4056
  fill r: [255 - n*5, 0].max, g: [n*5, 255].min, b: 0, a: 0.5
4049
- stroke color: 0, thickness: 2
4057
+ stroke :black, thickness: 2
4050
4058
  transform {
4051
4059
  skew 0.15, 0.15
4052
4060
  translate 50, 50
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
@@ -4,10 +4,10 @@ require 'glimmer-dsl-libui'
4
4
 
5
5
  include Glimmer
6
6
 
7
- window('hello world', 300, 200) { |w|
7
+ window('hello world', 300, 200) {
8
8
  button('Button') {
9
9
  on_clicked do
10
- msg_box(w, 'Information', 'You clicked the button')
10
+ msg_box('Information', 'You clicked the button')
11
11
  end
12
12
  }
13
13
 
@@ -4,7 +4,7 @@ require 'glimmer-dsl-libui'
4
4
 
5
5
  include Glimmer
6
6
 
7
- window('Basic Entry', 300, 50) { |w|
7
+ window('Basic Entry', 300, 50) {
8
8
  horizontal_box {
9
9
  e = entry {
10
10
  # stretchy true # Smart default option for appending to horizontal_box
@@ -20,7 +20,7 @@ window('Basic Entry', 300, 50) { |w|
20
20
 
21
21
  on_clicked do
22
22
  text = e.text
23
- msg_box(w, 'You entered', text)
23
+ msg_box('You entered', text)
24
24
  end
25
25
  }
26
26
  }
@@ -14,7 +14,7 @@ window('Basic Transform', 350, 350) {
14
14
  square(0, 0, 100)
15
15
 
16
16
  fill r: [255 - n*5, 0].max, g: [n*5, 255].min, b: 0, a: 0.5
17
- stroke color: 0, thickness: 2
17
+ stroke :black, thickness: 2
18
18
  transform {
19
19
  skew 0.15, 0.15
20
20
  translate 50, 50
@@ -7,14 +7,14 @@ include Glimmer
7
7
  menu('File') {
8
8
  menu_item('Open') {
9
9
  on_clicked do
10
- file = open_file(MAIN_WINDOW)
10
+ file = open_file
11
11
  puts file unless file.nil?
12
12
  end
13
13
  }
14
14
 
15
15
  menu_item('Save') {
16
16
  on_clicked do
17
- file = save_file(MAIN_WINDOW)
17
+ file = save_file
18
18
  puts file unless file.nil?
19
19
  end
20
20
  }
@@ -57,7 +57,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500) {
57
57
  stretchy false
58
58
 
59
59
  on_clicked do
60
- msg_box(MAIN_WINDOW, 'Information', 'You clicked the button')
60
+ msg_box('Information', 'You clicked the button')
61
61
  end
62
62
  }
63
63
 
data/examples/form.rb CHANGED
@@ -4,7 +4,7 @@ require 'glimmer-dsl-libui'
4
4
 
5
5
  include Glimmer
6
6
 
7
- window('Form') { |w|
7
+ window('Form') {
8
8
  margined true
9
9
 
10
10
  vertical_box {
@@ -20,7 +20,7 @@ window('Form') { |w|
20
20
 
21
21
  button('Display Name') {
22
22
  on_clicked do
23
- msg_box(w, 'Name', "#{@first_name_entry.text} #{@last_name_entry.text}")
23
+ msg_box('Name', "#{@first_name_entry.text} #{@last_name_entry.text}")
24
24
  end
25
25
  }
26
26
  }
@@ -9,31 +9,29 @@ Y_OFF_TOP = 20
9
9
  X_OFF_RIGHT = 20
10
10
  Y_OFF_BOTTOM = 20
11
11
  POINT_RADIUS = 5
12
-
13
12
  COLOR_BLUE = 0x1E90FF
14
13
 
14
+ @datapoints = 10.times.map {Random.new.rand(90)}
15
+
15
16
  def graph_size(area_width, area_height)
16
17
  graph_width = area_width - X_OFF_LEFT - X_OFF_RIGHT
17
18
  graph_height = area_height - Y_OFF_TOP - Y_OFF_BOTTOM
18
19
  [graph_width, graph_height]
19
20
  end
20
21
 
21
- def point_locations(datapoints, width, height)
22
+ def point_locations(width, height)
22
23
  xincr = width / 9.0 # 10 - 1 to make the last point be at the end
23
24
  yincr = height / 100.0
24
25
 
25
- data = []
26
- datapoints.each_with_index do |dp, i|
27
- val = 100 - dp.value
28
- data << [xincr * i, yincr * val]
29
- i += 1
26
+ @datapoints.each_with_index.map do |value, i|
27
+ val = 100 - value
28
+ [xincr * i, yincr * val]
30
29
  end
31
-
32
- data
33
30
  end
34
31
 
35
- def graph_path(datapoints, width, height, should_extend, &block)
36
- locations = point_locations(datapoints, width, height)
32
+ # method-based custom control representing a graph path
33
+ def graph_path(width, height, should_extend, &block)
34
+ locations = point_locations(width, height)
37
35
  path {
38
36
  first_location = locations[0] # x and y
39
37
  figure(first_location[0], first_location[1]) {
@@ -48,7 +46,7 @@ def graph_path(datapoints, width, height, should_extend, &block)
48
46
  end
49
47
  }
50
48
 
51
- # now transform the coordinate space so (0, 0) is the top-left corner of the graph
49
+ # apply a transform to the coordinate space for this path so (0, 0) is the top-left corner of the graph
52
50
  transform {
53
51
  translate X_OFF_LEFT, Y_OFF_TOP
54
52
  }
@@ -64,12 +62,13 @@ window('histogram example', 640, 480) {
64
62
  vertical_box {
65
63
  stretchy false
66
64
 
67
- @datapoints = 10.times.map do
68
- spinbox(0, 100) { |datapoint|
65
+ 10.times do |i|
66
+ spinbox(0, 100) { |sb|
69
67
  stretchy false
70
- value Random.new.rand(90)
68
+ value @datapoints[i]
71
69
 
72
70
  on_changed do
71
+ @datapoints[i] = sb.value
73
72
  @area.queue_redraw_all
74
73
  end
75
74
  }
@@ -90,7 +89,7 @@ window('histogram example', 640, 480) {
90
89
  path {
91
90
  rectangle(0, 0, area_draw_params[:area_width], area_draw_params[:area_height])
92
91
 
93
- fill color: 0xFFFFFF
92
+ fill 0xFFFFFF
94
93
  }
95
94
 
96
95
  graph_width, graph_height = *graph_size(area_draw_params[:area_width], area_draw_params[:area_height])
@@ -101,16 +100,16 @@ window('histogram example', 640, 480) {
101
100
  line(X_OFF_LEFT + graph_width, Y_OFF_TOP + graph_height)
102
101
  }
103
102
 
104
- stroke color: 0x000000, thickness: 2, miter_limit: 10
103
+ stroke 0x000000, thickness: 2, miter_limit: 10
105
104
  }
106
105
 
107
106
  # now create the fill for the graph below the graph line
108
- graph_path(@datapoints, graph_width, graph_height, true) {
107
+ graph_path(graph_width, graph_height, true) {
109
108
  fill @color_button.color.merge(a: 0.5)
110
109
  }
111
110
 
112
111
  # now draw the histogram line
113
- graph_path(@datapoints, graph_width, graph_height, false) {
112
+ graph_path(graph_width, graph_height, false) {
114
113
  stroke @color_button.color.merge(thickness: 2, miter_limit: 10)
115
114
  }
116
115
  end