glimmer-dsl-libui 0.3.0 → 0.3.1

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: 82c9b768b4dd09cbbad087d470016eaa80a667151f844a57aecf4c339d8bbfe5
4
- data.tar.gz: 4c4b1a1fec0c78d61cb7d47ce79d93766f2ec3c94e2332e185e44b35ecd9dfd8
3
+ metadata.gz: 74fca1540788e27b3b5086a888b83f0fe13e296c54eb6faf4ed244ee8e659484
4
+ data.tar.gz: 0ce0c22598269dea07489049462f3b94a16e75fc68dcb1fc61f69f1ad66686a0
5
5
  SHA512:
6
- metadata.gz: abd5077dd154505ac5b97986baace9c72d61a734515f39cb9213161fbd16dff85e46af725b702edfc87fae6043288f4897b53b8c1d0671dc509e0c3ce3b222b2
7
- data.tar.gz: cb2273302f43a0b4e2543ac75c08a51414013d50600d5ccf51406799fba6122ca5144cf8a26c018a594d8e8238e899976c9f8a4a0b00505be954164095726b16
6
+ metadata.gz: e449f830e5cdf53aae5bcd490644b5f6611f080353f455a833b17c75dc2f2dd3feacac53fc584aff06d38f7b6f9665b423818d81f6e42523b0549ac029269170
7
+ data.tar.gz: 78eb5db52c86d37166f32a91fee303d6cbd3ba91e9add0cd97c6ff6db14d85348a947fdf53bfd9e254a66bff819308844eb9669ebd7affe3c9d7c46cc08729f4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.3.1
4
+
5
+ - Support building `image_column` `image` objects in a `table` via `file` property (simplify through automation of use of `image_part` for `.png` image files given that `chunky_png` is now included in the gem)
6
+ - Support Web URL as `image` control `file` property
7
+ - Add `key_code` as alias to `key_value` in `area_key_event` `Hash`
8
+ - Fix issue with editing `text_color_column` in `table` having `editable true` property
9
+ - Fix issue with editing `checkbox_text_column` text in `table` having `editable true` or `editable_text true` property
10
+
3
11
  ## 0.3.0
4
12
 
