glimmer-dsl-libui 0.2.5 → 0.2.9

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: b691a0eeec6e7d571ac6815c272e0dd5ae48c0f0302fc11876ae373cb92cba1e
4
- data.tar.gz: 576d6840f47182d0dc0bd3ccccdb301b5a9efb2f7b7038efa3e5fa8d8ea30537
3
+ metadata.gz: 7aaaa95f0efdd3c1dd3dcc5ceb961e6f643d3df62a7145fce68da5dee977bcc6
4
+ data.tar.gz: 410b8273b462a9ad76dc7485d4183c0be08be62c60bd64f92a7b7aa974692e5d
5
5
  SHA512:
6
- metadata.gz: d00b9ecc527e56e144d1baead2910e62a29f9f429af9fc57a1da05a4d590d9286f47c2fe8d840062c1a989f42183f9dfc717a0800db2ec6467acc434201d3707
7
- data.tar.gz: 53dbe182b9b9607111915412af9d418571511af560dc5af83d792214139c62f91358aa5555147d962a040802852d74f581413b99d287827454ea2ca865ec110b
6
+ metadata.gz: f04981d43dc57f873da61bd77166d16b519b408a4b11b3695a1f82670e8502eab328d19c4bef60cab5549eae25b6a813ec0ca40342c65b2597c1a9b315ce3014
7
+ data.tar.gz: f714acf1968782069530c9ebce6c260080a12bb664d5218e84ec10f86250152e2e0abbc0b48e98c435da46e8915f858ff6e16a241009b0564cb8ebbb8f018c65
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.9
4
+
5
+ - Upgrade to glimmer 2.3.0
6
+ - Use glimmer 2.3.0 to support automatic table row change when performing a direct deep row/column update in `cell_rows` (e.g. `data[3][0] = 'new value'`) as opposed to a general shallow row update (e.g. `data[3] = ['new value', 'other new value']` <- already supported)
7
+
8
+ ## 0.2.8
9
+
10
+ - Support `table` `on_changed` listener to report all changes (of operation type `:deleted`, `:changed`, `:inserted`)
11
+ - Support `table` `on_edited` listener to report changes happening through direct table editing only
12
+ - Default value of `text` `width` argument looks into x and adjusts by leaving the same space on the right side
13
+
14
+ ## 0.2.7
15
+
16
+ - New examples/basic_table_color.rb
17
+ - Support `background_color_column` for `table`
18
+ - Support `text_color_column` for `table`
19
+ - Support `checkbox_text_color_column` for `table`
20
+ - Support `image_text_color_column` for `table`
21
+
22
+ ## 0.2.6
23
+
24
+ - Support `string` control property: `open_type_features`
25
+ - Auto-free attributed string objects from memory
26
+
3
27
  ## 0.2.5
4
28
 
5
29
  - Support attributed `string` `underline_color` property (built-in enum symbols and custom color)
@@ -8,9 +32,9 @@
8
32
 
9
33
  - Support examples/custom_draw_text.rb
10
34
  - Support stable `text` control nestable under `area`
11
- - Support `string` control property `background`
12
- - Support `string` control property `font`
13
- - Support `string` control property `underline`
35
+ - Support `string` control property: `background`
36
+ - Support `string` control property: `font`
37
+ - Support `string` control property: `underline`
14
38
  - Enhance `combobox` to accept `String` value for `selected` item instead of just `Integer` index
15
39
  - Add `selected_item` read-only property to `combobox` to return selected item `String` value
16
40
  - Fix `color` property support for `string` to accept 255-based rgb values
@@ -23,7 +47,7 @@
23
47
  - Support dynamic `text` control to be called in `area` `on_draw` listener
24
48
  - Support `text` control `default_font` property
25
49
  - Support `string` control nestable under `text` to represent an attributed/unattributed string (depending on nestable properties)
26
- - Support `string` control property `color`
50
+ - Support `string` control property: `color`
27
51
  - Support enum symbols for `align` property of `text` control
28
52
  - Support enum symbols for `:italic` font descriptor key (in addition to numbers)
29
53
  - Support enum symbols for `:stretch` font descriptor key (in addition to numbers)
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.2.5
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.2.9
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)
@@ -61,7 +61,7 @@ window('Task Progress', 300, 200) {
61
61
 
62
62
  on_clicked do
63
63
  data.each_with_index do |row_data, row|
64
- data[row] = [row_data[0], 100] # automatically updates table due to implicit data-binding
64
+ data[row][1] = 100 # automatically updates table due to implicit data-binding
65
65
  end
66
66
  end
67
67
  }
@@ -197,7 +197,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
197
197
 
198
198
  ## Table of Contents
199
199
 
