glimmer-dsl-libui 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c673025a7a4676538178064f6fb3db7c98eb35f2c2b8c0bf7eb75627d4810309
4
- data.tar.gz: b3c7a7c67edc0566e542cbdad854a5340cba70c61ac36611a5279095b7710248
3
+ metadata.gz: 33e2f34a434ea4036e788ae6fee9b2329220f53b002357c5447cdf6d2421959b
4
+ data.tar.gz: d38442e11122157bb2aa1db6a7881a3bc0e353c40842ccfdc823a357cdf9a16e
5
5
  SHA512:
6
- metadata.gz: 49254ae087358b968b0479dd4ccc1909e03e532e8ad3671432dedd96079d7487f9fb7bdfd3f3f20edd53475389e0553b4676f7fceacd04b130444914254afcd9
7
- data.tar.gz: f40187fed7f069bf214c16b287b87848e9815a79c72ddb78dd47f9df567d40ceef432dc800ba74ee7247d6f1a0a32e81b65d863e860f2ccec7ea6c20d11a97eb
6
+ metadata.gz: c0c9657f2d68852873bdbf8a294816a2bc684e5ca902e8c9c1d43d43ed0e313850ef127176470b29df0c000a4fe65465cc58948c0cfcdc182eef569c978fd72a
7
+ data.tar.gz: b13df322764b9bd8e4fd2259992d2eff0abe2ed1f4e7e144deb8d15d56ddaccd6eaaa78fa40715eaff89dddbd201a4a9f2f6d77fd9ab8692cbf325043161510e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.7
4
+
5
+ - New examples/basic_table_color.rb
6
+ - Support `background_color_column` for `table`
7
+ - Support `text_color_column` for `table`
8
+ - Support `checkbox_text_color_column` for `table`
9
+ - Support `image_text_color_column` for `table`
10
+
3
11
  ## 0.2.6
4
12
 
