glimmer-dsl-libui 0.4.15 → 0.4.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/README.md +135 -64
  4. data/VERSION +1 -1
  5. data/examples/basic_table.rb +1 -1
  6. data/examples/basic_table_button.rb +0 -1
  7. data/examples/cpu_percentage.rb +1 -1
  8. data/examples/custom_draw_text.rb +14 -7
  9. data/examples/custom_draw_text2.rb +15 -8
  10. data/examples/method_based_custom_keyword.rb +9 -9
  11. data/examples/method_based_custom_keyword2.rb +9 -9
  12. data/glimmer-dsl-libui.gemspec +0 -0
  13. data/icons/blank.png +0 -0
  14. data/lib/glimmer/dsl/libui/dsl.rb +1 -0
  15. data/lib/glimmer/dsl/libui/observe_expression.rb +1 -1
  16. data/lib/glimmer/dsl/libui/operation_expression.rb +47 -0
  17. data/lib/glimmer/dsl/libui/property_expression.rb +2 -2
  18. data/lib/glimmer/libui/control_proxy/column/background_color_column_proxy.rb +6 -0
  19. data/lib/glimmer/libui/control_proxy/column/button_column_proxy.rb +6 -0
  20. data/lib/glimmer/libui/control_proxy/column/checkbox_column_proxy.rb +6 -0
  21. data/lib/glimmer/libui/control_proxy/column/checkbox_text_color_column_proxy.rb +6 -0
  22. data/lib/glimmer/libui/control_proxy/column/checkbox_text_column_proxy.rb +6 -0
  23. data/lib/glimmer/libui/control_proxy/column/image_column_proxy.rb +6 -0
  24. data/lib/glimmer/libui/control_proxy/column/image_text_color_column_proxy.rb +6 -0
  25. data/lib/glimmer/libui/control_proxy/column/image_text_column_proxy.rb +6 -0
  26. data/lib/glimmer/libui/control_proxy/column/progress_bar_column_proxy.rb +6 -0
  27. data/lib/glimmer/libui/control_proxy/column/text_color_column_proxy.rb +6 -0
  28. data/lib/glimmer/libui/control_proxy/column/text_column_proxy.rb +6 -0
  29. data/lib/glimmer/libui/control_proxy/column.rb +7 -0
  30. data/lib/glimmer/libui/control_proxy/image_proxy.rb +1 -0
  31. data/lib/glimmer/libui/control_proxy/menu_item_proxy/quit_menu_item_proxy.rb +0 -1
  32. data/lib/glimmer/libui/control_proxy/path_proxy.rb +6 -4
  33. data/lib/glimmer/libui/control_proxy/table_proxy.rb +56 -31
  34. data/lib/glimmer/libui/data_bindable.rb +1 -1
  35. data/lib/glimmer/libui/shape/bezier.rb +20 -3
  36. data/lib/glimmer/libui/shape/line.rb +23 -3
  37. data/lib/glimmer/libui.rb +1 -0
  38. data/lib/glimmer-dsl-libui.rb +6 -0
  39. metadata +22 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34cb8eb1da8d200b96163b3e2a0a607ed32dda75cb0df62088c5fcfaad2e2b18
4
- data.tar.gz: 169bb5a5d620cc28606cdb03a7cd1e19544ae14d7c5d11dd2704cca869e3a2fe
3
+ metadata.gz: da444c365d1e7febf1868c1cc63e1d3714eca5e1c3340b0e4694c74e8427f458
4
+ data.tar.gz: ad68dbc1451dd6b3dc388657b25f8039418fc333ce3876b55e878109a43f88d5
5
5
  SHA512:
