glimmer-dsl-libui 0.2.4 → 0.2.8

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: 65d8bf2e6e00eeece96482279bc7dedb367ee21f4a88dd8b96869ff78e051e2f
4
- data.tar.gz: 3b3ca0d276675e9787a22f8318089bf4d88f3fea1df0d225d024a1037f63d5fc
3
+ metadata.gz: c97e75e5d70341821d3b41fe832ae7efe1c70713ad673576a8498c4a3cd4ce70
4
+ data.tar.gz: 46fab85f1c845963a823a4e894987914dfbff128122db19b7ae4a82766f43044
5
5
  SHA512:
6
- metadata.gz: 00a8a549d4aa8c13fe2824f2fda437d6de675b02108ac3e6196c149db02ee0fd48a6ff11e509155eecf512a9ae66e89c60b850cd99cae44ad1302c1533405330
7
- data.tar.gz: 9432f12897bad09cbaf9b72077d15968bc87852a35055e083923779ad311ef5b1221e1a9e1382f7623c0a1524540d98e2e20e91583530facaac5d505cece357c
6
+ metadata.gz: 9aa8032624bfdca1b1dcdb399e16eb2246244f09d48cf476e20a35ce58b2d2b0e6bba34defb810a8265a1c838422fecffd09f568aabb797c7d5ba93c6ffed93d
7
+ data.tar.gz: 63206e935531bf431b417925fc4c569d685e6acbfc06e73d8231b7f53f60751bab0797ddfdd9580ca85d4cbc9d27e80b23b0bebccafa554ab988130e17478fe5
data/CHANGELOG.md CHANGED
@@ -1,12 +1,35 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.8
4
+
5
+ - Support `table` `on_changed` listener to report all changes (of operation type `:deleted`, `:changed`, `:inserted`)
6
+ - Support `table` `on_edited` listener to report changes happening through direct table editing only
7
+ - Default value of `text` `width` argument looks into x and adjusts by leaving the same space on the right side
8
+
9
+ ## 0.2.7
10
+
11
+ - New examples/basic_table_color.rb
12
+ - Support `background_color_column` for `table`
13
+ - Support `text_color_column` for `table`
14
+ - Support `checkbox_text_color_column` for `table`
15
+ - Support `image_text_color_column` for `table`
16
+
17
+ ## 0.2.6
18
+
19
+ - Support `string` control property: `open_type_features`
20
+ - Auto-free attributed string objects from memory
21
+
22
+ ## 0.2.5
23
+
24
+ - Support attributed `string` `underline_color` property (built-in enum symbols and custom color)
25
+
3
26
  ## 0.2.4
4
27
 
5
28
  - Support examples/custom_draw_text.rb
6
29
  - Support stable `text` control nestable under `area`
7
- - Support `string` control property `background`
8
- - Support `string` control property `font`
9
- - Support `string` control property `underline`
30
+ - Support `string` control property: `background`
31
+ - Support `string` control property: `font`
32
+ - Support `string` control property: `underline`
10
33
  - Enhance `combobox` to accept `String` value for `selected` item instead of just `Integer` index
11
34
  - Add `selected_item` read-only property to `combobox` to return selected item `String` value
12
35
  - Fix `color` property support for `string` to accept 255-based rgb values
@@ -19,7 +42,7 @@
19
42
  - Support dynamic `text` control to be called in `area` `on_draw` listener
20
43
  - Support `text` control `default_font` property
21
44
  - Support `string` control nestable under `text` to represent an attributed/unattributed string (depending on nestable properties)
22
- - Support `string` control property `color`
45
+ - Support `string` control property: `color`
23
46
  - Support enum symbols for `align` property of `text` control
24
47
  - Support enum symbols for `:italic` font descriptor key (in addition to numbers)