5
13
  - Support `string` control property: `open_type_features`
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.6
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.7
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.6](#-glimmer-dsl-for-libui-026)
200
+ - [Glimmer DSL for LibUI 0.2.7](#-glimmer-dsl-for-libui-027)
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.6'
337
+ gem 'glimmer-dsl-libui', '~> 0.2.7'
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
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 | None
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.
@@ -798,10 +809,10 @@ To draw `text` in an `area`, you simply nest a `text(x, y, width)` control direc
798
809
 
799
810
  `string` can have the following properties:
800
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
801
- - `color`: rgba, hex, or x11 color
802
- - `background`: rgba, hex, or x11 color
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
803
814
  - `underline`: one of `:none`, `:single`, `:double`, `:suggestion`, `:color_custom`, `:color_spelling`, `:color_grammar`, `:color_auxiliary`
804
- - `underline_color`: one of `:spelling`, `:grammar`, `:auxiliary`, rgba, hex, or x11 color
815
+ - `underline_color`: one of `:spelling`, `:grammar`, `:auxiliary`, rgba, hex, or [X11](https://en.wikipedia.org/wiki/X11_color_names) color
805
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.
806
817
 
807
818
  Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
@@ -875,7 +886,7 @@ window('area text drawing') {
875
886
 
876
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`).
877
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).
878
- - 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)
879
890
 
880
891
  ### Original API
881
892
 
@@ -2584,7 +2595,7 @@ window('Editable column animal sounds', 400, 200) {
2584
2595
 
2585
2596
  ### Basic Table Image
2586
2597
 
2587
- This example has a prerequisite of installing `chunky_png` Ruby gem:
2598
+ This example requires pre-installing `chunky_png` Ruby gem:
2588
2599
 
2589
2600
  ```
2590
2601
  gem install chunky_png -v1.4.0
@@ -3041,6 +3052,78 @@ window('Task Progress', 300, 200) {
3041
3052
  }.show
3042
3053
  ```
3043
3054
 
3055
+ ### Basic Table Color
3056
+
3057
+ This example requires pre-installing `chunky_png` Ruby gem:
3058
+
3059
+ ```
3060
+ gem install chunky_png -v1.4.0
3061
+ ```
3062
+
3063
+ [examples/basic_table_color.rb](examples/basic_table_color.rb)
3064
+
3065
+ Run with this command from the root of the project if you cloned the project:
3066
+
3067
+ ```
3068
+ ruby -r './lib/glimmer-dsl-libui' examples/basic_table_color.rb
3069
+ ```
3070
+
3071
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
3072
+
3073
+ ```
3074
+ ruby -r glimmer-dsl-libui -e "require 'examples/basic_table_color'"
3075
+ ```
3076
+
3077
+ Mac
3078
+
3079
+ ![glimmer-dsl-libui-mac-basic-table-color.png](images/glimmer-dsl-libui-mac-basic-table-color.png)
3080
+
3081
+ Linux
3082
+
3083
+ ![glimmer-dsl-libui-linux-basic-table-color.png](images/glimmer-dsl-libui-linux-basic-table-color.png)
3084
+
3085
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
3086
+
3087
+ ```ruby
3088
+ require 'glimmer-dsl-libui'
3089
+ require 'chunky_png'
3090
+
3091
+ include Glimmer
3092
+
3093
+ f = File.open(File.expand_path('../icons/glimmer.png', __dir__))
3094
+ canvas = ChunkyPNG::Canvas.from_io(f)
3095
+ f.close
3096
+ canvas.resample_nearest_neighbor!(24, 24)
3097
+ data = canvas.to_rgba_stream
3098
+ width = canvas.width
3099
+ height = canvas.height
3100
+ img = image {
3101
+ image_part(data, width, height, width * 4)
3102
+ }
3103
+
3104
+ data = [
3105
+ [['cat', :red] , ['meow', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], {r: 255, g: 120, b: 0, a: 0.5}],
3106
+ [['dog', :yellow] , ['woof', {r: 240, g: 32, b: 32}] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], :skyblue],
3107
+ [['chicken', :beige], ['cock-a-doodle-doo', :blue] , [false, 'mammal', :red] , [img, 'Glimmer', :beige], {r: 5, g: 120, b: 110}],
3108
+ [['horse', :purple] , ['neigh', {r: 240, g: 32, b: 32}], [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], '13a1fb'],
3109
+ [['cow', :gray] , ['moo', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :brown], 0x12ff02]
3110
+ ]
3111
+
3112
+ window('Animals', 500, 200) {
3113
+ horizontal_box {
3114
+ table {
3115
+ text_color_column('Animal')
3116
+ text_color_column('Sound')
3117
+ checkbox_text_color_column('Description')
3118
+ image_text_color_column('GUI')
3119
+ background_color_column('Mammal')
3120
+
3121
+ cell_rows data
3122
+ }
3123
+ }
3124
+ }.show
3125
+ ```
3126
+
3044
3127
  ### Form Table
3045
3128
 
3046
3129
  [examples/form_table.rb](examples/form_table.rb)
@@ -5441,11 +5524,11 @@ class CustomDrawText
5441
5524
  text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
5442
5525
  # align :left # default alignment
5443
5526
 
5444
- @string = string {
5445
- font @font unless @font.nil?
5446
- color @color unless @color.nil?
5447
- background @background unless @background.nil?
5448
- underline @underline unless @underline.nil?
5527
+ string {
5528
+ font @font
5529
+ color @color
5530
+ background @background
5531
+ underline @underline
5449
5532
 
5450
5533
  ' At last Ygramul sensed that something was coming toward ' \
5451
5534
  'her. With the speed of lightning, she turned about, confronting ' \
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.2.7
@@ -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
Binary file
data/icons/glimmer.png ADDED
Binary file
@@ -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
@@ -58,8 +58,16 @@ module Glimmer
58
58
 
59
59
  def post_initialize_child(child)
60
60
  @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)
61
+ # add extra complementary columns (:text, :color) if it is a dual/triple column (i.e. ImageTextColumnProxy or CheckboxTextColumnProxy
62
+ case child
63
+ when Column::ImageTextColumnProxy, Column::CheckboxTextColumnProxy
64
+ @columns << :text
65
+ when Column::TextColorColumnProxy
66
+ @columns << :color
67
+ when Column::CheckboxTextColorColumnProxy, Column::ImageTextColorColumnProxy
68
+ @columns << :text
69
+ @columns << :color
70
+ end
63
71
  end
64
72
 
65
73
  def destroy
@@ -119,27 +127,36 @@ module Glimmer
119
127
  @model_handler = ::LibUI::FFI::TableModelHandler.malloc
120
128
  @model_handler.NumColumns = fiddle_closure_block_caller(4) { @columns.map {|c| c.is_a?(DualColumn) ? 2 : 1}.sum }
121
129
  @model_handler.ColumnType = fiddle_closure_block_caller(4, [1, 1, 4]) do |_, _, column|
130
+ # TODO consider refactoring to use Glimmer::LibUI.enum_symbols(:table_value_type)
122
131
  case @columns[column]
123
- when Column::TextColumnProxy, Column::ButtonColumnProxy, NilClass
132
+ when Column::TextColumnProxy, Column::ButtonColumnProxy, Column::TextColorColumnProxy, :text
124
133
  0
125
- when Column::ImageColumnProxy, Column::ImageTextColumnProxy
134
+ when Column::ImageColumnProxy, Column::ImageTextColumnProxy, Column::ImageTextColorColumnProxy
126
135
  1
127
- when Column::CheckboxColumnProxy, Column::CheckboxTextColumnProxy, Column::ProgressBarColumnProxy
136
+ when Column::CheckboxColumnProxy, Column::CheckboxTextColumnProxy, Column::CheckboxTextColorColumnProxy, Column::ProgressBarColumnProxy
128
137
  2
138
+ when Column::BackgroundColorColumnProxy, :color
139
+ 3
129
140
  end
130
141
  end
131
142
  @model_handler.NumRows = fiddle_closure_block_caller(4) { cell_rows.count }
132
143
  @model_handler.CellValue = fiddle_closure_block_caller(1, [1, 1, 4, 4]) do |_, _, row, column|
133
144
  the_cell_rows = expanded_cell_rows
134
145
  case @columns[column]
135
- when Column::TextColumnProxy, Column::ButtonColumnProxy, NilClass
146
+ when Column::TextColumnProxy, Column::ButtonColumnProxy, Column::TextColorColumnProxy, :text
136
147
  ::LibUI.new_table_value_string((expanded_cell_rows[row] && expanded_cell_rows[row][column]).to_s)
137
- when Column::ImageColumnProxy, Column::ImageTextColumnProxy
148
+ when Column::ImageColumnProxy, Column::ImageTextColumnProxy, Column::ImageTextColorColumnProxy
138
149
  ::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
150
+ when Column::CheckboxColumnProxy, Column::CheckboxTextColumnProxy, Column::CheckboxTextColorColumnProxy
140
151
  ::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
152
  when Column::ProgressBarColumnProxy
142
153
  ::LibUI.new_table_value_int((expanded_cell_rows[row] && (expanded_cell_rows[row][column].to_i)))
154
+ when Column::BackgroundColorColumnProxy
155
+ background_color = Glimmer::LibUI.interpret_color(expanded_cell_rows[row] && expanded_cell_rows[row][column])
156
+ ::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)
157
+ when :color
158
+ color = Glimmer::LibUI.interpret_color(expanded_cell_rows[row] && expanded_cell_rows[row][column])
159
+ ::LibUI.new_table_value_color(color[:r] / 255.0, color[:g] / 255.0, color[:b] / 255.0, color[:a] || 1.0)
143
160
  end
144
161
  end
145
162
  @model_handler.SetCellValue = fiddle_closure_block_caller(0, [1, 1, 4, 4, 1]) do |_, _, row, column, val|
@@ -148,7 +165,7 @@ module Glimmer
148
165
  column = @columns[column].index
149
166
  @cell_rows[row] ||= []
150
167
  @cell_rows[row][column] = ::LibUI.table_value_string(val).to_s
151
- when NilClass
168
+ when :text
152
169
  column = @columns[column - 1].index
153
170
  @cell_rows[row][column][1] = ::LibUI.table_value_string(val).to_s
154
171
  when Column::ButtonColumnProxy
@@ -162,13 +179,16 @@ module Glimmer
162
179
 
163
180
  @model = ::LibUI.new_table_model(@model_handler)
164
181
 
182
+ # figure out and reserve column indices for columns
183
+ @columns.each { |column| column.respond_to?(:column_index) && column.column_index }
184
+
165
185
  @table_params = ::LibUI::FFI::TableParams.malloc
166
186
  @table_params.Model = @model
167
- @table_params.RowBackgroundColorModelColumn = -1
187
+ @table_params.RowBackgroundColorModelColumn = @columns.find {|column| column.is_a?(Column::BackgroundColorColumnProxy)}&.column_index || -1
168
188
 
169
189
  @libui = ControlProxy.new_control(@keyword, [@table_params])
170
190
  @libui.tap do
171
- @columns.each {|column| column&.send(:build_control) }
191
+ @columns.each {|column| column.respond_to?(:build_control, true) && column.send(:build_control) }
172
192
  end
173
193
  end
174
194
 
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
@@ -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
@@ -320,6 +326,7 @@ files:
320
326
  - lib/glimmer/libui/control_proxy/table_proxy.rb
321
327
  - lib/glimmer/libui/control_proxy/text_proxy.rb
322
328
  - lib/glimmer/libui/control_proxy/transformable.rb
329
+ - lib/glimmer/libui/control_proxy/triple_column.rb
323
330
  - lib/glimmer/libui/control_proxy/window_proxy.rb
324
331
  - lib/glimmer/libui/parent.rb
325
332
  - lib/glimmer/libui/shape.rb