6
- metadata.gz: b00b7729fcc0635faa743f9310d048a132d679d1550033302ee39b13dedd5d5f9e4ab79e5673b2cfceb2d887d87f33c24774a3b5d4f0b2bbfdfd8e366844acb2
7
- data.tar.gz: c879ccd0d7f27b08080905669bff25543673e9117d44650dd31a57674596cf09aee3034a49b8af8c73f7976c1143ec0a8f7892a77252eb945318fafcc6f49da2
6
+ metadata.gz: b8cb2a4b292b10b35a3a058a23af3e5ca7b37bcbf968d498a831b5e40d0d9896fcf0fad428f8857eae0e59785b979e039d0d62cab1a1c83aeb4c8028ed208aff
7
+ data.tar.gz: 11314401a9da405b96055351321088352cb6503abe74d9d75280c4350266b8aa11772380cdac691609c4499e18d12c2da9d7ee789eb3f72f592b3d09af1888b8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.4.19
4
+
5
+ - Have `line` optionally support 4 arguments instead of 2 to use outside of a `figure`
6
+ - Have `bezier` optionally support 8 arguments instead of 6 to use outside of a `figure`
7
+ - Minor fix to `observe` keyword code (had the wrong DSL name)
8
+
9
+ ## 0.4.18
10
+
11
+ - Support setting `table` `cell_rows` after the `table` definition completed (e.g. `@table.cell_rows = data` after `table {}` curly braces closed already)
12
+ - Support adding to `table` `cell_rows` piecemeal after the `table` definition completed (e.g. `data.each { |row| @table.cell_rows << row }` after `table {}` curly braces closed already)
13
+ - Support notifying observers of control property changes when calling the `set_attribute` version of attribute writers, not just `attribute=`
14
+ - Hide background field in examples/custom_draw_text.rb on Windows since it is not supported there
15
+ - Fix issue with `quit_menu_item` click resulting in a stack overflow on Windows
16
+
17
+ ## 0.4.17
18
+
19
+ - Remove Windows workaround of always adding an extra row at the bottom of `table` as it is no longer necessary after adding a better workaround (on Windows, add & remove row just after constructing `table` to get rid of double-delete glitch)
20
+ - Improved parsing code of examples/cpu_percentage.rb for Windows to make it more resilient
21
+ - Upgrade to glimmer 2.5.3 to silently ignore frozen observables with `observe(*args, ignore_frozen: true)`
22
+ - Added equalizer gem dependency to properly provide equality methods for `Glimmer::LibUI::ControlProxy::ImageProxy`
23
+
24
+ ## 0.4.16
25
+
26
+ - Upgrade to glimmer 2.5.1
27
+ - Fix issue on Windows with `table` having image column crashing when empty
28
+
3
29
  ## 0.4.15
4
30
 