5
13
  - Upgrade to glimmer 2.4.1
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.3.0
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.3.1
2
2
  ## Prerequisite-Free Ruby Desktop Development GUI Library
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-libui.svg)](http://badge.fury.io/rb/glimmer-dsl-libui)
4
4
  [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@@ -238,7 +238,14 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
238
238
  - [Extra Operations](#extra-operations)
239
239
  - [Table API](#table-api)
240
240
  - [Area API](#area-api)
241
- - [Image Glimmer Custom Control](#image-glimmer-custom-control)
241
+ - [Area Path Shapes](#area-path-shapes)
242
+ - [Area Text](#area-text)
243
+ - [Area Image](#area-image)
244
+ - [Colors](#colors)
245
+ - [Area Draw Params](#area-draw-params)
246
+ - [Area Listeners](#area-listeners)
247
+ - [Area Methods/Attributes](#area-methods-attributes)
248
+ - [Area Transform Matrix](#area-transform-matrix)
242
249
  - [Smart Defaults and Conventions](#smart-defaults-and-conventions)
243
250
  - [Custom Keywords](#custom-keywords)
244
251
  - [API Gotchas](#api-gotchas)
@@ -375,7 +382,7 @@ gem install glimmer-dsl-libui
375
382
  Or install via Bundler `Gemfile`:
376
383
 
377
384
  ```ruby
378
- gem 'glimmer-dsl-libui', '~> 0.3.0'
385
+ gem 'glimmer-dsl-libui', '~> 0.3.1'
379
386
  ```
380
387
 
381
388
  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.
@@ -446,8 +453,6 @@ w.libui # => #<Fiddle::Pointer:0x00007fde53997980 ptr=0x00007fde51352a60 size=0
446
453
 
447
454
  ### Supported Keywords
448
455
 
449
- These are all the supported keywords. Note that some keywords do not represent controls, but produce objects that are used as the property values of controls (e.g. `image` builds objects to use in `cell_rows` for a `table` with an image column)
450
-
451
456
  Keyword(Args) | Properties | Listeners
452
457
  ------------- | ---------- | ---------
453
458
  `about_menu_item` | None | `on_clicked`
@@ -719,6 +724,8 @@ The `area` control is a canvas-like control for drawing paths that can be used i
719
724
  - Declaratively via stable paths: useful for stable paths that will not change often later on. Simply nest `path` and figures like `rectangle` and all drawing logic is generated automatically. Path proxy objects are preserved across redraws assuming there would be relatively few stable paths (mostly for decorative reasons).
720
725
  - Semi-declaratively via on_draw listener dynamic paths: useful for more dynamic paths that will definitely change very often. Open an `on_draw` listener block that receives a `area_draw_params` argument and nest `path` and figures like `rectangle` and all drawing logic is generated automatically. Path proxy objects are destroyed (thrown-away) at the end of drawing, thus having less memory overhead for drawing thousands of dynamic paths.
721
726
 
727
+ Note that when nesting an `area` directly underneath `window` (without a layout control like `vertical_box`), it is automatically reparented with `vertical_box` in between the `window` and `area` since it would not show up on Linux otherwise.
728
+
722
729
  Here is an example of a declarative `area` with a stable path (you may copy/paste in [`girb`](#girb-glimmer-irb)):
723
730
 
724
731
  ```ruby
@@ -741,8 +748,18 @@ window('Basic Area', 400, 400) {
741
748
  }.show
742
749
  ```
743
750
 
751
+ Mac
752
+
744
753
  ![glimmer-dsl-libui-mac-basic-area.png](images/glimmer-dsl-libui-mac-basic-area.png)
745
754
 
755
+ Windows
756
+
757
+ ![glimmer-dsl-libui-windows-basic-area.png](images/glimmer-dsl-libui-windows-basic-area.png)
758
+
759
+ Linux
760
+
761
+ ![glimmer-dsl-libui-linux-basic-area.png](images/glimmer-dsl-libui-linux-basic-area.png)
762
+
746
763
  Here is the same example using a semi-declarative `area` with `on_draw` listener that receives a `area_draw_params` argument and a dynamic path (you may copy/paste in [`girb`](#girb-glimmer-irb)):
747
764
 
748
765
  ```ruby
@@ -769,6 +786,8 @@ window('Basic Area', 400, 400) {
769
786
 
770
787
  Check [examples/dynamic_area.rb](#dynamic-area) for a more detailed semi-declarative example.
771
788
 
789
+ #### Area Path Shapes
790
+
772
791
  `path` can receive a `draw_fill_mode` argument that can accept values `:winding` or `:alternate` and defaults to `:winding`.
773
792
 
774
793
  Available nested `path` shapes:
@@ -784,136 +803,19 @@ Available nested `path` shapes:
784
803
 
785
804
  Check [examples/area_gallery.rb](#area-gallery) for an overiew of all `path` shapes.
786
805
 
787
- The `area_draw_params` argument for `on_draw` block is a hash consisting of the following keys:
788
- - `:context`: the drawing context object
789
- - `:area_width`: area width
790
- - `:area_height`: area height
791
- - `:clip_x`: clip region top-left x coordinate
792
- - `:clip_y`: clip region top-left y coordinate
793
- - `:clip_width`: clip region width
794
- - `:clip_height`: clip region height
795
-
796
- In general, it is recommended to use declarative stable paths whenever feasible since they require less code and simpler maintenance. But, in more advanced cases, semi-declarative dynamic paths could be used instead, especially if there are thousands of dynamic paths that need maximum performance and low memory footprint.
797
-
798
- `area` supported mouse listeners are:
799
- - `on_key_event {|area_key_event| ...}`: general catch-all key event (recommend using fine-grained key events below instead)
800
- - `on_key_down {|area_key_event| ...}`
801
- - `on_key_up {|area_key_event| ...}`
802
- - `on_mouse_event {|area_mouse_event| ...}`: general catch-all mouse event (recommend using fine-grained mouse events below instead)
803
- - `on_mouse_down {|area_mouse_event| ...}`
804
- - `on_mouse_up {|area_mouse_event| ...}`
805
- - `on_mouse_drag_started {|area_mouse_event| ...}`
806
- - `on_mouse_dragged {|area_mouse_event| ...}`
807
- - `on_mouse_dropped {|area_mouse_event| ...}`
808
- - `on_mouse_entered {...}`
809
- - `on_mouse_exited {...}`
810
- - `on_mouse_crossed {|left| ...}` (NOT RECOMMENDED; it does what `on_mouse_entered` and `on_mouse_exited` do by returning a `left` argument indicating if mouse left `area`)
811
- - `on_drag_broken {...}` (NOT RECOMMENDED; varies per platforms; use `on_mouse_dropped` instead)
812
-
813
- The `area_mouse_event` `Hash` argument for mouse events that receive it (e.g. `on_mouse_up`, `on_mouse_dragged`) consist of the following hash keys:
814
- - `:x`: mouse x location in relation to area's top-left-corner
815
- - `:y`: mouse y location in relation to area's top-left-corner
816
- - `:area_width`: area current width
817
- - `:area_height`: area current height
818
- - `:down`: mouse pressed button (e.g. `1` is left button, `3` is right button)
819
- - `:up`: mouse depressed button (e.g. `1` is left button, `3` is right button)
820
- - `:count`: count of mouse clicks (e.g. `2` for double-click, `1` for single-click)
821
- - `:modifers`: `Array` of `Symbol`s from one of the following: `[:command, :shift, :alt, :control]`
822
- - `:held`: mouse held button during dragging (e.g. `1` is left button, `4` is right button)
823
-
824
- The `area_key_event` `Hash` argument for keyboard events that receive it (e.g. `on_key_up`, `on_key_down`) consist of the following hash keys:
825
- - `:key`: key character (`String`)
826
- - `:key_value`: key value (`Integer`). Useful in rare cases for numeric processing of keys instead of dealing with as `:key` character `String`
827
- - `:ext_key`: non-character extra key (`Symbol`) from `Glimmer::LibUI.enum_symbols(:ext_key)` such as `:left`, `:right`, `:escape`, `:insert`
828
- - `:ext_key_value`: non-character extra key value (`Integer`). Useful in rare cases for numeric processing of extra keys instead of dealing with as `:ext_key` `Symbol`
829
- - `:modifier`: modifier key pressed alone (e.g. `:shift` or `:control`)
830
- - `:modifiers`: modifier keys pressed simultaneously with `:key`, `:ext_key`, or `:modifier`
831
- - `:up`: indicates if key has been released or not (Boolean)
832
-
833
- Note that when nesting an `area` directly underneath `window` (without a layout control like `vertical_box`), it is automatically reparented with `vertical_box` in between the `window` and `area` since it would not show up on Linux otherwise.
834
-
835
- To redraw an `area`, you may call the `#queue_redraw_all` method, or simply `#redraw`.
836
-
837
- `area` has the following Glimmer-added API methods/attributes:
838
- - `request_auto_redraw`: requests auto redraw upon changes to nested stable `path` or shapes
839
- - `pause_auto_redraw`: pause auto redraw upon changes to nested stable `path` or shapes (useful to avoid too many micro-change redraws, to group all redraws as one after many micro-changes)
840
- - `resume_auto_redraw`: resume auto redraw upon changes to nested stable `path` or shapes
841
- - `auto_redraw_enabled`/`auto_redraw_enabled?`/`auto_redraw_enabled=`: an attribute to disable/enable auto redraw on an `area` upon changes to nested stable `path` or shapes
842
-
843
- A transform `matrix` can be set on a path by building a `matrix(m11 = nil, m12 = nil, m21 = nil, m22 = nil, m31 = nil, m32 = nil) {operations}` proxy object and then setting via `transform` property, or alternatively by building and setting the matrix in one call to `transform(m11 = nil, m12 = nil, m21 = nil, m22 = nil, m31 = nil, m32 = nil) {operations}` passing it the matrix arguments and/or content operations.
844
-
845
- When instantiating a `matrix` object, it always starts with identity matrix.
846
-
847
- Here are the following operations that can be performed in a `matrix` body:
848
- - `identity` [alias: `set_identity`]: resets matrix to identity matrix
849
- - `translate(x as Numeric, y as Numeric)`
850
- - `scale(x_center = 0 as Numeric, y_center = 0 as Numeric, x as Numeric, y as Numeric)`
851
- - `skew(x = 0 as Numeric, y = 0 as Numeric, x_amount as Numeric, y_amount as Numeric)`
852
- - `rotate(x = 0 as Numeric, y = 0 as Numeric, degrees as Numeric)`
853
-
854
- Example of using transform matrix (you may copy/paste in [`girb`](#girb-glimmer-irb)):
855
-
856
- ```ruby
857
- require 'glimmer-dsl-libui'
858
-
859
- include Glimmer
860
-
861
- window('Basic Transform', 350, 350) {
862
- area {
863
- path {
864
- square(0, 0, 350)
865
-
866
- fill r: 255, g: 255, b: 0
867
- }
868
- 40.times do |n|
869
- path {
870
- square(0, 0, 100)
871
-
872
- fill r: [255 - n*5, 0].max, g: [n*5, 255].min, b: 0, a: 0.5
873
- stroke :black, thickness: 2
874
- transform {
875
- skew 0.15, 0.15
876
- translate 50, 50
877
- rotate 100, 100, -9 * n
878
- scale 1.1, 1.1
879
- }
880
- }
881
- end
882
- }
883
- }.show
884
- ```
885
-
886
- Keep in mind that this part could be written differently when there is a need to reuse the matrix:
887
-
888
- ```ruby
889
- transform {
890
- translate 100, 100
891
- rotate 100, 100, -9 * n
892
- }
893
- ```
894
-
895
- Alternatively:
896
-
897
- ```ruby
898
- m1 = matrix {
899
- translate 100, 100
900
- rotate 100, 100, -9 * n
901
- }
902
- transform m1
903
- # and then reuse m1 elsewhere too
904
- ```
806
+ Mac
905
807
 
906
- You can set a `matrix`/`transform` on `area` directly to conveniently apply to all nested `path`s too.
808
+ ![glimmer-dsl-libui-mac-area-gallery.png](images/glimmer-dsl-libui-mac-area-gallery.png)
907
809
 
908
- Note that `area`, `path`, and nested shapes are all truly declarative, meaning they do not care about the ordering of calls to `fill`, `stroke`, and `transform`. Furthermore, any transform that is applied is reversed at the end of the block, so you never have to worry about the ordering of `transform` calls among different paths. You simply set a transform on the `path`s that need it and it is guaranteed to be called before all its content is drawn, and then undone afterwards to avoid affecting later paths. Matrix `transform` can be set on an entire `area` too, applying to all nested `path`s.
810
+ Windows
909
811
 
910
- `fill` and `stroke` accept [X11](https://en.wikipedia.org/wiki/X11_color_names) color `Symbol`s/`String`s like `:skyblue` and `'sandybrown'` or 6-char hex or 3-char hex-shorthand (as `Integer` or `String` with or without `0x` prefix)
812
+ ![glimmer-dsl-libui-windows-area-gallery.png](images/glimmer-dsl-libui-windows-area-gallery.png)
911
813
 
912
- Available [X11 colors](https://en.wikipedia.org/wiki/X11_color_names) can be obtained through `Glimmer::LibUI.x11_colors` method.
814
+ Linux
913
815
 
914
- Check [Basic Transform](#basic-transform) example for use of [X11](https://en.wikipedia.org/wiki/X11_color_names) colors.
816
+ ![glimmer-dsl-libui-linux-area-gallery.png](images/glimmer-dsl-libui-linux-area-gallery.png)
915
817
 
916
- Check [Histogram](#histogram) example for use of hex colors.
818
+ #### Area Text
917
819
 
918
820
  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 {[attributes]; string_value}` controls underneath it returning an actual `String` (think of them as the `<span>` or `<p>` element in html, which contains a string of text). Alternatively, you can nest attributed `string(string_value) {[attributes]}` if `string_value` is a short single-line string. An attributed `string` value can be changed dynamically via its `string` property.
919
821
 
@@ -964,17 +866,32 @@ window('area text drawing') {
964
866
  }.show
965
867
  ```
966
868
 
967
- #### Image Glimmer Custom Control
869
+ You may checkout [examples/basic_draw_text.rb](#basic-draw-text) and [examples/custom_draw_text.rb](#custom-draw-text) for examples of using `text` inside `area`.
870
+
871
+ Mac
872
+
873
+ ![glimmer-dsl-libui-mac-custom-draw-text-changed.png](images/glimmer-dsl-libui-mac-custom-draw-text-changed.png)
874
+
875
+ Windows
876
+
877
+ ![glimmer-dsl-libui-windows-custom-draw-text-changed.png](images/glimmer-dsl-libui-windows-custom-draw-text-changed.png)
878
+
879
+ Linux
880
+
881
+ ![glimmer-dsl-libui-linux-custom-draw-text-changed.png](images/glimmer-dsl-libui-linux-custom-draw-text-changed.png)
882
+
883
+ #### Area Image
968
884
 
969
885
  **(ALPHA FEATURE)**
970
886
 
971
887
  [libui](https://github.com/andlabs/libui) does not support `image` rendering outside of `table` yet.
972
888
  However, [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) adds a special `image` custom control that renders an image unto an `area` pixel by pixel (and when possible to optimize, line by line).
973
889
 
974
- Given that it is not a [libui](https://github.com/andlabs/libui)-native control, please keep these notes in mind:
975
- - [libui](https://github.com/andlabs/libui) pixel-by-pixel rendering performance is slow
890
+ Given that it is very new and not a [libui](https://github.com/andlabs/libui)-native control, please keep these notes in mind:
891
+ - It only supports the `.png` file format.
892
+ - [libui](https://github.com/andlabs/libui) pixel-by-pixel rendering performance is slow.
976
893
  - Including an `image` inside an `area` `on_draw` listener improves performance due to not retaining pixel/line data in memory.
977
- - Supplying `width` and `height` (2nd and 3rd arguments) greatly improves performance when shrinking image
894
+ - Supplying `width` and `height` (2nd and 3rd arguments) greatly improves performance when shrinking image.
978
895
 
979
896
  Currently, it is recommended to use `image` with very small `width` and `height` values only.
980
897
 
@@ -982,7 +899,13 @@ Setting a `transform` `matrix` is supported under `image` just like it is under
982
899
 
983
900
  Example of using `image` declaratively (you may copy/paste in [`girb`](#girb-glimmer-irb)):
984
901
 
985
- ![Basic Image](/images/glimmer-dsl-libui-mac-basic-image.png)
902
+ Mac
903
+
904
+ ![glimmer-dsl-libui-mac-basic-image.png](images/glimmer-dsl-libui-mac-basic-image.png)
905
+
906
+ Windows
907
+
908
+ ![glimmer-dsl-libui-windows-basic-image.png](images/glimmer-dsl-libui-windows-basic-image.png)
986
909
 
987
910
  ```ruby
988
911
  require 'glimmer-dsl-libui'
@@ -1128,8 +1051,149 @@ window('Basic Image', 96, 96) {
1128
1051
  }.show
1129
1052
  ```
1130
1053
 
1054
+ One final note is that in Linux, table images grow and shrink with the image size unlike on the Mac where table row heights are constant regardless of image sizes. As such, you may be able to repurpose a table with a single image column and a single row as an image control with more native libui rendering if you are only targeting Linux with your app.
1055
+
1131
1056
  Check out [examples/basic_image.rb](#basic-image) (all versions) for examples of using `image` Glimmer custom control.
1132
1057
 
1058
+ #### Colors
1059
+
1060
+ `fill` and `stroke` accept [X11](https://en.wikipedia.org/wiki/X11_color_names) color `Symbol`s/`String`s like `:skyblue` and `'sandybrown'` or 6-char hex or 3-char hex-shorthand (as `Integer` or `String` with or without `0x` prefix)
1061
+
1062
+ Available [X11 colors](https://en.wikipedia.org/wiki/X11_color_names) can be obtained through `Glimmer::LibUI.x11_colors` method.
1063
+
1064
+ Check [Basic Transform](#basic-transform) example for use of [X11](https://en.wikipedia.org/wiki/X11_color_names) colors.
1065
+
1066
+ Check [Histogram](#histogram) example for use of hex colors.
1067
+
1068
+ #### Area Draw Params
1069
+
1070
+ The `area_draw_params` argument for `on_draw` block is a hash consisting of the following keys:
1071
+ - `:context`: the drawing context object
1072
+ - `:area_width`: area width
1073
+ - `:area_height`: area height
1074
+ - `:clip_x`: clip region top-left x coordinate
1075
+ - `:clip_y`: clip region top-left y coordinate
1076
+ - `:clip_width`: clip region width
1077
+ - `:clip_height`: clip region height
1078
+
1079
+ In general, it is recommended to use declarative stable paths whenever feasible since they require less code and simpler maintenance. But, in more advanced cases, semi-declarative dynamic paths could be used instead, especially if there are thousands of dynamic paths that need maximum performance and low memory footprint.
1080
+
1081
+ #### Area Listeners
1082
+
1083
+ `area` supported listeners are:
1084
+ - `on_key_event {|area_key_event| ...}`: general catch-all key event (recommend using fine-grained key events below instead)
1085
+ - `on_key_down {|area_key_event| ...}`
1086
+ - `on_key_up {|area_key_event| ...}`
1087
+ - `on_mouse_event {|area_mouse_event| ...}`: general catch-all mouse event (recommend using fine-grained mouse events below instead)
1088
+ - `on_mouse_down {|area_mouse_event| ...}`
1089
+ - `on_mouse_up {|area_mouse_event| ...}`
1090
+ - `on_mouse_drag_started {|area_mouse_event| ...}`
1091
+ - `on_mouse_dragged {|area_mouse_event| ...}`
1092
+ - `on_mouse_dropped {|area_mouse_event| ...}`
1093
+ - `on_mouse_entered {...}`
1094
+ - `on_mouse_exited {...}`
1095
+ - `on_mouse_crossed {|left| ...}` (NOT RECOMMENDED; it does what `on_mouse_entered` and `on_mouse_exited` do by returning a `left` argument indicating if mouse left `area`)
1096
+ - `on_drag_broken {...}` (NOT RECOMMENDED; varies per platforms; use `on_mouse_dropped` instead)
1097
+
1098
+ The `area_mouse_event` `Hash` argument for mouse events that receive it (e.g. `on_mouse_up`, `on_mouse_dragged`) consist of the following hash keys:
1099
+ - `:x`: mouse x location in relation to area's top-left-corner
1100
+ - `:y`: mouse y location in relation to area's top-left-corner
1101
+ - `:area_width`: area current width
1102
+ - `:area_height`: area current height
1103
+ - `:down`: mouse pressed button (e.g. `1` is left button, `3` is right button)
1104
+ - `:up`: mouse depressed button (e.g. `1` is left button, `3` is right button)
1105
+ - `:count`: count of mouse clicks (e.g. `2` for double-click, `1` for single-click)
1106
+ - `:modifers`: `Array` of `Symbol`s from one of the following: `[:command, :shift, :alt, :control]`
1107
+ - `:held`: mouse held button during dragging (e.g. `1` is left button, `4` is right button)
1108
+
1109
+ The `area_key_event` `Hash` argument for keyboard events that receive it (e.g. `on_key_up`, `on_key_down`) consist of the following hash keys:
1110
+ - `:key`: key character (`String`)
1111
+ - `:key_value` (alias: `:key_code`): key code value (`Integer`). Useful in rare cases for numeric processing of keys instead of dealing with as `:key` character `String`
1112
+ - `:ext_key`: non-character extra key (`Symbol`) from `Glimmer::LibUI.enum_symbols(:ext_key)` such as `:left`, `:right`, `:escape`, `:insert`
1113
+ - `:ext_key_value`: non-character extra key value (`Integer`). Useful in rare cases for numeric processing of extra keys instead of dealing with as `:ext_key` `Symbol`
1114
+ - `:modifier`: modifier key pressed alone (e.g. `:shift` or `:control`)
1115
+ - `:modifiers`: modifier keys pressed simultaneously with `:key`, `:ext_key`, or `:modifier`
1116
+ - `:up`: indicates if key has been released or not (Boolean)
1117
+
1118
+ #### Area Methods/Attributes
1119
+
1120
+ To redraw an `area`, you may call the `#queue_redraw_all` method, or simply `#redraw`.
1121
+
1122
+ `area` has the following Glimmer-added API methods/attributes:
1123
+ - `request_auto_redraw`: requests auto redraw upon changes to nested stable `path` or shapes
1124
+ - `pause_auto_redraw`: pause auto redraw upon changes to nested stable `path` or shapes (useful to avoid too many micro-change redraws, to group all redraws as one after many micro-changes)
1125
+ - `resume_auto_redraw`: resume auto redraw upon changes to nested stable `path` or shapes
1126
+ - `auto_redraw_enabled`/`auto_redraw_enabled?`/`auto_redraw_enabled=`: an attribute to disable/enable auto redraw on an `area` upon changes to nested stable `path` or shapes
1127
+
1128
+ #### Area Transform Matrix
1129
+
1130
+ A transform `matrix` can be set on a path by building a `matrix(m11 = nil, m12 = nil, m21 = nil, m22 = nil, m31 = nil, m32 = nil) {operations}` proxy object and then setting via `transform` property, or alternatively by building and setting the matrix in one call to `transform(m11 = nil, m12 = nil, m21 = nil, m22 = nil, m31 = nil, m32 = nil) {operations}` passing it the matrix arguments and/or content operations.
1131
+
1132
+ When instantiating a `matrix` object, it always starts with identity matrix.
1133
+
1134
+ Here are the following operations that can be performed in a `matrix` body:
1135
+ - `identity` [alias: `set_identity`]: resets matrix to identity matrix
1136
+ - `translate(x as Numeric, y as Numeric)`
1137
+ - `scale(x_center = 0 as Numeric, y_center = 0 as Numeric, x as Numeric, y as Numeric)`
1138
+ - `skew(x = 0 as Numeric, y = 0 as Numeric, x_amount as Numeric, y_amount as Numeric)`
1139
+ - `rotate(x = 0 as Numeric, y = 0 as Numeric, degrees as Numeric)`
1140
+
1141
+ Example of using transform matrix (you may copy/paste in [`girb`](#girb-glimmer-irb)):
1142
+
1143
+ ```ruby
1144
+ require 'glimmer-dsl-libui'
1145
+
1146
+ include Glimmer
1147
+
1148
+ window('Basic Transform', 350, 350) {
1149
+ area {
1150
+ path {
1151
+ square(0, 0, 350)
1152
+
1153
+ fill r: 255, g: 255, b: 0
1154
+ }
1155
+ 40.times do |n|
1156
+ path {
1157
+ square(0, 0, 100)
1158
+
1159
+ fill r: [255 - n*5, 0].max, g: [n*5, 255].min, b: 0, a: 0.5
1160
+ stroke :black, thickness: 2
1161
+ transform {
1162
+ skew 0.15, 0.15
1163
+ translate 50, 50
1164
+ rotate 100, 100, -9 * n
1165
+ scale 1.1, 1.1
1166
+ }
1167
+ }
1168
+ end
1169
+ }
1170
+ }.show
1171
+ ```
1172
+
1173
+ Keep in mind that this part could be written differently when there is a need to reuse the matrix:
1174
+
1175
+ ```ruby
1176
+ transform {
1177
+ translate 100, 100
1178
+ rotate 100, 100, -9 * n
1179
+ }
1180
+ ```
1181
+
1182
+ Alternatively:
1183
+
1184
+ ```ruby
1185
+ m1 = matrix {
1186
+ translate 100, 100
1187
+ rotate 100, 100, -9 * n
1188
+ }
1189
+ transform m1
1190
+ # and then reuse m1 elsewhere too
1191
+ ```
1192
+
1193
+ You can set a `matrix`/`transform` on `area` directly to conveniently apply to all nested `path`s too.
1194
+
1195
+ Note that `area`, `path`, and nested shapes are all truly declarative, meaning they do not care about the ordering of calls to `fill`, `stroke`, and `transform`. Furthermore, any transform that is applied is reversed at the end of the block, so you never have to worry about the ordering of `transform` calls among different paths. You simply set a transform on the `path`s that need it and it is guaranteed to be called before all its content is drawn, and then undone afterwards to avoid affecting later paths. Matrix `transform` can be set on an entire `area` too, applying to all nested `path`s.
1196
+
1133
1197
  ### Smart Defaults and Conventions
1134
1198
 
1135
1199
  - `horizontal_box`, `vertical_box`, `grid`, and `form` controls have `padded` as `true` upon instantiation to ensure more user-friendly GUI by default
@@ -1280,7 +1344,8 @@ window('Method-Based Custom Keyword') {
1280
1344
  ### API Gotchas
1281
1345
 
1282
1346
  - 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`).
1283
- - `table` `checkbox_column` and `checkbox_text_column` checkbox editing only works on Linux and Windows (not Mac) due to a current limitation in [libui](https://github.com/andlabs/ui/issues/357).
1347
+ - `table` `checkbox_column` checkbox editing only works on Linux and Windows (not Mac) due to a current limitation in [libui](https://github.com/andlabs/ui/issues/357).
1348
+ - `table` `checkbox_text_column` checkbox editing only works on Linux (not Mac or Windows) due to a current limitation in [libui](https://github.com/andlabs/ui/issues/357).
1284
1349
  - `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)
1285
1350
  - `text` `string` `background` does not work on Windows due to an [issue in libui](https://github.com/andlabs/libui/issues/347).
1286
1351
  - `table` controls on Windows intentionally get an extra empty row at the end because if any row were to be deleted for the first time, double-deletion happens due to an issue in [libui](https://github.com/andlabs/libui) on Windows.
@@ -1930,11 +1995,11 @@ class TinyMidiPlayer
1930
1995
 
1931
1996
  UI.new_horizontal_box.tap do |hbox|
1932
1997
  UI.new_vertical_box.tap do |vbox|
1933
- UI.new_button('â–¶').tap do |button1|
1998
+ UI.new_button('â–¶').tap do |button1|
1934
1999
  UI.button_on_clicked(button1) { play_midi }
1935
2000
  UI.box_append(vbox, button1, 1)
1936
2001
  end
1937
- UI.new_button('â– ').tap do |button2|
2002
+ UI.new_button('â– ').tap do |button2|
1938
2003
  UI.button_on_clicked(button2) { stop_midi }
1939
2004
  UI.box_append(vbox, button2, 1)
1940
2005
  end
@@ -2028,12 +2093,12 @@ class TinyMidiPlayer
2028
2093
  vertical_box {
2029
2094
  stretchy false
2030
2095
 
2031
- button('â–¶') {
2096
+ button('â–¶') {
2032
2097
  on_clicked do
2033
2098
  play_midi
2034
2099
  end
2035
2100
  }
2036
- button('â– ') {
2101
+ button('â– ') {
2037
2102
  on_clicked do
2038
2103
  stop_midi
2039
2104
  end
@@ -3278,6 +3343,41 @@ UI.quit
3278
3343
  # NOTE:
3279
3344
  # This example displays images that can be freely downloaded from the Studio Ghibli website.
3280
3345
 
3346
+ require 'glimmer-dsl-libui'
3347
+
3348
+ include Glimmer
3349
+
3350
+ IMAGE_ROWS = []
3351
+
3352
+ 50.times do |i|
3353
+ url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
3354
+ puts "Processing Image: #{url}"; $stdout.flush # for Windows
3355
+ IMAGE_ROWS << [image(url)] # array of one column cell
3356
+ rescue StandardError => e
3357
+ warn url, e.message
3358
+ end
3359
+
3360
+ window('The Red Turtle', 310, 350, false) {
3361
+ horizontal_box {
3362
+ table {
3363
+ image_column('www.ghibli.jp/works/red-turtle')
3364
+
3365
+ cell_rows IMAGE_ROWS
3366
+ }
3367
+ }
3368
+
3369
+ on_closing do
3370
+ puts 'Bye Bye'
3371
+ end
3372
+ }.show
3373
+ ```
3374
+
3375
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2 (manual construction of `image` from `image_part`):
3376
+
3377
+ ```ruby
3378
+ # NOTE:
3379
+ # This example displays images that can be freely downloaded from the Studio Ghibli website.
3380
+
3281
3381
  require 'glimmer-dsl-libui'
3282
3382
  require 'chunky_png'
3283
3383
  require 'open-uri'
@@ -3354,6 +3454,42 @@ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version
3354
3454
  # NOTE:
3355
3455
  # This example displays images that can be freely downloaded from the Studio Ghibli website.
3356
3456
 
3457
+ require 'glimmer-dsl-libui'
3458
+
3459
+ include Glimmer
3460
+
3461
+ IMAGE_ROWS = []
3462
+
3463
+ 5.times do |i|
3464
+ url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
3465
+ puts "Processing Image: #{url}"; $stdout.flush # for Windows
3466
+ text = url.sub('https://www.ghibli.jp/gallery/thumb-redturtle', '').sub('.png', '')
3467
+ img = image(url)
3468
+ IMAGE_ROWS << [[img, text], [img, text]] # cell values are dual-element arrays
3469
+ rescue StandardError => e
3470
+ warn url, e.message
3471
+ end
3472
+
3473
+ window('The Red Turtle', 670, 350) {
3474
+ horizontal_box {
3475
+ table {
3476
+ image_text_column('image/number')
3477
+ image_text_column('image/number (editable)') {
3478
+ editable true
3479
+ }
3480
+
3481
+ cell_rows IMAGE_ROWS
3482
+ }
3483
+ }
3484
+ }.show
3485
+ ```
3486
+
3487
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2 (manual construction of `image` from `image_part`):
3488
+
3489
+ ```ruby
3490
+ # NOTE:
3491
+ # This example displays images that can be freely downloaded from the Studio Ghibli website.
3492
+
3357
3493
  require 'glimmer-dsl-libui'
3358
3494
  require 'chunky_png'
3359
3495
  require 'open-uri'
@@ -3668,6 +3804,40 @@ Linux
3668
3804
 
3669
3805
  New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
3670
3806
 
3807
+ ```ruby
3808
+ # frozen_string_literal: true
3809
+
3810
+ require 'glimmer-dsl-libui'
3811
+
3812
+ include Glimmer
3813
+
3814
+ img = image(File.expand_path('../icons/glimmer.png', __dir__), 24, 24)
3815
+
3816
+ data = [
3817
+ [['cat', :red] , ['meow', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], {r: 255, g: 120, b: 0, a: 0.5}],
3818
+ [['dog', :yellow] , ['woof', {r: 240, g: 32, b: 32}] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], :skyblue],
3819
+ [['chicken', :beige], ['cock-a-doodle-doo', :blue] , [false, 'mammal', :red] , [img, 'Glimmer', :beige], {r: 5, g: 120, b: 110}],
3820
+ [['horse', :purple] , ['neigh', {r: 240, g: 32, b: 32}], [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], '13a1fb'],
3821
+ [['cow', :gray] , ['moo', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :brown], 0x12ff02]
3822
+ ]
3823
+
3824
+ window('Animals', 500, 200) {
3825
+ horizontal_box {
3826
+ table {
3827
+ text_color_column('Animal')
3828
+ text_color_column('Sound')
3829
+ checkbox_text_color_column('Description')
3830
+ image_text_color_column('GUI')
3831
+ background_color_column('Mammal')
3832
+
3833
+ cell_rows data
3834
+ }
3835
+ }
3836
+ }.show
3837
+ ```
3838
+
3839
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2 (manual construction of [libui](https://github.com/andlabs/libui) `image` from `image_part`):
3840
+
3671
3841
  ```ruby
3672
3842
  require 'glimmer-dsl-libui'
3673
3843
  require 'chunky_png'
@@ -4895,6 +5065,10 @@ Mac
4895
5065
 
4896
5066
  ![glimmer-dsl-libui-mac-basic-image.png](images/glimmer-dsl-libui-mac-basic-image.png)
4897
5067
 
5068
+ Windows
5069
+
5070
+ ![glimmer-dsl-libui-windows-basic-image.png](images/glimmer-dsl-libui-windows-basic-image.png)
5071
+
4898
5072
  New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
4899
5073
 
4900
5074
  ```ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/bin/girb CHANGED
File without changes
@@ -1,20 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'glimmer-dsl-libui'
4
- require 'chunky_png'
5
4
 
6
5
  include Glimmer
7
6
 
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
- }
7
+ img = image(File.expand_path('../icons/glimmer.png', __dir__), 24, 24)
18
8
 
19
9
  data = [
20
10
  [['cat', :red] , ['meow', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], {r: 255, g: 120, b: 0, a: 0.5}],
@@ -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
@@ -4,8 +4,6 @@
4
4
  # This example displays images that can be freely downloaded from the Studio Ghibli website.
5
5
 
6
6
  require 'glimmer-dsl-libui'
7
- require 'chunky_png'
8
- require 'open-uri'
9
7
 
10
8
  include Glimmer
11
9
 
@@ -13,18 +11,8 @@ IMAGE_ROWS = []
13
11
 
14
12
  50.times do |i|
15
13
  url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
16
- puts "Processing Image: #{url}"
17
- $stdout.flush # for Windows
18
- f = URI.open(url)
19
- canvas = ChunkyPNG::Canvas.from_io(f)
20
- f.close
21
- data = canvas.to_rgba_stream
22
- width = canvas.width
23
- height = canvas.height
24
- img = image {
25
- image_part(data, width, height, width * 4)
26
- }
27
- IMAGE_ROWS << [img] # array of one column cell
14
+ puts "Processing Image: #{url}"; $stdout.flush # for Windows
15
+ IMAGE_ROWS << [image(url)] # array of one column cell
28
16
  rescue StandardError => e
29
17
  warn url, e.message
30
18
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # NOTE:
4
+ # This example displays images that can be freely downloaded from the Studio Ghibli website.
5
+
6
+ require 'glimmer-dsl-libui'
7
+ require 'chunky_png'
8
+ require 'open-uri'
9
+
10
+ include Glimmer
11
+
12
+ IMAGE_ROWS = []
13
+
14
+ 50.times do |i|
15
+ url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
16
+ puts "Processing Image: #{url}"
17
+ $stdout.flush # for Windows
18
+ f = URI.open(url)
19
+ canvas = ChunkyPNG::Canvas.from_io(f)
20
+ f.close
21
+ data = canvas.to_rgba_stream
22
+ width = canvas.width
23
+ height = canvas.height
24
+ img = image {
25
+ image_part(data, width, height, width * 4)
26
+ }
27
+ IMAGE_ROWS << [img] # array of one column cell
28
+ rescue StandardError => e
29
+ warn url, e.message
30
+ end
31
+
32
+ window('The Red Turtle', 310, 350, false) {
33
+ horizontal_box {
34
+ table {
35
+ image_column('www.ghibli.jp/works/red-turtle')
36
+
37
+ cell_rows IMAGE_ROWS
38
+ }
39
+ }
40
+
41
+ on_closing do
42
+ puts 'Bye Bye'
43
+ end
44
+ }.show
@@ -4,8 +4,6 @@
4
4
  # This example displays images that can be freely downloaded from the Studio Ghibli website.
5
5
 
6
6
  require 'glimmer-dsl-libui'
7
- require 'chunky_png'
8
- require 'open-uri'
9
7
 
10
8
  include Glimmer
11
9
 
@@ -13,18 +11,9 @@ IMAGE_ROWS = []
13
11
 
14
12
  5.times do |i|
15
13
  url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
16
- puts "Processing Image: #{url}"
17
- $stdout.flush # for Windows
18
- f = URI.open(url)
19
- canvas = ChunkyPNG::Canvas.from_io(f)
20
- f.close
21
- data = canvas.to_rgba_stream
22
- width = canvas.width
23
- height = canvas.height
24
- img = image {
25
- image_part(data, width, height, width * 4)
26
- }
14
+ puts "Processing Image: #{url}"; $stdout.flush # for Windows
27
15
  text = url.sub('https://www.ghibli.jp/gallery/thumb-redturtle', '').sub('.png', '')
16
+ img = image(url)
28
17
  IMAGE_ROWS << [[img, text], [img, text]] # cell values are dual-element arrays
29
18
  rescue StandardError => e
30
19
  warn url, e.message
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # NOTE:
4
+ # This example displays images that can be freely downloaded from the Studio Ghibli website.
5
+
6
+ require 'glimmer-dsl-libui'
7
+ require 'chunky_png'
8
+ require 'open-uri'
9
+
10
+ include Glimmer
11
+
12
+ IMAGE_ROWS = []
13
+
14
+ 5.times do |i|
15
+ url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
16
+ puts "Processing Image: #{url}"
17
+ $stdout.flush # for Windows
18
+ f = URI.open(url)
19
+ canvas = ChunkyPNG::Canvas.from_io(f)
20
+ f.close
21
+ data = canvas.to_rgba_stream
22
+ width = canvas.width
23
+ height = canvas.height
24
+ img = image {
25
+ image_part(data, width, height, width * 4)
26
+ }
27
+ text = url.sub('https://www.ghibli.jp/gallery/thumb-redturtle', '').sub('.png', '')
28
+ IMAGE_ROWS << [[img, text], [img, text]] # cell values are dual-element arrays
29
+ rescue StandardError => e
30
+ warn url, e.message
31
+ end
32
+
33
+ window('The Red Turtle', 670, 350) {
34
+ horizontal_box {
35
+ table {
36
+ image_text_column('image/number')
37
+ image_text_column('image/number (editable)') {
38
+ editable true
39
+ }
40
+
41
+ cell_rows IMAGE_ROWS
42
+ }
43
+ }
44
+ }.show
Binary file
@@ -218,6 +218,7 @@ module Glimmer
218
218
  {
219
219
  key: key_to_char(area_key_event.Key, modifiers),
220
220
  key_value: area_key_event.Key,
221
+ key_code: area_key_event.Key,
221
222
  ext_key: ext_key_to_symbol(area_key_event.ExtKey),
222
223
  ext_key_value: area_key_event.ExtKey,
223
224
  modifier: modifiers_to_symbols(area_key_event.Modifier).first,
@@ -43,9 +43,9 @@ module Glimmer
43
43
  @column_index ||= @parent_proxy.send(:next_column_index)
44
44
  end
45
45
 
46
- # actual index within table columns (disregarding nil fillings that account for DualColumn instances)
46
+ # actual index within table columns (disregarding extra fillings that account for DualColumn instances)
47
47
  def index
48
- @parent_proxy.columns.compact.index(self)
48
+ @parent_proxy.columns.select {|c| c.is_a?(Column)}.index(self)
49
49
  end
50
50
  end
51
51
  end
@@ -20,6 +20,7 @@
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  require 'glimmer/libui/control_proxy'
23
+ require 'glimmer/libui/control_proxy/image_part_proxy'
23
24
  require 'glimmer/libui/image_path_renderer'
24
25
  require 'glimmer/data_binding/observer'
25
26
  require 'glimmer/libui/control_proxy/transformable'
@@ -63,15 +64,13 @@ module Glimmer
63
64
  end
64
65
 
65
66
  def file(value = nil)
66
- if area_image?
67
- if value.nil?
68
- @args[0]
69
- else
70
- @args[0] = value
71
- if @content_added
72
- post_add_content
73
- request_auto_redraw
74
- end
67
+ if value.nil?
68
+ @args[0]
69
+ else
70
+ @args[0] = value
71
+ if @content_added
72
+ post_add_content
73
+ request_auto_redraw
75
74
  end
76
75
  end
77
76
  end
@@ -80,16 +79,12 @@ module Glimmer
80
79
 
81
80
  def width(value = nil)
82
81
  if value.nil?
83
- area_image? ? @args[1] : @args[0]
82
+ @args[1]
84
83
  else
85
- if area_image?
86
- @args[1] = value
87
- if @content_added
88
- post_add_content
89
- request_auto_redraw
90
- end
91
- else
92
- @args[0] = value
84
+ @args[1] = value
85
+ if area_image? && @content_added
86
+ post_add_content
87
+ request_auto_redraw
93
88
  end
94
89
  end
95
90
  end
@@ -98,16 +93,12 @@ module Glimmer
98
93
 
99
94
  def height(value = nil)
100
95
  if value.nil?
101
- area_image? ? @args[2] : @args[1]
96
+ @args[2]
102
97
  else
103
- if area_image?
104
- @args[2] = value
105
- if @content_added
106
- post_add_content
107
- request_auto_redraw
108
- end
109
- else
110
- @args[1] = value
98
+ @args[2] = value
99
+ if area_image? && @content_added
100
+ post_add_content
101
+ request_auto_redraw
111
102
  end
112
103
  end
113
104
  end
@@ -133,8 +124,7 @@ module Glimmer
133
124
 
134
125
  def area_image?
135
126
  @parent_proxy&.is_a?(AreaProxy) or
136
- AreaProxy.current_area_draw_params or
137
- @args[0].is_a?(String) # first arg is file
127
+ AreaProxy.current_area_draw_params
138
128
  end
139
129
 
140
130
  def destroy
@@ -146,23 +136,41 @@ module Glimmer
146
136
 
147
137
  def build_control
148
138
  unless area_image? # image object
149
- @args = [@children.first.args[1], @children.first.args[2]] if @children.size == 1 && (@args[0].nil? || @args[1].nil?)
150
- super
139
+ if file
140
+ load_image
141
+ ImagePartProxy.new('image_part', self, [@data, width, height, width * 4])
142
+ end
143
+ @args[1] = @children.first.args[1] if @children.size == 1 && @args[1].nil?
144
+ @args[2] = @children.first.args[2] if @children.size == 1 && @args[2].nil?
145
+ @libui = ControlProxy.new_control(@keyword, [width, height])
151
146
  @libui.tap do
152
147
  @children.each {|child| child&.send(:build_control) }
153
148
  end
154
149
  end
150
+ rescue => e
151
+ Glimmer::Config.logger.error {"Failed to load image file: #{file}"}
152
+ Glimmer::Config.logger.error {e.full_message}
153
+ raise e
155
154
  end
156
155
 
157
156
  def load_image
158
157
  require 'chunky_png'
159
- f = File.open(file)
160
- canvas = ChunkyPNG::Canvas.from_io(f)
161
- f.close
158
+ canvas = nil
159
+ if file.start_with?('http')
160
+ require 'net/http'
161
+ require 'open-uri'
162
+ uri = URI(file)
163
+ canvas = ChunkyPNG::Canvas.from_string(Net::HTTP.get(uri))
164
+ else
165
+ f = File.open(file)
166
+ canvas = ChunkyPNG::Canvas.from_io(f)
167
+ f.close
168
+ end
162
169
  canvas.resample_nearest_neighbor!(width, height) if width && height
163
170
  @data = canvas.to_rgba_stream
164
171
  self.width = canvas.width
165
172
  self.height = canvas.height
173
+ [@data, width, height]
166
174
  end
167
175
 
168
176
  def parse_pixels
@@ -21,6 +21,7 @@
21
21
 
22
22
  require 'glimmer/libui/control_proxy'
23
23
  require 'glimmer/libui/control_proxy/dual_column'
24
+ require 'glimmer/libui/control_proxy/triple_column'
24
25
  require 'glimmer/data_binding/observer'
25
26
  require 'glimmer/fiddle_consumer'
26
27
 
@@ -137,7 +138,7 @@ module Glimmer
137
138
 
138
139
  def build_control
139
140
  @model_handler = ::LibUI::FFI::TableModelHandler.malloc
140
- @model_handler.NumColumns = fiddle_closure_block_caller(4) { @columns.map {|c| c.is_a?(DualColumn) ? 2 : 1}.sum }
141
+ @model_handler.NumColumns = fiddle_closure_block_caller(4) { @columns.map {|c| c.is_a?(DualColumn) ? 2 : (c.is_a?(TripleColumn) ? 3 : 1)}.sum }
141
142
  @model_handler.ColumnType = fiddle_closure_block_caller(4, [1, 1, 4]) do |_, _, column|
142
143
  # TODO consider refactoring to use Glimmer::LibUI.enum_symbols(:table_value_type)
143
144
  case @columns[column]
@@ -193,15 +194,27 @@ module Glimmer
193
194
  column = @columns[column].index
194
195
  @cell_rows[row] ||= []
195
196
  @cell_rows[row][column] = ::LibUI.table_value_string(val).to_s
197
+ when Column::TextColorColumnProxy
198
+ column = @columns[column].index
199
+ @cell_rows[row] ||= []
200
+ @cell_rows[row][column] ||= []
201
+ @cell_rows[row][column][0] = ::LibUI.table_value_string(val).to_s
196
202
  when :text
197
203
  column = @columns[column - 1].index
204
+ @cell_rows[row] ||= []
205
+ @cell_rows[row][column] ||= []
198
206
  @cell_rows[row][column][1] = ::LibUI.table_value_string(val).to_s
199
207
  when Column::ButtonColumnProxy
200
208
  @columns[column].notify_listeners(:on_clicked, row)
201
- when Column::CheckboxColumnProxy, Column::CheckboxTextColumnProxy
209
+ when Column::CheckboxColumnProxy
202
210
  column = @columns[column].index
203
211
  @cell_rows[row] ||= []
204
212
  @cell_rows[row][column] = ::LibUI.table_value_int(val).to_i == 1
213
+ when Column::CheckboxTextColumnProxy
214
+ column = @columns[column].index
215
+ @cell_rows[row] ||= []
216
+ @cell_rows[row][column] ||= []
217
+ @cell_rows[row][column][0] = ::LibUI.table_value_int(val).to_i == 1
205
218
  end
206
219
  on_edited.each {|listener| listener.call(row, @cell_rows[row])}
207
220
  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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
@@ -190,20 +190,6 @@ dependencies:
190
190
  - - "~>"
191
191
  - !ruby/object:Gem::Version
192
192
  version: 0.7.0
193
- - !ruby/object:Gem::Dependency
194
- name: chunky_png
195
- requirement: !ruby/object:Gem::Requirement
196
- requirements:
197
- - - "~>"
198
- - !ruby/object:Gem::Version
199
- version: 1.4.0
200
- type: :development
201
- prerelease: false
202
- version_requirements: !ruby/object:Gem::Requirement
203
- requirements:
204
- - - "~>"
205
- - !ruby/object:Gem::Version
206
- version: 1.4.0
207
193
  description: Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI
208
194
  Library) - No need to pre-install any prerequisites. Just install the gem and have
209
195
  platform-independent native GUI that just works! Glimmer DSL for LibUI aims to provide
@@ -245,8 +231,11 @@ files:
245
231
  - examples/basic_table_checkbox.rb
246
232
  - examples/basic_table_checkbox_text.rb
247
233
  - examples/basic_table_color.rb
234
+ - examples/basic_table_color2.rb
248
235
  - examples/basic_table_image.rb
236
+ - examples/basic_table_image2.rb
249
237
  - examples/basic_table_image_text.rb
238
+ - examples/basic_table_image_text2.rb
250
239
  - examples/basic_table_progress_bar.rb
251
240
  - examples/basic_transform.rb
252
241
  - examples/basic_window.rb