25
48
  - 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.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.8
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)
@@ -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.4](#-glimmer-dsl-for-libui-024)
200
+ - [Glimmer DSL for LibUI 0.2.8](#-glimmer-dsl-for-libui-028)
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.4'
337
+ gem 'glimmer-dsl-libui', '~> 0.2.8'
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
@@ -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
@@ -5260,7 +5403,7 @@ class CustomDrawText
5260
5403
  include Glimmer
5261
5404
 
5262
5405
  def launch
5263
- window('Michael Ende (1929-1995) The Neverending Story', 600, 400) {
5406
+ window('Michael Ende (1929-1995) The Neverending Story', 600, 500) {
5264
5407
  margined true
5265
5408
 
5266
5409
  vertical_box {
@@ -5349,7 +5492,7 @@ class CustomDrawText
5349
5492
  include Glimmer
5350
5493
 
5351
5494
  def launch
5352
- window('Michael Ende (1929-1995) The Neverending Story', 600, 400) {
5495
+ window('Michael Ende (1929-1995) The Neverending Story', 600, 500) {
5353
5496
  margined true
5354
5497
 
5355
5498
  vertical_box {
@@ -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.4
1
+ 0.2.8
@@ -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
@@ -7,7 +7,7 @@ class CustomDrawText
7
7
  include Glimmer
8
8
 
9
9
  def launch
10
- window('Michael Ende (1929-1995) The Neverending Story', 600, 400) {
10
+ window('Michael Ende (1929-1995) The Neverending Story', 600, 500) {
11
11
  margined true
12
12
 
13
13
  vertical_box {
@@ -44,12 +44,34 @@ class CustomDrawText
44
44
  @string.underline = c.selected_item.underscore
45
45
  end
46
46
  }
47
+ combobox { |c|
48
+ label 'Underline Built-In Color'
49
+ items Glimmer::LibUI.enum_symbols(:underline_color).map(&:to_s).map(&:capitalize)
50
+ selected 'Custom'
51
+
52
+ on_selected do
53
+ @underline_custom_color_button.enabled = c.selected_item == 'Custom'
54
+ if c.selected_item == 'Custom'
55
+ @string.underline_color = @underline_custom_color_button.color
56
+ else
57
+ @string.underline_color = c.selected_item.underscore
58
+ @underline_custom_color_button.color = :black
59
+ end
60
+ end
61
+ }
62
+ @underline_custom_color_button = color_button {
63
+ label 'Underline Custom Color'
64
+
65
+ on_changed do
66
+ @string.underline_color = @underline_custom_color_button.color
67
+ end
68
+ }
47
69
  }
48
70
 
49
71
  area {
50
- 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)
51
73
  # align :left # default alignment
52
-
74
+
53
75
  @string = string {
54
76
  ' At last Ygramul sensed that something was coming toward ' \
55
77
  'her. With the speed of lightning, she turned about, confronting ' \
@@ -7,7 +7,7 @@ class CustomDrawText
7
7
  include Glimmer
8
8
 
9
9
  def launch
10
- window('Michael Ende (1929-1995) The Neverending Story', 600, 400) {
10
+ window('Michael Ende (1929-1995) The Neverending Story', 600, 500) {
11
11
  margined true
12
12
 
13
13
  vertical_box {
@@ -48,18 +48,43 @@ class CustomDrawText
48
48
  @area.queue_redraw_all
49
49
  end
50
50
  }
51
+ combobox { |c|
52
+ label 'Underline Built-In Color'
53
+ items Glimmer::LibUI.enum_symbols(:underline_color).map(&:to_s).map(&:capitalize)
54
+ selected 'Custom'
55
+
56
+ on_selected do
57
+ @underline_custom_color_button.enabled = c.selected_item == 'Custom'
58
+ if c.selected_item == 'Custom'
59
+ @underline_color = @underline_custom_color_button.color
60
+ else
61
+ @underline_color = c.selected_item.underscore
62
+ @underline_custom_color_button.color = :black
63
+ end
64
+ @area.queue_redraw_all
65
+ end
66
+ }
67
+ @underline_custom_color_button = color_button {
68
+ label 'Underline Custom Color'
69
+
70
+ on_changed do
71
+ @underline_color = @underline_custom_color_button.color
72
+ @area.queue_redraw_all
73
+ end
74
+ }
51
75
  }
52
76
 
53
77
  @area = area {
54
78
  on_draw do |area_draw_params|
55
- 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)
56
80
  # align :left # default alignment
57
81
 
58
- @string = string {
82
+ string {
59
83
  font @font
60
84
  color @color
61
85
  background @background
62
86
  underline @underline
87
+ underline_color @underline_color
63
88
 
64
89
  ' At last Ygramul sensed that something was coming toward ' \
65
90
  'her. With the speed of lightning, she turned about, confronting ' \
@@ -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
@@ -70,7 +70,7 @@ module Glimmer
70
70
  end
71
71
  end
72
72
  alias background= background
73
- alias background background
73
+ alias set_background background
74
74
 
75
75
  def underline(value = nil)
76
76
  if value.nil?
@@ -81,7 +81,29 @@ module Glimmer
81
81
  end
82
82
  end
83
83
  alias underline= underline
84
- alias underline underline
84
+ alias set_underline underline
85
+
86
+ def underline_color(value = nil)
87
+ if value.nil?
88
+ @underline_color
89
+ else
90
+ @underline_color = value
91
+ redraw
92
+ end
93
+ end
94
+ alias underline_color= underline_color
95
+ alias set_underline_color underline_color
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
85
107
 
86
108
  def post_add_content
87
109
  block_result = block&.call
@@ -89,6 +111,10 @@ module Glimmer
89
111
  @parent_proxy&.post_initialize_child(self)
90
112
  end
91
113
 
114
+ def post_initialize_child(child)
115
+ self.open_type_features = child if child.is_a?(Glimmer::LibUI::ControlProxy::OpenTypeFeaturesProxy)
116
+ end
117
+
92
118
  def draw(area_draw_params)
93
119
  @start = ::LibUI.attributed_string_len(@parent_proxy.attributed_string)
94
120
  ::LibUI.attributed_string_append_unattributed(@parent_proxy.attributed_string, @string)
@@ -104,6 +130,16 @@ module Glimmer
104
130
  underline_attribute = ::LibUI.new_underline_attribute(Glimmer::LibUI.enum_symbol_to_value(:underline, @underline))
105
131
  ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, underline_attribute, @start, @start + @string.size)
106
132
  end
133
+ unless underline_color.nil?
134
+ if Glimmer::LibUI.enum_symbols(:underline_color).include?(underline_color.to_s.to_sym) && underline_color.to_s.to_sym != :custom
135
+ underline_color_attribute = ::LibUI.new_underline_color_attribute(Glimmer::LibUI.enum_symbol_to_value(:underline_color, @underline_color), 0, 0, 0, 0)
136
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, underline_color_attribute, @start, @start + @string.size)
137
+ else
138
+ the_color = Glimmer::LibUI.interpret_color(@underline_color)
139
+ underline_color_attribute = ::LibUI.new_underline_color_attribute(0, the_color[:r].to_f / 255.0, the_color[:g].to_f / 255.0, the_color[:b].to_f / 255.0, the_color[:a] || 1.0)
140
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, underline_color_attribute, @start, @start + @string.size)
141
+ end
142
+ end
107
143
  unless font.nil?
108
144
  family_attribute = ::LibUI.new_family_attribute(font[:family])
109
145
  ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, family_attribute, @start, @start + @string.size)
@@ -116,10 +152,15 @@ module Glimmer
116
152
  stretch_attribute = ::LibUI.new_stretch_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_stretch, font[:stretch]))
117
153
  ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, stretch_attribute, @start, @start + @string.size)
118
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
119
159
  destroy if area_proxy.nil?
120
160
  end
121
161
 
122
162
  def destroy
163
+ open_type_features.destroy unless open_type_features.nil?
123
164
  @parent_proxy&.children&.delete(self)
124
165
  end
125
166
 
@@ -51,6 +51,8 @@ module Glimmer
51
51
  ::LibUI.color_button_set_color(@libui, value[:r].to_f / 255.0, value[:g].to_f / 255.0, value[:b].to_f / 255.0, value[:a])
52
52
  end
53
53
  end
54
+ alias color= color
55
+ alias set_color color
54
56
 
55
57
  def red(value = nil)
56
58
  if value.nil?
@@ -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
@@ -78,14 +88,19 @@ module Glimmer
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
106
  @last_cell_rows = @cell_rows.clone
@@ -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
 
@@ -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.4
4
+ version: 0.2.8
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
@@ -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