200
- - [Glimmer DSL for LibUI 0.2.5](#-glimmer-dsl-for-libui-025)
200
+ - [Glimmer DSL for LibUI 0.2.9](#-glimmer-dsl-for-libui-029)
201
201
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
202
202
  - [Usage](#usage)
203
203
  - [Girb (Glimmer IRB)](#girb-glimmer-irb)
@@ -235,6 +235,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
235
235
  - [Basic Table Checkbox](#basic-table-checkbox)
236
236
  - [Basic Table Checkbox Text](#basic-table-checkbox-text)
237
237
  - [Basic Table Progress Bar](#basic-table-progress-bar)
238
+ - [Basic Table Color](#basic-table-color)
238
239
  - [Form Table](#form-table)
239
240
  - [Basic Area](#basic-area)
240
241
  - [Dynamic Area](#dynamic-area)
@@ -333,7 +334,7 @@ gem install glimmer-dsl-libui
333
334
  Or install via Bundler `Gemfile`:
334
335
 
335
336
  ```ruby
336
- gem 'glimmer-dsl-libui', '~> 0.2.5'
337
+ gem 'glimmer-dsl-libui', '~> 0.2.9'
337
338
  ```
338
339
 
339
340
  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.
@@ -409,12 +410,14 @@ Control(Args) | Properties | Listeners
409
410
  `about_menu_item` | None | `on_clicked`
410
411
  `area` | None | `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)`
411
412
  `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
413
+ `background_color_column(name as String)` | None | None
412
414
  `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
413
415
  `button(text as String)` | `text` (`String`) | `on_clicked`
414
416
  `button_column(name as String)` | `enabled` (Boolean) | None
415
417
  `checkbox(text as String)` | `checked` (Boolean), `text` (`String`) | `on_toggled`
416
418
  `checkbox_column(name as String)` | `editable` (Boolean) | None
417
419
  `checkbox_text_column(name as String)` | `editable` (Boolean), `editable_checkbox` (Boolean), `editable_text` (Boolean) | None
420
+ `checkbox_text_color_column(name as String)` | `editable` (Boolean), `editable_checkbox` (Boolean), `editable_text` (Boolean) | None
418
421
  `combobox` | `items` (`Array` of `String`), `selected` (`Integer`) | `on_selected`
419
422
  `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`
420
423
  `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`
@@ -432,6 +435,7 @@ Control(Args) | Properties | Listeners
432
435
  `image_part(pixels as String [encoded image rgba byte array], width as Numeric, height as Numeric, byte_stride as Numeric [usually width*4])` | None | None
433
436
  `image_column(name as String)` | None | None
434
437
  `image_text_column(name as String)` | None | None
438
+ `image_text_color_column(name as String)` | None | None
435
439
  `label(text as String)` | `text` (`String`) | None
436
440
  `line(x as Numeric, y as Numeric)` | `x` (`Numeric`), `y` (`Numeric`) | None
437
441
  `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
@@ -453,10 +457,13 @@ Control(Args) | Properties | Listeners
453
457
  `slider(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
454
458
  `spinbox(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
455
459
  `square(x as Numeric, y as Numeric, length as Numeric)` | `x` (`Numeric`), `y` (`Numeric`), `length` (`Numeric`) | None
460
+ `string` | `font`, `color`, `background`, `underline`, `underline_color`, `open_type_features` | None
456
461
  `tab` | `margined` (Boolean), `num_pages` (`Integer`) | None
457
462
  `tab_item(name as String)` | `index` [read-only] (`Integer`), `margined` (Boolean), `name` [read-only] (`String`) | None
458
- `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
463
+ `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 | `on_changed {|row, type, row_data| ...}`, `on_edited {|row, row_data| ...}`
464
+ `text(x = 0 as Numeric, y = 0 as Numeric, width = area_width as Numeric)` | `align`, `default_font` | None
459
465
  `text_column(name as String)` | `editable` (Boolean) | None
466
+ `text_color_column(name as String)` | `editable` (Boolean) | None
460
467
  `time_picker` | `time` (`Hash` of keys: `sec` as `Integer`, `min` as `Integer`, `hour` as `Integer`) | `on_changed`
461
468
  `vertical_box` | `padded` (Boolean) | None
462
469
  `vertical_separator` | None | None
@@ -510,12 +517,16 @@ All operations that could normally be called on `LibUI` can also be called on `G
510
517
  ### Table API
511
518
 
512
519
  The `table` control must first declare its columns via one of these column keywords (mentioned in [Supported Controls](#supported-controls)):
520
+ - `background_color_column`: expects color cell values
513
521
  - `button_column`: expects `String` cell values
514
522
  - `checkbox_column`: expects Boolean cell values
515
523
  - `checkbox_text_column`: expects dual-element `Array` of Boolean and `String` cell values
524
+ - `checkbox_text_color_column`: expects triple-element `Array` of Boolean, `String`, and color cell values
516
525
  - `image_column`: expects `image` cell values (produced by `image` and `image_part` keywords as per [Supported Controls](#supported-controls))
517
526
  - `image_text_column`: expects dual-element `Array` of `image` and `String` cell values
527
+ - `image_text_color_column`: expects triple-element `Array` of `image`, `String`, and color cell values
518
528
  - `text_column`: expects `String` cell values
529
+ - `text_color_column`: expects dual-element `Array` of `String` and color cell values
519
530
  - `progress_bar_column`: expects `Integer` cell values
520
531
 
521
532
  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.
@@ -790,6 +801,50 @@ Check [Basic Transform](#basic-transform) example for use of [X11](https://en.wi
790
801
 
791
802
  Check [Histogram](#histogram) example for use of hex colors.
792
803
 
804
+ To draw `text` in an `area`, you simply nest a `text(x, y, width)` control directly under `area` or inside a `on_draw` listener, and then nest attributed `string {string_value}` controls underneath it returning an actual `String` (think of them as the `<span>` element in html, which contains a string of text).
805
+
806
+ `text` control can have the following properties:
807
+ - `default_font`:
808
+ - `align`: `:left` (default), `:center`, or `:right` (`align` currently seems not to work on the Mac)
809
+
810
+ `string` can have the following properties:
811
+ - `font`: font descriptor hash consisting of `:family`, `:size`, `:weight` (`[:minimum, :thin, :ultra_light, :light, :book, :normal, :medium, :semi_bold, :bold, :ultra_bold, :heavy, :ultra_heavy, :maximum]`), `:italic` (`[:normal, :oblique, :italic]`), and `:stretch` (`[:ultra_condensed, :extra_condensed, :condensed, :semi_condensed, :normal, :semi_expanded, :expanded, :extra_expanded, :ultra_expanded]`) key values
812
+ - `color`: rgba, hex, or [X11](https://en.wikipedia.org/wiki/X11_color_names) color
813
+ - `background`: rgba, hex, or [X11](https://en.wikipedia.org/wiki/X11_color_names) color
814
+ - `underline`: one of `:none`, `:single`, `:double`, `:suggestion`, `:color_custom`, `:color_spelling`, `:color_grammar`, `:color_auxiliary`
815
+ - `underline_color`: one of `:spelling`, `:grammar`, `:auxiliary`, rgba, hex, or [X11](https://en.wikipedia.org/wiki/X11_color_names) color
816
+ - `open_type_features`: it must have a block containing `open_type_tag` occurrances, which take the a, b, c, d arguments plus a number at the end.
817
+
818
+ Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
819
+
820
+ ```ruby
821
+ window('area text drawing') {
822
+ area {
823
+ text {
824
+ default_font family: 'Helvetica', size: 12, weight: :normal, italic: :normal, stretch: :normal
825
+
826
+ string {
827
+ font family: 'Georgia', size: 13, weight: :medium, italic: :normal, stretch: :normal
828
+ color r: 230, g: 100, b: 50, a: 0.5
829
+ background r: 230, g: 200, b: 250, a: 0.8
830
+ underline :single
831
+ underline_color :spelling
832
+ open_type_features {
833
+ open_type_tag 'l', 'i', 'g', 'a', 0
834
+ open_type_tag 'l', 'i', 'g', 'a', 1
835
+ }
836
+
837
+ "This is a test\n\n"
838
+ }
839
+
840
+ string {
841
+ 'This is another test'
842
+ }
843
+ }
844
+ }
845
+ }.show
846
+ ```
847
+
793
848
  ### Smart Defaults and Conventions
794
849
 
795
850
  - `horizontal_box`, `vertical_box`, `grid`, and `form` controls have `padded` as `true` upon instantiation to ensure more user-friendly GUI by default
@@ -831,7 +886,7 @@ Check [Histogram](#histogram) example for use of hex colors.
831
886
 
832
887
  - 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`).
833
888
  - `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).
834
- - It seems that `arc` `start_angle` and `sweep` properties are ignored by [libui](https://github.com/andlabs/libui) and always set to `0` and `360` respectively, producing a full circle.
889
+ - `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)
835
890
 
836
891
  ### Original API
837
892
 
@@ -2469,6 +2524,14 @@ window('Editable animal sounds', 300, 200) {
2469
2524
 
2470
2525
  cell_rows data
2471
2526
  editable true
2527
+
2528
+ on_changed do |row, type, row_data| # fires on all changes (even ones happening through data array)
2529
+ puts "Row #{row} #{type}: #{row_data}"
2530
+ end
2531
+
2532
+ on_edited do |row, row_data| # only fires on direct table editing
2533
+ puts "Row #{row} edited: #{row_data}"
2534
+ end
2472
2535
  }
2473
2536
  }
2474
2537
 
@@ -2540,7 +2603,7 @@ window('Editable column animal sounds', 400, 200) {
2540
2603
 
2541
2604
  ### Basic Table Image
2542
2605
 
2543
- This example has a prerequisite of installing `chunky_png` Ruby gem:
2606
+ This example requires pre-installing `chunky_png` Ruby gem:
2544
2607
 
2545
2608
  ```
2546
2609
  gem install chunky_png -v1.4.0
@@ -2827,6 +2890,10 @@ window('Animal sounds', 300, 200) {
2827
2890
  }
2828
2891
 
2829
2892
  cell_rows data # implicit data-binding
2893
+
2894
+ on_changed do |row, type, row_data|
2895
+ puts "Row #{row} #{type}: #{row_data}"
2896
+ end
2830
2897
  }
2831
2898
  }
2832
2899
  }.show
@@ -2989,7 +3056,7 @@ window('Task Progress', 300, 200) {
2989
3056
 
2990
3057
  on_clicked do
2991
3058
  data.each_with_index do |row_data, row|
2992
- data[row] = [row_data[0], 100] # automatically updates table due to implicit data-binding
3059
+ data[row][1] = 100 # automatically updates table due to implicit data-binding
2993
3060
  end
2994
3061
  end
2995
3062
  }
@@ -2997,6 +3064,78 @@ window('Task Progress', 300, 200) {
2997
3064
  }.show
2998
3065
  ```
2999
3066
 
3067
+ ### Basic Table Color
3068
+
3069
+ This example requires pre-installing `chunky_png` Ruby gem:
3070
+
3071
+ ```
3072
+ gem install chunky_png -v1.4.0
3073
+ ```
3074
+
3075
+ [examples/basic_table_color.rb](examples/basic_table_color.rb)
3076
+
3077
+ Run with this command from the root of the project if you cloned the project:
3078
+
3079
+ ```
3080
+ ruby -r './lib/glimmer-dsl-libui' examples/basic_table_color.rb
3081
+ ```
3082
+
3083
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
3084
+
3085
+ ```
3086
+ ruby -r glimmer-dsl-libui -e "require 'examples/basic_table_color'"
3087
+ ```
3088
+
3089
+ Mac
3090
+
3091
+ ![glimmer-dsl-libui-mac-basic-table-color.png](images/glimmer-dsl-libui-mac-basic-table-color.png)
3092
+
3093
+ Linux
3094
+
3095
+ ![glimmer-dsl-libui-linux-basic-table-color.png](images/glimmer-dsl-libui-linux-basic-table-color.png)
3096
+
3097
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
3098
+
3099
+ ```ruby
3100
+ require 'glimmer-dsl-libui'
3101
+ require 'chunky_png'
3102
+
3103
+ include Glimmer
3104
+
3105
+ f = File.open(File.expand_path('../icons/glimmer.png', __dir__))
3106
+ canvas = ChunkyPNG::Canvas.from_io(f)
3107
+ f.close
3108
+ canvas.resample_nearest_neighbor!(24, 24)
3109
+ data = canvas.to_rgba_stream
3110
+ width = canvas.width
3111
+ height = canvas.height
3112
+ img = image {
3113
+ image_part(data, width, height, width * 4)
3114
+ }
3115
+
3116
+ data = [
3117
+ [['cat', :red] , ['meow', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], {r: 255, g: 120, b: 0, a: 0.5}],
3118
+ [['dog', :yellow] , ['woof', {r: 240, g: 32, b: 32}] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], :skyblue],
3119
+ [['chicken', :beige], ['cock-a-doodle-doo', :blue] , [false, 'mammal', :red] , [img, 'Glimmer', :beige], {r: 5, g: 120, b: 110}],
3120
+ [['horse', :purple] , ['neigh', {r: 240, g: 32, b: 32}], [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], '13a1fb'],
3121
+ [['cow', :gray] , ['moo', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :brown], 0x12ff02]
3122
+ ]
3123
+
3124
+ window('Animals', 500, 200) {
3125
+ horizontal_box {
3126
+ table {
3127
+ text_color_column('Animal')
3128
+ text_color_column('Sound')
3129
+ checkbox_text_color_column('Description')
3130
+ image_text_color_column('GUI')
3131
+ background_color_column('Mammal')
3132
+
3133
+ cell_rows data
3134
+ }
3135
+ }
3136
+ }.show
3137
+ ```
3138
+
3000
3139
  ### Form Table
3001
3140
 
3002
3141
  [examples/form_table.rb](examples/form_table.rb)
@@ -3112,6 +3251,10 @@ window('Contacts', 600, 600) { |w|
3112
3251
  text_column('State')
3113
3252
 
3114
3253
  cell_rows data # implicit data-binding
3254
+
3255
+ on_changed do |row, type, row_data|
3256
+ puts "Row #{row} #{type}: #{row_data}"
3257
+ end
3115
3258
  }
3116
3259
  }
3117
3260
  }.show
@@ -5397,11 +5540,11 @@ class CustomDrawText
5397
5540
  text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
5398
5541
  # align :left # default alignment
5399
5542
 
5400
- @string = string {
5401
- font @font unless @font.nil?
5402
- color @color unless @color.nil?
5403
- background @background unless @background.nil?
5404
- underline @underline unless @underline.nil?
5543
+ string {
5544
+ font @font
5545
+ color @color
5546
+ background @background
5547
+ underline @underline
5405
5548
 
5406
5549
  ' At last Ygramul sensed that something was coming toward ' \
5407
5550
  'her. With the speed of lightning, she turned about, confronting ' \
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.9
@@ -24,6 +24,10 @@ window('Animal sounds', 300, 200) {
24
24
  }
25
25
 
26
26
  cell_rows data # implicit data-binding
27
+
28
+ on_changed do |row, type, row_data|
29
+ puts "Row #{row} #{type}: #{row_data}"
30
+ end
27
31
  }
28
32
  }
29
33
  }.show
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'glimmer-dsl-libui'
4
+ require 'chunky_png'
5
+
6
+ include Glimmer
7
+
8
+ f = File.open(File.expand_path('../icons/glimmer.png', __dir__))
9
+ canvas = ChunkyPNG::Canvas.from_io(f)
10
+ f.close
11
+ canvas.resample_nearest_neighbor!(24, 24)
12
+ data = canvas.to_rgba_stream
13
+ width = canvas.width
14
+ height = canvas.height
15
+ img = image {
16
+ image_part(data, width, height, width * 4)
17
+ }
18
+
19
+ data = [
20
+ [['cat', :red] , ['meow', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], {r: 255, g: 120, b: 0, a: 0.5}],
21
+ [['dog', :yellow] , ['woof', {r: 240, g: 32, b: 32}] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], :skyblue],
22
+ [['chicken', :beige], ['cock-a-doodle-doo', :blue] , [false, 'mammal', :red] , [img, 'Glimmer', :beige], {r: 5, g: 120, b: 110}],
23
+ [['horse', :purple] , ['neigh', {r: 240, g: 32, b: 32}], [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], '13a1fb'],
24
+ [['cow', :gray] , ['moo', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :brown], 0x12ff02]
25
+ ]
26
+
27
+ window('Animals', 500, 200) {
28
+ horizontal_box {
29
+ table {
30
+ text_color_column('Animal')
31
+ text_color_column('Sound')
32
+ checkbox_text_color_column('Description')
33
+ image_text_color_column('GUI')
34
+ background_color_column('Mammal')
35
+
36
+ cell_rows data
37
+ }
38
+ }
39
+ }.show
@@ -26,7 +26,7 @@ window('Task Progress', 300, 200) {
26
26
 
27
27
  on_clicked do
28
28
  data.each_with_index do |row_data, row|
29
- data[row] = [row_data[0], 100] # automatically updates table due to implicit data-binding
29
+ data[row][1] = 100 # automatically updates table due to implicit data-binding
30
30
  end
31
31
  end
32
32
  }
@@ -69,9 +69,9 @@ class CustomDrawText
69
69
  }
70
70
 
71
71
  area {
72
- text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
72
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width] - 2*x)
73
73
  # align :left # default alignment
74
-
74
+
75
75
  @string = string {
76
76
  ' At last Ygramul sensed that something was coming toward ' \
77
77
  'her. With the speed of lightning, she turned about, confronting ' \
@@ -76,10 +76,10 @@ class CustomDrawText
76
76
 
77
77
  @area = area {
78
78
  on_draw do |area_draw_params|
79
- text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
79
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width] - 2*x)
80
80
  # align :left # default alignment
81
81
 
82
- @string = string {
82
+ string {
83
83
  font @font
84
84
  color @color
85
85
  background @background
@@ -20,6 +20,14 @@ window('Editable animal sounds', 300, 200) {
20
20
 
21
21
  cell_rows data
22
22
  editable true
23
+
24
+ on_changed do |row, type, row_data| # fires on all changes (even ones happening through data array)
25
+ puts "Row #{row} #{type}: #{row_data}"
26
+ end
27
+
28
+ on_edited do |row, row_data| # only fires on direct table editing
29
+ puts "Row #{row} edited: #{row_data}"
30
+ end
23
31
  }
24
32
  }
25
33
 
@@ -82,6 +82,10 @@ window('Contacts', 600, 600) { |w|
82
82
  text_column('State')
83
83
 
84
84
  cell_rows data # implicit data-binding
85
+
86
+ on_changed do |row, type, row_data|
87
+ puts "Row #{row} #{type}: #{row_data}"
88
+ end
85
89
  }
86
90
  }
87
91
  }.show
Binary file
data/icons/glimmer.png ADDED
Binary file
@@ -94,12 +94,27 @@ module Glimmer
94
94
  alias underline_color= underline_color
95
95
  alias set_underline_color underline_color
96
96
 
97
+ def open_type_features(value = nil)
98
+ if value.nil?
99
+ @open_type_features
100
+ else
101
+ @open_type_features = value
102
+ redraw
103
+ end
104
+ end
105
+ alias open_type_features= open_type_features
106
+ alias set_open_type_features open_type_features
107
+
97
108
  def post_add_content
98
109
  block_result = block&.call
99
110
  @string = block_result if block_result.is_a?(String)
100
111
  @parent_proxy&.post_initialize_child(self)
101
112
  end
102
113
 
114
+ def post_initialize_child(child)
115
+ self.open_type_features = child if child.is_a?(Glimmer::LibUI::ControlProxy::OpenTypeFeaturesProxy)
116
+ end
117
+
103
118
  def draw(area_draw_params)
104
119
  @start = ::LibUI.attributed_string_len(@parent_proxy.attributed_string)
105
120
  ::LibUI.attributed_string_append_unattributed(@parent_proxy.attributed_string, @string)
@@ -137,10 +152,15 @@ module Glimmer
137
152
  stretch_attribute = ::LibUI.new_stretch_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_stretch, font[:stretch]))
138
153
  ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, stretch_attribute, @start, @start + @string.size)
139
154
  end
155
+ unless open_type_features.nil?
156
+ open_type_features_attribute = ::LibUI.new_features_attribute(open_type_features.libui)
157
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, open_type_features_attribute, @start, @start + @string.size)
158
+ end
140
159
  destroy if area_proxy.nil?
141
160
  end
142
161
 
143
162
  def destroy
163
+ open_type_features.destroy unless open_type_features.nil?
144
164
  @parent_proxy&.children&.delete(self)
145
165
  end
146
166
 
@@ -0,0 +1,38 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/control_proxy'
23
+ require 'glimmer/libui/control_proxy/column'
24
+
25
+ module Glimmer
26
+ module LibUI
27
+ class ControlProxy
28
+ module Column
29
+ # Proxy for LibUI background color column objects
30
+ #
31
+ # Follows the Proxy Design Pattern
32
+ class BackgroundColorColumnProxy < ControlProxy
33
+ include Column
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,82 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/control_proxy'
23
+ require 'glimmer/libui/control_proxy/column'
24
+ require 'glimmer/libui/control_proxy/triple_column'
25
+ require 'glimmer/libui/control_proxy/editable_column'
26
+
27
+ module Glimmer
28
+ module LibUI
29
+ class ControlProxy
30
+ module Column
31
+ # Proxy for LibUI checkbox text color column objects
32
+ #
33
+ # Follows the Proxy Design Pattern
34
+ class CheckboxTextColorColumnProxy < ControlProxy
35
+ include Column
36
+ include TripleColumn
37
+ include EditableColumn
38
+
39
+ def editable_checkbox(value = nil)
40
+ if value.nil?
41
+ @editable_checkbox = false if @editable_checkbox.nil?
42
+ @editable_checkbox
43
+ else
44
+ @editable_checkbox = !!value
45
+ end
46
+ end
47
+ alias editable_checkbox= editable_checkbox
48
+ alias set_editable_checkbox editable_checkbox
49
+ alias editable_checkbox? editable_checkbox
50
+
51
+ def editable_text(value = nil)
52
+ if value.nil?
53
+ @editable_text = false if @editable_text.nil?
54
+ @editable_text
55
+ else
56
+ @editable_text = !!value
57
+ end
58
+ end
59
+ alias editable_text= editable_text
60
+ alias set_editable_text editable_text
61
+ alias editable_text? editable_text
62
+
63
+ private
64
+
65
+ def build_control
66
+ table_text_column_optional_params = ::LibUI::FFI::TableTextColumnOptionalParams.malloc
67
+ table_text_column_optional_params.ColorModelColumn = third_column_index
68
+ @parent_proxy.append_checkbox_text_column(name, column_index, editable_checkbox_value, second_column_index, editable_text_value, table_text_column_optional_params)
69
+ end
70
+
71
+ def editable_checkbox_value
72
+ (@parent_proxy.editable? || editable? || editable_checkbox?) ? -2 : -1
73
+ end
74
+
75
+ def editable_text_value
76
+ (@parent_proxy.editable? || editable? || editable_text?) ? -2 : -1
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/control_proxy'
23
+ require 'glimmer/libui/control_proxy/column'
24
+ require 'glimmer/libui/control_proxy/triple_column'
25
+ require 'glimmer/libui/control_proxy/editable_column'
26
+
27
+ module Glimmer
28
+ module LibUI
29
+ class ControlProxy
30
+ module Column
31
+ # Proxy for LibUI image text color column objects
32
+ #
33
+ # Follows the Proxy Design Pattern
34
+ class ImageTextColorColumnProxy < ControlProxy
35
+ include Column
36
+ include TripleColumn
37
+ include EditableColumn
38
+
39
+ private
40
+
41
+ def build_control
42
+ table_text_column_optional_params = ::LibUI::FFI::TableTextColumnOptionalParams.malloc
43
+ table_text_column_optional_params.ColorModelColumn = third_column_index
44
+ @parent_proxy.append_image_text_column(name, column_index, second_column_index, editable_value, table_text_column_optional_params)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/control_proxy'
23
+ require 'glimmer/libui/control_proxy/column'
24
+ require 'glimmer/libui/control_proxy/dual_column'
25
+ require 'glimmer/libui/control_proxy/editable_column'
26
+
27
+ module Glimmer
28
+ module LibUI
29
+ class ControlProxy
30
+ module Column
31
+ # Proxy for LibUI text color column objects
32
+ #
33
+ # Follows the Proxy Design Pattern
34
+ class TextColorColumnProxy < ControlProxy
35
+ include Column
36
+ include DualColumn
37
+ include EditableColumn
38
+
39
+ private
40
+
41
+ def build_control
42
+ table_text_column_optional_params = ::LibUI::FFI::TableTextColumnOptionalParams.malloc
43
+ table_text_column_optional_params.ColorModelColumn = second_column_index
44
+ @parent_proxy.append_text_column(name, column_index, editable_value, table_text_column_optional_params)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -38,6 +38,7 @@ module Glimmer
38
38
  private
39
39
 
40
40
  def editable_value
41
+ # TODO consider relying on enum symbol :table_model_column
41
42
  (@parent_proxy.editable? || editable?) ? -2 : -1
42
43
  end
43
44
  end
@@ -0,0 +1,53 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/control_proxy'
23
+ require 'glimmer/libui/control_proxy/area_proxy'
24
+ require 'glimmer/libui/parent'
25
+
26
+ module Glimmer
27
+ module LibUI
28
+ class ControlProxy
29
+ # Proxy for LibUI open type features objects
30
+ #
31
+ # Follows the Proxy Design Pattern
32
+ class OpenTypeFeaturesProxy < ControlProxy
33
+ include Parent
34
+
35
+ def destroy
36
+ ::LibUI.free_open_type_features(@libui)
37
+ @parent_proxy&.children&.delete(self)
38
+ ControlProxy.control_proxies.delete(self)
39
+ end
40
+
41
+ def redraw
42
+ @parent_proxy.redraw
43
+ end
44
+
45
+ private
46
+
47
+ def build_control
48
+ @libui = ::LibUI.new_open_type_features
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,59 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/control_proxy'
23
+ require 'glimmer/libui/control_proxy/area_proxy'
24
+ require 'glimmer/libui/parent'
25
+
26
+ module Glimmer
27
+ module LibUI
28
+ class ControlProxy
29
+ # Proxy for LibUI open type tag objects
30
+ #
31
+ # Follows the Proxy Design Pattern
32
+ class OpenTypeTagProxy < ControlProxy
33
+ def destroy
34
+ @parent_proxy&.children&.delete(self)
35
+ ControlProxy.control_proxies.delete(self)
36
+ end
37
+
38
+ def redraw
39
+ @parent_proxy.redraw
40
+ end
41
+
42
+ private
43
+
44
+ def build_control
45
+ tag_args = @args.dup
46
+ tag_args[0] = ordinalize(tag_args[0])
47
+ tag_args[1] = ordinalize(tag_args[1])
48
+ tag_args[2] = ordinalize(tag_args[2])
49
+ tag_args[3] = ordinalize(tag_args[3])
50
+ ::LibUI.open_type_features_add(@parent_proxy.libui, *tag_args)
51
+ end
52
+
53
+ def ordinalize(arg)
54
+ arg.is_a?(String) ? arg.ord : arg
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -35,6 +35,8 @@ module Glimmer
35
35
  class TableProxy < ControlProxy
36
36
  include Glimmer::FiddleConsumer
37
37
 
38
+ LISTENERS = ['on_changed', 'on_edited']
39
+
38
40
  attr_reader :model_handler, :model, :table_params, :columns
39
41
 
40
42
  def initialize(keyword, parent, args, &block)
@@ -58,8 +60,16 @@ module Glimmer
58
60
 
59
61
  def post_initialize_child(child)
60
62
  @columns << child
61
- # add an extra complementary nil column if it is a dual column (i.e. ImageTextColumnProxy or CheckboxTextColumnProxy
62
- @columns << nil if child.is_a?(DualColumn)
63
+ # add extra complementary columns (:text, :color) if it is a dual/triple column (i.e. ImageTextColumnProxy or CheckboxTextColumnProxy
64
+ case child
65
+ when Column::ImageTextColumnProxy, Column::CheckboxTextColumnProxy
66
+ @columns << :text
67
+ when Column::TextColorColumnProxy
68
+ @columns << :color
69
+ when Column::CheckboxTextColorColumnProxy, Column::ImageTextColorColumnProxy
70
+ @columns << :text
71
+ @columns << :color
72
+ end
63
73
  end
64
74
 
65
75
  def destroy
@@ -73,22 +83,27 @@ module Glimmer
73
83
  else
74
84
  @cell_rows = rows
75
85
  @cell_rows.tap do
76
- @last_cell_rows = @cell_rows.clone
86
+ @last_cell_rows = array_deep_clone(@cell_rows)
77
87
  Glimmer::DataBinding::Observer.proc do
78
88
  if @cell_rows.size < @last_cell_rows.size && @last_cell_rows.include_all?(*@cell_rows)
79
89
  @last_cell_rows.array_diff_indexes(@cell_rows).reverse.each do |row|
80
90
  ::LibUI.table_model_row_deleted(model, row)
91
+ on_changed.each {|listener| listener.call(row, :deleted, @last_cell_rows[row])}
81
92
  end
82
93
  elsif @cell_rows.size > @last_cell_rows.size && @cell_rows.include_all?(*@last_cell_rows)
83
94
  @cell_rows.array_diff_indexes(@last_cell_rows).each do |row|
84
95
  ::LibUI.table_model_row_inserted(model, row)
96
+ on_changed.each {|listener| listener.call(row, :inserted, @cell_rows[row])}
85
97
  end
86
98
  else
87
99
  @cell_rows.each_with_index do |new_row_data, row|
88
- ::LibUI.table_model_row_changed(model, row) if new_row_data != @last_cell_rows[row]
100
+ if new_row_data != @last_cell_rows[row]
101
+ ::LibUI.table_model_row_changed(model, row)
102
+ on_changed.each {|listener| listener.call(row, :changed, @cell_rows[row])}
103
+ end
89
104
  end
90
105
  end
91
- @last_cell_rows = @cell_rows.clone
106
+ @last_cell_rows = array_deep_clone(@cell_rows)
92
107
  end.observe(self, :cell_rows)
93
108
  end
94
109
  end
@@ -119,27 +134,36 @@ module Glimmer
119
134
  @model_handler = ::LibUI::FFI::TableModelHandler.malloc
120
135
  @model_handler.NumColumns = fiddle_closure_block_caller(4) { @columns.map {|c| c.is_a?(DualColumn) ? 2 : 1}.sum }
121
136
  @model_handler.ColumnType = fiddle_closure_block_caller(4, [1, 1, 4]) do |_, _, column|
137
+ # TODO consider refactoring to use Glimmer::LibUI.enum_symbols(:table_value_type)
122
138
  case @columns[column]
123
- when Column::TextColumnProxy, Column::ButtonColumnProxy, NilClass
139
+ when Column::TextColumnProxy, Column::ButtonColumnProxy, Column::TextColorColumnProxy, :text
124
140
  0
125
- when Column::ImageColumnProxy, Column::ImageTextColumnProxy
141
+ when Column::ImageColumnProxy, Column::ImageTextColumnProxy, Column::ImageTextColorColumnProxy
126
142
  1
127
- when Column::CheckboxColumnProxy, Column::CheckboxTextColumnProxy, Column::ProgressBarColumnProxy
143
+ when Column::CheckboxColumnProxy, Column::CheckboxTextColumnProxy, Column::CheckboxTextColorColumnProxy, Column::ProgressBarColumnProxy
128
144
  2
145
+ when Column::BackgroundColorColumnProxy, :color
146
+ 3
129
147
  end
130
148
  end
131
149
  @model_handler.NumRows = fiddle_closure_block_caller(4) { cell_rows.count }
132
150
  @model_handler.CellValue = fiddle_closure_block_caller(1, [1, 1, 4, 4]) do |_, _, row, column|
133
151
  the_cell_rows = expanded_cell_rows
134
152
  case @columns[column]
135
- when Column::TextColumnProxy, Column::ButtonColumnProxy, NilClass
153
+ when Column::TextColumnProxy, Column::ButtonColumnProxy, Column::TextColorColumnProxy, :text
136
154
  ::LibUI.new_table_value_string((expanded_cell_rows[row] && expanded_cell_rows[row][column]).to_s)
137
- when Column::ImageColumnProxy, Column::ImageTextColumnProxy
155
+ when Column::ImageColumnProxy, Column::ImageTextColumnProxy, Column::ImageTextColorColumnProxy
138
156
  ::LibUI.new_table_value_image((expanded_cell_rows[row] && (expanded_cell_rows[row][column].respond_to?(:libui) ? expanded_cell_rows[row][column].libui : expanded_cell_rows[row][column])))
139
- when Column::CheckboxColumnProxy, Column::CheckboxTextColumnProxy
157
+ when Column::CheckboxColumnProxy, Column::CheckboxTextColumnProxy, Column::CheckboxTextColorColumnProxy
140
158
  ::LibUI.new_table_value_int((expanded_cell_rows[row] && (expanded_cell_rows[row][column] == 1 || expanded_cell_rows[row][column].to_s.strip.downcase == 'true' ? 1 : 0)))
141
159
  when Column::ProgressBarColumnProxy
142
160
  ::LibUI.new_table_value_int((expanded_cell_rows[row] && (expanded_cell_rows[row][column].to_i)))
161
+ when Column::BackgroundColorColumnProxy
162
+ background_color = Glimmer::LibUI.interpret_color(expanded_cell_rows[row] && expanded_cell_rows[row][column])
163
+ ::LibUI.new_table_value_color(background_color[:r] / 255.0, background_color[:g] / 255.0, background_color[:b] / 255.0, background_color[:a] || 1.0)
164
+ when :color
165
+ color = Glimmer::LibUI.interpret_color(expanded_cell_rows[row] && expanded_cell_rows[row][column])
166
+ ::LibUI.new_table_value_color(color[:r] / 255.0, color[:g] / 255.0, color[:b] / 255.0, color[:a] || 1.0)
143
167
  end
144
168
  end
145
169
  @model_handler.SetCellValue = fiddle_closure_block_caller(0, [1, 1, 4, 4, 1]) do |_, _, row, column, val|
@@ -148,7 +172,7 @@ module Glimmer
148
172
  column = @columns[column].index
149
173
  @cell_rows[row] ||= []
150
174
  @cell_rows[row][column] = ::LibUI.table_value_string(val).to_s
151
- when NilClass
175
+ when :text
152
176
  column = @columns[column - 1].index
153
177
  @cell_rows[row][column][1] = ::LibUI.table_value_string(val).to_s
154
178
  when Column::ButtonColumnProxy
@@ -158,17 +182,22 @@ module Glimmer
158
182
  @cell_rows[row] ||= []
159
183
  @cell_rows[row][column] = ::LibUI.table_value_int(val).to_i == 1
160
184
  end
185
+ on_changed.each {|listener| listener.call(row, :changed, @cell_rows[row])}
186
+ on_edited.each {|listener| listener.call(row, @cell_rows[row])}
161
187
  end
162
188
 
163
189
  @model = ::LibUI.new_table_model(@model_handler)
164
190
 
191
+ # figure out and reserve column indices for columns
192
+ @columns.each { |column| column.respond_to?(:column_index) && column.column_index }
193
+
165
194
  @table_params = ::LibUI::FFI::TableParams.malloc
166
195
  @table_params.Model = @model
167
- @table_params.RowBackgroundColorModelColumn = -1
196
+ @table_params.RowBackgroundColorModelColumn = @columns.find {|column| column.is_a?(Column::BackgroundColorColumnProxy)}&.column_index || -1
168
197
 
169
198
  @libui = ControlProxy.new_control(@keyword, [@table_params])
170
199
  @libui.tap do
171
- @columns.each {|column| column&.send(:build_control) }
200
+ @columns.each {|column| column.respond_to?(:build_control, true) && column.send(:build_control) }
172
201
  end
173
202
  end
174
203
 
@@ -176,6 +205,16 @@ module Glimmer
176
205
  @next_column_index ||= -1
177
206
  @next_column_index += 1
178
207
  end
208
+
209
+ def array_deep_clone(array_or_object)
210
+ if array_or_object.is_a?(Array)
211
+ array_or_object.map do |element|
212
+ array_deep_clone(element)
213
+ end
214
+ else
215
+ array_or_object.clone
216
+ end
217
+ end
179
218
  end
180
219
  end
181
220
  end
@@ -56,6 +56,7 @@ module Glimmer
56
56
  build_control
57
57
  ::LibUI.draw_text(area_draw_params[:context], @libui, x, y)
58
58
  ::LibUI.draw_free_text_layout(@libui)
59
+ ::LibUI.free_attributed_string(@attributed_string)
59
60
  end
60
61
 
61
62
  def destroy
@@ -89,7 +90,7 @@ module Glimmer
89
90
 
90
91
  def width(value = nil)
91
92
  if value.nil?
92
- @width ||= args[2] || (AreaProxy.current_area_draw_params && AreaProxy.current_area_draw_params[:area_width])
93
+ @width ||= args[2] || (AreaProxy.current_area_draw_params && (AreaProxy.current_area_draw_params[:area_width] - 2*x))
93
94
  else
94
95
  @width = value
95
96
  redraw
@@ -0,0 +1,45 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module Glimmer
23
+ module LibUI
24
+ class ControlProxy
25
+ # A dual column is one that represents two values (e.g. image and text or checkbox and text)
26
+ # It is meant to be included in a column proxy class that already includes Column
27
+ module TripleColumn
28
+ def second_column_index
29
+ column_index + 1
30
+ end
31
+
32
+ def third_column_index
33
+ column_index + 2
34
+ end
35
+
36
+ def column_index
37
+ @column_index ||= @parent_proxy.send(:next_column_index).tap do
38
+ @parent_proxy.send(:next_column_index)
39
+ @parent_proxy.send(:next_column_index)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-06 00:00:00.000000000 Z
11
+ date: 2021-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.2
19
+ version: 2.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.2
26
+ version: 2.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: os
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -222,6 +222,7 @@ files:
222
222
  - examples/basic_table_button.rb
223
223
  - examples/basic_table_checkbox.rb
224
224
  - examples/basic_table_checkbox_text.rb
225
+ - examples/basic_table_color.rb
225
226
  - examples/basic_table_image.rb
226
227
  - examples/basic_table_image_text.rb
227
228
  - examples/basic_table_progress_bar.rb
@@ -249,6 +250,7 @@ files:
249
250
  - examples/simple_notepad.rb
250
251
  - examples/timer.rb
251
252
  - glimmer-dsl-libui.gemspec
253
+ - icons/glimmer.png
252
254
  - lib/glimmer-dsl-libui.rb
253
255
  - lib/glimmer/dsl/libui/control_expression.rb
254
256
  - lib/glimmer/dsl/libui/dsl.rb
@@ -273,12 +275,16 @@ files:
273
275
  - lib/glimmer/libui/control_proxy/checkbox_proxy.rb
274
276
  - lib/glimmer/libui/control_proxy/color_button_proxy.rb
275
277
  - lib/glimmer/libui/control_proxy/column.rb
278
+ - lib/glimmer/libui/control_proxy/column/background_color_column_proxy.rb
276
279
  - lib/glimmer/libui/control_proxy/column/button_column_proxy.rb
277
280
  - lib/glimmer/libui/control_proxy/column/checkbox_column_proxy.rb
281
+ - lib/glimmer/libui/control_proxy/column/checkbox_text_color_column_proxy.rb
278
282
  - lib/glimmer/libui/control_proxy/column/checkbox_text_column_proxy.rb
279
283
  - lib/glimmer/libui/control_proxy/column/image_column_proxy.rb
284
+ - lib/glimmer/libui/control_proxy/column/image_text_color_column_proxy.rb
280
285
  - lib/glimmer/libui/control_proxy/column/image_text_column_proxy.rb
281
286
  - lib/glimmer/libui/control_proxy/column/progress_bar_column_proxy.rb
287
+ - lib/glimmer/libui/control_proxy/column/text_color_column_proxy.rb
282
288
  - lib/glimmer/libui/control_proxy/column/text_column_proxy.rb
283
289
  - lib/glimmer/libui/control_proxy/combobox_proxy.rb
284
290
  - lib/glimmer/libui/control_proxy/date_time_picker_proxy.rb
@@ -312,12 +318,15 @@ files:
312
318
  - lib/glimmer/libui/control_proxy/message_box/msg_box_proxy.rb
313
319
  - lib/glimmer/libui/control_proxy/multiline_entry_proxy.rb
314
320
  - lib/glimmer/libui/control_proxy/multiline_entry_proxy/non_wrapping_multiline_entry_proxy.rb
321
+ - lib/glimmer/libui/control_proxy/open_type_features_proxy.rb
322
+ - lib/glimmer/libui/control_proxy/open_type_tag_proxy.rb
315
323
  - lib/glimmer/libui/control_proxy/path_proxy.rb
316
324
  - lib/glimmer/libui/control_proxy/radio_buttons_proxy.rb
317
325
  - lib/glimmer/libui/control_proxy/tab_item_proxy.rb
318
326
  - lib/glimmer/libui/control_proxy/table_proxy.rb
319
327
  - lib/glimmer/libui/control_proxy/text_proxy.rb
320
328
  - lib/glimmer/libui/control_proxy/transformable.rb
329
+ - lib/glimmer/libui/control_proxy/triple_column.rb
321
330
  - lib/glimmer/libui/control_proxy/window_proxy.rb
322
331
  - lib/glimmer/libui/parent.rb
323
332
  - lib/glimmer/libui/shape.rb