5
31
  - Support ability to attach multiple listeners on a control (e.g. multiple `on_changed {}` on `entry` or multiple `on_clicked` on `button`)
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.4.15
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.4.19
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
  [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@@ -506,7 +506,7 @@ gem install glimmer-dsl-libui
506
506
  Or install via Bundler `Gemfile`:
507
507
 
508
508
  ```ruby
509
- gem 'glimmer-dsl-libui', '~> 0.4.15'
509
+ gem 'glimmer-dsl-libui', '~> 0.4.19'
510
510
  ```
511
511
 
512
512
  Test that installation worked by running the [Meta-Example](#examples):
@@ -595,7 +595,7 @@ Keyword(Args) | Properties | Listeners
595
595
  `area` | `auto_draw_enabled` | `on_draw(area_draw_params)`, `on_mouse_event(area_mouse_event)`, `on_mouse_down(area_mouse_event)`, `on_mouse_up(area_mouse_event)`, `on_mouse_drag_started(area_mouse_event)`, `on_mouse_dragged(area_mouse_event)`, `on_mouse_dropped(area_mouse_event)`, `on_mouse_entered`, `on_mouse_exited`, `on_key_event(area_key_event)`, `on_key_down(area_key_event)`, `on_key_up(area_key_event)`
596
596
  `arc(x_center as Numeric, y_center as Numeric, radius as Numeric, start_angle as Numeric, sweep as Numeric, is_negative as Boolean)` | `x_center` (`Numeric`), `y_center` (`Numeric`), `radius` (`Numeric`), `start_angle` (`Numeric`), `sweep` (`Numeric`), `is_negative` (Boolean) | None
597
597
  `background_color_column` | None | None
598
- `bezier(c1_x as Numeric, c1_y as Numeric, c2_x as Numeric, c2_y as Numeric, end_x as Numeric, end_y as Numeric)` | `c1_x` (`Numeric`), `c1_y` (`Numeric`), `c2_x` (`Numeric`), `c2_y` (`Numeric`), `end_x` (`Numeric`), `end_y` (`Numeric`) | None
598
+ `bezier(x = nil as Numeric, y = nil as Numeric, c1_x as Numeric, c1_y as Numeric, c2_x as Numeric, c2_y as Numeric, end_x as Numeric, end_y as Numeric)` | `x` (`Numeric`), `y` (`Numeric`), `c1_x` (`Numeric`), `c1_y` (`Numeric`), `c2_x` (`Numeric`), `c2_y` (`Numeric`), `end_x` (`Numeric`), `end_y` (`Numeric`) | None
599
599
  `button(text as String)` | `text` (`String`) | `on_clicked`
600
600
  `button_column(name as String)` | `enabled` (Boolean) | None
601
601
  `checkbox(text as String)` | `checked` (Boolean), `text` (`String`) | `on_toggled`
@@ -622,7 +622,7 @@ Keyword(Args) | Properties | Listeners
622
622
  `image_text_column(name as String)` | None | None
623
623
  `image_text_color_column(name as String)` | None | None
624
624
  `label(text as String)` | `text` (`String`) | None
625
- `line(x as Numeric, y as Numeric)` | `x` (`Numeric`), `y` (`Numeric`) | None
625
+ `line(x as Numeric, y as Numeric, end_x = nil as Numeric, end_y = nil as Numeric)` | `x` (`Numeric`), `y` (`Numeric`), `end_x` (`Numeric`), `end_y` (`Numeric`) | None
626
626
  `matrix(m11 = nil as Numeric, m12 = nil as Numeric, m21 = nil as Numeric, m22 = nil as Numeric, m31 = nil as Numeric, m32 = nil as Numeric)` | `m11` (`Numeric`), `m12` (`Numeric`), `m21` (`Numeric`), `m22` (`Numeric`), `m31` (`Numeric`), `m32` (`Numeric`) | None
627
627
  `menu(text as String)` | None | None
628
628
  `menu_item(text as String)` | None | `on_clicked`
@@ -958,8 +958,8 @@ Available `path` shapes (that can be nested explicitly under `path` or implicitl
958
958
  - `square(x as Numeric, y as Numeric, length as Numeric)`
959
959
  - `arc(x_center as Numeric, y_center as Numeric, radius as Numeric, start_angle as Numeric, sweep as Numeric, is_negative as Boolean)`
960
960
  - `circle(x_center as Numeric, y_center as Numeric, radius as Numeric)`
961
- - `line(x as Numeric, y as Numeric)`: must be placed in a figure (check `polyline`/`polygon` alternatives that do not require a `figure`)
962
- - `bezier(c1_x as Numeric, c1_y as Numeric, c2_x as Numeric, c2_y as Numeric, end_x as Numeric, end_y as Numeric)`: must be placed in a figure (check `polybezier` alternative that does not require a `figure`)
961
+ - `line(x as Numeric, y as Numeric, end_x = nil as Numeric, end_y = nil as Numeric)`: must be placed in a `figure` if only `x`/`y` are specified or have `end_x`/`end_y` otherwise if outside of `figure` (check `polyline`/`polygon` alternatives that do not require a `figure`)
962
+ - `bezier(x = nil as Numeric, y = nil as Numeric, c1_x as Numeric, c1_y as Numeric, c2_x as Numeric, c2_y as Numeric, end_x as Numeric, end_y as Numeric)`: must be placed in a `figure` if `x`/`y` are not specified or have `x`/`y` as start point otherwise if outside of `figure` (check `polybezier` alternative that does not require a `figure`)
963
963
  - `polygon(point_array as Array of Arrays of Numeric or Array of Numeric)`: shortcut for a closed figure of lines; can receive points as [[x1, y1], [x2, y2], ...] or [x1, y1, x2, y2, ...]
964
964
  - `polyline(point_array as Array of Arrays of Numeric or Array of Numeric)`: shortcut for an open figure of lines; can receive points as [[x1, y1], [x2, y2], ...] or [x1, y1, x2, y2, ...]
965
965
  - `polybezier(point_array as Array of Arrays of Numeric or Array of Numeric)`: shortcut for an open figure of beziers; can receive points as [[start_x1, start_y1], [c1_x2, c1_y2, c2_x2, c2_y2, end_x2, end_y2], [c1_x3, c1_y3, c2_x3, c2_y3, end_x3, end_y3], ...] or [start_x1, start_y1, c1_x2, c1_y2, c2_x2, c2_y2, end_x2, end_y2, c1_x3, c1_y3, c2_x3, c2_y3, end_x3, end_y3, ...]
@@ -1384,6 +1384,7 @@ Note that `area`, `path`, and nested shapes are all truly declarative, meaning t
1384
1384
  - `scrolling_area` `#scroll_to` 3rd and 4th arguments (`width` and `height`) default to main window width and height if not specified.
1385
1385
  - `area` paths are specified declaratively with shapes/figures underneath (e.g. `rectangle`), and `area` draw listener is automatically generated
1386
1386
  - `area` path shapes can be added directly under `area` without declaring `path` explicitly as a convenient shorthand
1387
+ - `line` and `bezier` automatically start a new figure if placed outside of `figure`
1387
1388
  - Observe figure properties (e.g. `rectangle` `width`) for changes and automatically redraw containing area accordingly
1388
1389
  - Observe `path` `fill` and `stroke` hashes for changes and automatically redraw containing area accordingly
1389
1390
  - Observe `text` and `string` properties for changes and automatically redraw containing area accordingly
@@ -1395,7 +1396,13 @@ Note that `area`, `path`, and nested shapes are all truly declarative, meaning t
1395
1396
 
1396
1397
  ### Custom Keywords
1397
1398
 
1398
- To define custom keywords, simply define a method representing the custom control you want. To make reusable, you can define in modules and simply include the modules in the view classes that need them.
1399
+ Custom keywords can be defined to represent custom controls (components) that provide new features or act as composites of [existing controls](#supported-keywords) that need to be reused multiple times in an application or across multiple applications. Custom keywords save a lot of development time, improving productivity and maintainbility.
1400
+
1401
+ For example, you can define a custom `address` control as an aggregate of multiple `label` controls to reuse multiple times as a standard address View, displaying street, city, state, and zip code.
1402
+
1403
+ To define custom keywords, simply define a method representing the custom control you want (e.g. `address`) with any arguments needed (e.g. `address(address_model)`).
1404
+
1405
+ To make custom keywords externally reusable, you can define in modules and simply include the modules in the view classes that need them.
1399
1406
 
1400
1407
  Example that defines `form_field`, `address_form`, `label_pair`, and `address` keywords (you may copy/paste in [`girb`](#girb-glimmer-irb)):
1401
1408
 
@@ -1407,44 +1414,37 @@ include Glimmer
1407
1414
 
1408
1415
  Address = Struct.new(:street, :p_o_box, :city, :state, :zip_code)
1409
1416
 
1410
- def form_field(model, property)
1411
- property = property.to_s
1417
+ def form_field(model, attribute)
1418
+ attribute = attribute.to_s
1412
1419
  entry { |e|
1413
- label property.underscore.split('_').map(&:capitalize).join(' ')
1414
- text model.send(property).to_s
1415
-
1416
- on_changed do
1417
- model.send("#{property}=", e.text)
1418
- end
1420
+ label attribute.underscore.split('_').map(&:capitalize).join(' ')
1421
+ text <=> [model, attribute]
1419
1422
  }
1420
1423
  end
1421
1424
 
1422
- def address_form(address)
1425
+ def address_form(address_model)
1423
1426
  form {
1424
- form_field(address, :street)
1425
- form_field(address, :p_o_box)
1426
- form_field(address, :city)
1427
- form_field(address, :state)
1428
- form_field(address, :zip_code)
1427
+ form_field(address_model, :street)
1428
+ form_field(address_model, :p_o_box)
1429
+ form_field(address_model, :city)
1430
+ form_field(address_model, :state)
1431
+ form_field(address_model, :zip_code)
1429
1432
  }
1430
1433
  end
1431
1434
 
1432
1435
  def label_pair(model, attribute, value)
1433
- name_label = nil
1434
- value_label = nil
1435
1436
  horizontal_box {
1436
- name_label = label(attribute.to_s.underscore.split('_').map(&:capitalize).join(' '))
1437
- value_label = label(value.to_s)
1437
+ label(attribute.to_s.underscore.split('_').map(&:capitalize).join(' '))
1438
+ label(value.to_s) {
1439
+ text <= [model, attribute]
1440
+ }
1438
1441
  }
1439
- Glimmer::DataBinding::Observer.proc do
1440
- value_label.text = model.send(attribute)
1441
- end.observe(model, attribute)
1442
1442
  end
1443
1443
 
1444
- def address(address)
1444
+ def address(address_model)
1445
1445
  vertical_box {
1446
- address.each_pair do |attribute, value|
1447
- label_pair(address, attribute, value)
1446
+ address_model.each_pair do |attribute, value|
1447
+ label_pair(address_model, attribute, value)
1448
1448
  end
1449
1449
  }
1450
1450
  end
@@ -1501,6 +1501,12 @@ window('Method-Based Custom Keyword') {
1501
1501
 
1502
1502
  ![glimmer-dsl-libui-mac-method-based-custom-keyword.png](images/glimmer-dsl-libui-mac-method-based-custom-keyword.png)
1503
1503
 
1504
+ The [`area`](#area-api) control can be utilized to build non-native custom controls from scratch by leveraging vector graphics, formattable text, keyboard events, and mouse events.
1505
+
1506
+ Defining custom keywords enables unlimited extension of the [Glimmer GUI DSL](#glimmer-gui-dsl). The sky is the limit on what can be done with custom keywords as a result. You can compose new visual vocabulary to build applications in any domain from higher concepts rather than [mere standard controls](#supported-keywords). For example, in a traffic signaling app, you could define `street`, `light_signal`, `traffic_sign`, and `car` as custom keywords and build your application from these concepts directly, saving enormous time and achieving much higher productivity.
1507
+
1508
+ Learn more from custom keyword usage in [Method-Based Custom Keyword](#method-based-custom-keyword), [Histogram](#histogram), and [Tetris](#tetris) examples.
1509
+
1504
1510
  ### Observer Pattern
1505
1511
 
1506
1512
  The [Observer Design Pattern](https://en.wikipedia.org/wiki/Observer_pattern) (a.k.a. Observer Pattern) is fundamental to building GUIs (Graphical User Interfaces) following the [MVC (Model View Controller) Architectural Pattern](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) or any of its variations like [MVP (Model View Presenter)](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter). In the original Smalltalk-MVC, the View observes the Model for changes and updates itself accordingly.
@@ -1795,8 +1801,8 @@ Learn more from data-binding usage in [Login](#login) (4 data-binding versions),
1795
1801
  #### Data-Binding Gotchas
1796
1802
 
1797
1803
  - Never data-bind a control property to an attribute on the same view object with the same exact name (e.g. binding `entry` `text` property to `self` `text` attribute) as it would conflict with it. Instead, data-bind view property to an attribute with a different name on the view object or with the same name, but on a presenter or model object (e.g. data-bind `entry` `text` to `self` `legal_text` attribute or to `contract` model `text` attribute)
1798
- - Data-binding a property utilizes the control's listener associated with the property (e.g. `on_changed` for `entry` `text`), so you cannot hook into the listener directly anymore as that would negate data-binding. Instead, you can add an `after_write: ->(val) {}` option to perform something on trigger of the control listener instead.
1799
- - Data-binding a View control to another View control directly is not a good idea. Instead, data-bind both View controls to the same Presenter/Model attribute, and that keeps them in sync while keeping the code decoupled.
1804
+ - Data-binding a property utilizes the control's listener associated with the property (e.g. `on_changed` for `entry` `text`), so although you can add another listener if you want ([Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) will happily add your listener to the list of listeners that will get notified by a certain event), sometimes it is recommended that you add an `after_read: ->(val) {}` or `after_write: ->(val) {}` block instead to perform something after data-binding reads from or writes to the Model attribute.
1805
+ - Data-binding a View control to another View control directly is not a good practice as it causes tight-coupling. Instead, data-bind both View controls to the same Presenter/Model attribute, and that keeps them in sync while keeping the code decoupled.
1800
1806
 
1801
1807
  ### API Gotchas
1802
1808
 
@@ -1805,7 +1811,6 @@ Learn more from data-binding usage in [Login](#login) (4 data-binding versions),
1805
1811
  - `table` `checkbox_text_column` checkbox editing only works on Linux (not Mac or Windows) due to a current limitation in [libui](https://github.com/andlabs/ui/issues/357).
1806
1812
  - `text` `align` property seems not to work on the Mac ([libui](https://github.com/andlabs/libui) has an [issue](https://github.com/andlabs/libui/pull/407) about it)
1807
1813
  - `text` `string` `background` does not work on Windows due to an [issue in libui](https://github.com/andlabs/libui/issues/347).
1808
- - `table` controls on Windows intentionally get an extra empty row at the end because if any row were to be deleted for the first time, double-deletion happens due to an issue in [libui](https://github.com/andlabs/libui) on Windows.
1809
1814
  - `table` `progress_bar` column on Windows cannot be updated with a positive value if it started initially with `-1` (it ignores update to avoid crashing due to an issue in [libui](https://github.com/andlabs/libui) on Windows.
1810
1815
  - It seems that [libui](https://github.com/andlabs/libui) does not support nesting multiple `area` controls under a `grid` as only the first one shows up in that scenario. To workaround that limitation, use a `vertical_box` with nested `horizontal_box`s instead to include multiple `area`s in a GUI.
1811
1816
  - As per the code of [examples/basic_transform.rb](#basic-transform), Windows requires different ordering of transforms than Mac and Linux.
@@ -3448,7 +3453,6 @@ class BasicTableButton
3448
3453
  end
3449
3454
  }
3450
3455
 
3451
-
3452
3456
  cell_rows <= [self, :animals, column_attributes: {'Animal' => :name, 'Description' => :sound}]
3453
3457
 
3454
3458
  # explicit unidirectional data-binding of table cell_rows to self.animals
@@ -6040,7 +6044,7 @@ Glimmer::LibUI.timer(1) do
6040
6044
  cpu_percentage_value = nil
6041
6045
  if OS.windows?
6042
6046
  cpu_percentage_raw_value = `wmic cpu get loadpercentage`
6043
- cpu_percentage_value = cpu_percentage_raw_value.split("\n")[2].to_i
6047
+ cpu_percentage_value = cpu_percentage_raw_value.split("\n").map(&:strip).find {|l| l.match(/^\d+$/)}.to_i
6044
6048
  elsif OS.mac?
6045
6049
  cpu_percentage_value = `ps -A -o %cpu | awk '{s+=$1} END {print s}'`.to_i
6046
6050
  elsif OS.linux?
@@ -6111,6 +6115,7 @@ class CustomDrawText
6111
6115
  @string.font = fb.font
6112
6116
  end
6113
6117
  }
6118
+
6114
6119
  color_button { |cb|
6115
6120
  label 'Color'
6116
6121
 
@@ -6118,13 +6123,17 @@ class CustomDrawText
6118
6123
  @string.color = cb.color
6119
6124
  end
6120
6125
  }
6121
- color_button { |cb|
6122
- label 'Background'
6123
-
6124
- on_changed do
6125
- @string.background = cb.color
6126
- end
6127
- }
6126
+
6127
+ unless OS.windows?
6128
+ color_button { |cb|
6129
+ label 'Background'
6130
+
6131
+ on_changed do
6132
+ @string.background = cb.color
6133
+ end
6134
+ }
6135
+ end
6136
+
6128
6137
  combobox { |c|
6129
6138
  label 'Underline'
6130
6139
  items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
@@ -6134,12 +6143,36 @@ class CustomDrawText
6134
6143
  @string.underline = c.selected_item.underscore
6135
6144
  end
6136
6145
  }
6146
+
6147
+ combobox { |c|
6148
+ label 'Underline Built-In Color'
6149
+ items Glimmer::LibUI.enum_symbols(:underline_color).map(&:to_s).map(&:capitalize)
6150
+ selected 'Custom'
6151
+
6152
+ on_selected do
6153
+ @underline_custom_color_button.enabled = c.selected_item == 'Custom'
6154
+ if c.selected_item == 'Custom'
6155
+ @string.underline_color = @underline_custom_color_button.color
6156
+ else
6157
+ @string.underline_color = c.selected_item.underscore
6158
+ @underline_custom_color_button.color = :black
6159
+ end
6160
+ end
6161
+ }
6162
+
6163
+ @underline_custom_color_button = color_button {
6164
+ label 'Underline Custom Color'
6165
+
6166
+ on_changed do
6167
+ @string.underline_color = @underline_custom_color_button.color
6168
+ end
6169
+ }
6137
6170
  }
6138
6171
 
6139
6172
  area {
6140
- text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
6173
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width] - 2*x)
6141
6174
  # align :left # default alignment
6142
-
6175
+
6143
6176
  @string = string {
6144
6177
  ' At last Ygramul sensed that something was coming toward ' \
6145
6178
  'her. With the speed of lightning, she turned about, confronting ' \
@@ -6184,62 +6217,94 @@ require 'glimmer-dsl-libui'
6184
6217
  # The English version, translated by Ralph Manheim, was published in 1983.
6185
6218
  class CustomDrawText
6186
6219
  include Glimmer
6187
-
6220
+
6188
6221
  def launch
6189
6222
  window('Michael Ende (1929-1995) The Neverending Story', 600, 500) {
6190
6223
  margined true
6191
-
6224
+
6192
6225
  vertical_box {
6193
6226
  form {
6194
6227
  stretchy false
6195
-
6228
+
6196
6229
  font_button { |fb|
6197
6230
  label 'Font'
6198
-
6231
+
6199
6232
  on_changed do
6200
6233
  @font = fb.font
6201
6234
  @area.queue_redraw_all
6202
6235
  end
6203
6236
  }
6237
+
6204
6238
  color_button { |cb|
6205
6239
  label 'Color'
6206
-
6240
+
6207
6241
  on_changed do
6208
6242
  @color = cb.color
6209
6243
  @area.queue_redraw_all
6210
6244
  end
6211
6245
  }
6212
- color_button { |cb|
6213
- label 'Background'
6214
-
6215
- on_changed do
6216
- @background = cb.color
6217
- @area.queue_redraw_all
6218
- end
6219
- }
6246
+
6247
+ unless OS.windows?
6248
+ color_button { |cb|
6249
+ label 'Background'
6250
+
6251
+ on_changed do
6252
+ @background = cb.color
6253
+ @area.queue_redraw_all
6254
+ end
6255
+ }
6256
+ end
6257
+
6220
6258
  combobox { |c|
6221
6259
  label 'Underline'
6222
6260
  items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
6223
6261
  selected 'None'
6224
-
6262
+
6225
6263
  on_selected do
6226
6264
  @underline = c.selected_item.underscore
6227
6265
  @area.queue_redraw_all
6228
6266
  end
6229
6267
  }
6268
+
6269
+ combobox { |c|
6270
+ label 'Underline Built-In Color'
6271
+ items Glimmer::LibUI.enum_symbols(:underline_color).map(&:to_s).map(&:capitalize)
6272
+ selected 'Custom'
6273
+
6274
+ on_selected do
6275
+ @underline_custom_color_button.enabled = c.selected_item == 'Custom'
6276
+ if c.selected_item == 'Custom'
6277
+ @underline_color = @underline_custom_color_button.color
6278
+ else
6279
+ @underline_color = c.selected_item.underscore
6280
+ @underline_custom_color_button.color = :black
6281
+ end
6282
+ @area.queue_redraw_all
6283
+ end
6284
+ }
6285
+
6286
+ @underline_custom_color_button = color_button {
6287
+ label 'Underline Custom Color'
6288
+
6289
+ on_changed do
6290
+ @underline_color = @underline_custom_color_button.color
6291
+ @area.queue_redraw_all
6292
+ end
6293
+ }
6230
6294
  }
6231
-
6295
+
6232
6296
  @area = area {
6233
6297
  on_draw do |area_draw_params|
6234
- text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
6298
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width] - 2*x)
6235
6299
  # align :left # default alignment
6236
-
6300
+
6237
6301
  string {
6238
6302
  font @font
6239
6303
  color @color
6240
6304
  background @background
6241
6305
  underline @underline
6242
-
6306
+ underline_color @underline_color
6307
+
6243
6308
  ' At last Ygramul sensed that something was coming toward ' \
6244
6309
  'her. With the speed of lightning, she turned about, confronting ' \
6245
6310
  'Atreyu with an enormous steel-blue face. Her single eye had a ' \
@@ -8310,6 +8375,12 @@ window('Login') {
8310
8375
 
8311
8376
  #### Method-Based Custom Keyword
8312
8377
 
8378
+ [Custom keywords](#custom-keywords) can be defined to represent custom controls (components) that provide new features or act as composites of existing controls that need to be reused multiple times in an application or across multiple applications. Custom keywords save a lot of development time, improving productivity and maintainbility.
8379
+
8380
+ This example defines `form_field`, `address_form`, `label_pair`, and `address` as custom control keywords.
8381
+
8382
+ The custom keywords are defined via methods (thus are "method-based").
8383
+
8313
8384
  [examples/method_based_custom_keyword.rb](examples/method_based_custom_keyword.rb)
8314
8385
 
8315
8386
  Run with this command from the root of the project if you cloned the project:
@@ -10047,7 +10118,7 @@ https://github.com/iraamaro/i3off-gtk-ruby
10047
10118
 
10048
10119
  ### Issues
10049
10120
 
10050
- If you encounter [issues](https://github.com/AndyObtiva/glimmer-dsl-libui/issues) that are not reported, discover missing features that are not mentioned in [TODO.md](TODO.md), or think up better ways to use [libui](https://github.com/andlabs/libui) than what is possible with [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui), you may submit an [issue](https://github.com/AndyObtiva/glimmer-dsl-libui/issues/new) or [pull request](https://github.com/AndyObtiva/glimmer-dsl-libui/compare) on [GitHub](https://github.com). In the meantime, you may try older gem versions of [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) till you find one that works until issues are resolved.
10121
+ If you encounter [issues](https://github.com/AndyObtiva/glimmer-dsl-libui/issues) that are not reported, discover missing features that are not mentioned in [TODO.md](TODO.md), or think up better ways to use [libui](https://github.com/andlabs/libui) than what is possible with [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui), you may submit an [issue](https://github.com/AndyObtiva/glimmer-dsl-libui/issues/new) or [pull request](https://github.com/AndyObtiva/glimmer-dsl-libui/compare) on [GitHub](https://github.com). In the meantime, you may try older gem versions of [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) till you find one that works.
10051
10122
 
10052
10123
  ### Chat
10053
10124
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.15
1
+ 0.4.19
@@ -17,7 +17,7 @@ window('Animal sounds', 300, 200) {
17
17
  table {
18
18
  text_column('Animal')
19
19
  text_column('Description')
20
-
20
+
21
21
  cell_rows data
22
22
  }
23
23
  }
@@ -41,7 +41,6 @@ class BasicTableButton
41
41
  end
42
42
  }
43
43
 
44
-
45
44
  cell_rows <= [self, :animals, column_attributes: {'Animal' => :name, 'Description' => :sound}]
46
45
 
47
46
  # explicit unidirectional data-binding of table cell_rows to self.animals
@@ -11,7 +11,7 @@ Glimmer::LibUI.timer(1) do
11
11
  cpu_percentage_value = nil
12
12
  if OS.windows?
13
13
  cpu_percentage_raw_value = `wmic cpu get loadpercentage`
14
- cpu_percentage_value = cpu_percentage_raw_value.split("\n")[2].to_i
14
+ cpu_percentage_value = cpu_percentage_raw_value.split("\n").map(&:strip).find {|l| l.match(/^\d+$/)}.to_i
15
15
  elsif OS.mac?
16
16
  cpu_percentage_value = `ps -A -o %cpu | awk '{s+=$1} END {print s}'`.to_i
17
17
  elsif OS.linux?
@@ -21,6 +21,7 @@ class CustomDrawText
21
21
  @string.font = fb.font
22
22
  end
23
23
  }
24
+
24
25
  color_button { |cb|
25
26
  label 'Color'
26
27
 
@@ -28,13 +29,17 @@ class CustomDrawText
28
29
  @string.color = cb.color
29
30
  end
30
31
  }
31
- color_button { |cb|
32
- label 'Background'
33
-
34
- on_changed do
35
- @string.background = cb.color
36
- end
37
- }
32
+
33
+ unless OS.windows?
34
+ color_button { |cb|
35
+ label 'Background'
36
+
37
+ on_changed do
38
+ @string.background = cb.color
39
+ end
40
+ }
41
+ end
42
+
38
43
  combobox { |c|
39
44
  label 'Underline'
40
45
  items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
@@ -44,6 +49,7 @@ class CustomDrawText
44
49
  @string.underline = c.selected_item.underscore
45
50
  end
46
51
  }
52
+
47
53
  combobox { |c|
48
54
  label 'Underline Built-In Color'
49
55
  items Glimmer::LibUI.enum_symbols(:underline_color).map(&:to_s).map(&:capitalize)
@@ -59,6 +65,7 @@ class CustomDrawText
59
65
  end
60
66
  end
61
67
  }
68
+
62
69
  @underline_custom_color_button = color_button {
63
70
  label 'Underline Custom Color'
64
71
 
@@ -22,6 +22,7 @@ class CustomDrawText
22
22
  @area.queue_redraw_all
23
23
  end
24
24
  }
25
+
25
26
  color_button { |cb|
26
27
  label 'Color'
27
28
 
@@ -30,14 +31,18 @@ class CustomDrawText
30
31
  @area.queue_redraw_all
31
32
  end
32
33
  }
33
- color_button { |cb|
34
- label 'Background'
35
-
36
- on_changed do
37
- @background = cb.color
38
- @area.queue_redraw_all
39
- end
40
- }
34
+
35
+ unless OS.windows?
36
+ color_button { |cb|
37
+ label 'Background'
38
+
39
+ on_changed do
40
+ @background = cb.color
41
+ @area.queue_redraw_all
42
+ end
43
+ }
44
+ end
45
+
41
46
  combobox { |c|
42
47
  label 'Underline'
43
48
  items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
@@ -48,6 +53,7 @@ class CustomDrawText
48
53
  @area.queue_redraw_all
49
54
  end
50
55
  }
56
+
51
57
  combobox { |c|
52
58
  label 'Underline Built-In Color'
53
59
  items Glimmer::LibUI.enum_symbols(:underline_color).map(&:to_s).map(&:capitalize)
@@ -64,6 +70,7 @@ class CustomDrawText
64
70
  @area.queue_redraw_all
65
71
  end
66
72
  }
73
+
67
74
  @underline_custom_color_button = color_button {
68
75
  label 'Underline Custom Color'
69
76
 
@@ -13,13 +13,13 @@ def form_field(model, attribute)
13
13
  }
14
14
  end
15
15
 
16
- def address_form(address)
16
+ def address_form(address_model)
17
17
  form {
18
- form_field(address, :street)
19
- form_field(address, :p_o_box)
20
- form_field(address, :city)
21
- form_field(address, :state)
22
- form_field(address, :zip_code)
18
+ form_field(address_model, :street)
19
+ form_field(address_model, :p_o_box)
20
+ form_field(address_model, :city)
21
+ form_field(address_model, :state)
22
+ form_field(address_model, :zip_code)
23
23
  }
24
24
  end
25
25
 
@@ -32,10 +32,10 @@ def label_pair(model, attribute, value)
32
32
  }
33
33
  end
34
34
 
35
- def address(address)
35
+ def address(address_model)
36
36
  vertical_box {
37
- address.each_pair do |attribute, value|
38
- label_pair(address, attribute, value)
37
+ address_model.each_pair do |attribute, value|
38
+ label_pair(address_model, attribute, value)
39
39
  end
40
40
  }
41
41
  end
@@ -17,13 +17,13 @@ def form_field(model, property)
17
17
  }
18
18
  end
19
19
 
20
- def address_form(address)
20
+ def address_form(address_model)
21
21
  form {
22
- form_field(address, :street)
23
- form_field(address, :p_o_box)
24
- form_field(address, :city)
25
- form_field(address, :state)
26
- form_field(address, :zip_code)
22
+ form_field(address_model, :street)
23
+ form_field(address_model, :p_o_box)
24
+ form_field(address_model, :city)
25
+ form_field(address_model, :state)
26
+ form_field(address_model, :zip_code)
27
27
  }
28
28
  end
29
29
 
@@ -39,10 +39,10 @@ def label_pair(model, attribute, value)
39
39
  end
40
40
  end
41
41
 
42
- def address(address)
42
+ def address(address_model)
43
43
  vertical_box {
44
- address.each_pair do |attribute, value|
45
- label_pair(address, attribute, value)
44
+ address_model.each_pair do |attribute, value|
45
+ label_pair(address_model, attribute, value)
46
46
  end
47
47
  }
48
48
  end
Binary file
data/icons/blank.png ADDED
Binary file
@@ -41,6 +41,7 @@ module Glimmer
41
41
  shine_data_binding
42
42
  property
43
43
  string
44
+ operation
44
45
  control
45
46
  shape
46
47
  ]