glimmer-dsl-libui 0.0.17 → 0.0.21

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: a9821169ec1b82253239d5169165c94c76e8b4efa407c27ccf4e73eae25cd68f
4
- data.tar.gz: 47b312e49da5f6acf1011d1e45283d1b6d9cb2f8a03d37e218fba794e07990d9
3
+ metadata.gz: 3a7491ce7cea65fb7025868e9fb2db5c4e6187ba269a177879e4276e50fa3d9f
4
+ data.tar.gz: 9b47cab46d79af36dd06b6914570f30662540b7b8c1e634dc326ed9af32ad041
5
5
  SHA512:
6
- metadata.gz: 326d75305142c5773a9dfd487fb595e7271c26a003ff1db10771a5e805e8c77eb567f6f56b54ac7ab721e2ed532f70ccdd9fa42437f6fd12c616f98d28c91f0e
7
- data.tar.gz: a60432231078bf85d00e8882657eae577eeb99cf0b71a57f12c485c933577f8f4f7d98ec1cb6337f4ab4f1d02bf0c0061a618b9f998c16dc05641ad6efc8352f
6
+ metadata.gz: 692870dd49de81f7d2840579f0de3b7bd414bda277db56a4c28597febd012446c6b8b098bf56e5afe8c9b17f68547bb24bceaba45e15c3e4fd3ca041e5c37d2a
7
+ data.tar.gz: 289ede334bc53171a6a028dca1d03e794d0e81329621f2278365bfdcb2079fd200da21161d4aed6cf8486f382c4e0b04afadf3883ba0e07790878dbfd8fad334
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.21
4
+
5
+ - New examples/editable_column_table_image_text.rb
6
+ - Support table `image_text_column`
7
+
8
+ ## 0.0.20
9
+
10
+ - New examples/editable_column_table.rb
11
+ - Support `editable` property for `text_column`
12
+
13
+ ## 0.0.19
14
+
15
+ - New examples/editable_table.rb
16
+ - Support editable `table` control
17
+ - Fix issue with table `text_column` repeating the first column as the second
18
+
19
+ ## 0.0.18
20
+
21
+ - Support examples/basic_table_image.rb
22
+ - Support table `image_column`
23
+ - Support `image` and `image_part` for building images from rgba byte arrays
24
+ - Rename `Glimmer::LibUI::ControlProxy.all_control_proxies` to `Glimmer::LibUI::ControlProxy.control_proxies`
25
+ - Add `Glimmer::LibUI::ControlProxy.image_proxies`
26
+
3
27
  ## 0.0.17
4
28
 
5
29
  - Support examples/basic_table.rb
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.0.17
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.0.21
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)
@@ -43,7 +43,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
43
43
 
44
44
  ## Table of Contents
45
45
 
46
- - [Glimmer DSL for LibUI 0.0.17](#-glimmer-dsl-for-libui-0017)
46
+ - [Glimmer DSL for LibUI 0.0.21](#-glimmer-dsl-for-libui-0021)
47
47
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
48
48
  - [Usage](#usage)
49
49
  - [API](#api)
@@ -70,6 +70,10 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
70
70
  - [Grid](#grid)
71
71
  - [Form](#form)
72
72
  - [Basic Table](#basic-table)
73
+ - [Editable Table](#editable-table)
74
+ - [Editable Column Table](#editable-column-table)
75
+ - [Basic Table Image](#basic-table-image)
76
+ - [Basic Table Image Text](#basic-table-image-text)
73
77
  - [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
74
78
  - [Help](#help)
75
79
  - [Issues](#issues)
@@ -157,7 +161,7 @@ gem install glimmer-dsl-libui
157
161
  Or install via Bundler `Gemfile`:
158
162
 
159
163
  ```ruby
160
- gem 'glimmer-dsl-libui', '~> 0.0.17'
164
+ gem 'glimmer-dsl-libui', '~> 0.0.21'
161
165
  ```
162
166
 
163
167
  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.
@@ -227,6 +231,10 @@ Control(Args) | Properties | Listeners
227
231
  `group(text as String)` | `margined` (Boolean), `title` (`String`) | None
228
232
  `horizontal_box` | `padded` (Boolean) | None
229
233
  `horizontal_separator` | None | None
234
+ `image(width as Numeric, height as Numeric)` | None | None
235
+ `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
236
+ `image_column(name as String)` | None | None
237
+ `image_text_column(name as String)` | None | None
230
238
  `label(text as String)` | `text` (`String`) | None
231
239
  `menu(text as String)` | None | None
232
240
  `menu_item(text as String)` | `checked` (Boolean) | `on_clicked`
@@ -242,8 +250,8 @@ Control(Args) | Properties | Listeners
242
250
  `spinbox(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
243
251
  `tab` | `margined` (Boolean), `num_pages` (`Integer`) | None
244
252
  `tab_item(name as String)` | `index` [read-only] (`Integer`), `margined` (Boolean), `name` [read-only] (`String`) | None
245
- `table` | `cell_rows` (`Array` (rows) of `Arrays` (row columns) of cell values (e.g. `String` values)) | None
246
- `text_column(name as String)` | None | None
253
+ `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
254
+ `text_column(name as String)` | `editable` as Boolean | None
247
255
  `time_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`
248
256
  `vertical_box` | `padded` (Boolean) | None
249
257
  `window(title as String, width as Integer, height as Integer, has_menubar as Boolean)` | `borderless` (Boolean), `content_size` (width `Numeric`, height `Numeric`), `fullscreen` (Boolean), `margined` (Boolean), `title` (`String`) | `on_closing`, `on_content_size_changed`, `on_destroy`
@@ -279,7 +287,9 @@ Control(Args) | Properties | Listeners
279
287
 
280
288
  ### Extra Operations
281
289
 
282
- - `ControlProxy::all_control_proxies`: returns all instantiated control proxies in the application
290
+ - `ControlProxy::control_proxies`: returns all instantiated control proxies in the application
291
+ - `ControlProxy::menu_proxies`: returns all instantiated `menu` proxies in the application
292
+ - `ControlProxy::image_proxies`: returns all instantiated `image` proxies in the application
283
293
  - `ControlProxy::main_window_proxy`: returns the first window proxy instantiated in the application
284
294
  - `ControlProxy#window_proxy`: returns the window proxy parent for a control
285
295
 
@@ -306,7 +316,9 @@ Control(Args) | Properties | Listeners
306
316
  - When destroying a control nested under a `window` or `group`, it is automatically unset as their child to allow successful destruction
307
317
  - For `date_time_picker`, `date_picker`, and `time_picker`, make sure `time` hash values for `mon`, `wday`, and `yday` are 1-based instead of [libui](https://github.com/andlabs/libui) original 0-based values, and return `dst` as Boolean instead of `isdst` as `1`/`0`
308
318
  - Smart defaults for `grid` child attributes are `left` (`0`), `top` (`0`), `xspan` (`1`), `yspan` (`1`), `hexpand` (`false`), `halign` (`0`), `vexpand` (`false`), and `valign` (`0`)
309
- - The `table` control automatically constructs required `TableModelHandler`, `TableModel`, and `TableParams`, calculating all their arguments from `cell_rows` property (e.g. `NumRows`)
319
+ - The `table` control automatically constructs required `TableModelHandler`, `TableModel`, and `TableParams`, calculating all their arguments from `cell_rows` and `editable` properties (e.g. `NumRows`) as well as nested columns (e.g. `text_column`)
320
+ - Table model instances are automatically freed from memory after `window` is destroyed.
321
+ - `image` instances are automatically freed from memory after `window` is destroyed.
310
322
 
311
323
  ### API Gotchas
312
324
 
@@ -500,6 +512,23 @@ window('hello world', 300, 200, true) {
500
512
  }.show
501
513
  ```
502
514
 
515
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
516
+
517
+ ```ruby
518
+ require 'glimmer-dsl-libui'
519
+
520
+ include Glimmer
521
+
522
+ window { # first 3 args can be set via properties with 4th arg has_menubar=true by default
523
+ title 'hello world'
524
+ content_size 300, 200
525
+
526
+ on_closing do
527
+ puts 'Bye Bye'
528
+ end
529
+ }.show
530
+ ```
531
+
503
532
  ### Basic Button
504
533
 
505
534
  [examples/basic_button.rb](examples/basic_button.rb)
@@ -564,7 +593,7 @@ require 'glimmer-dsl-libui'
564
593
 
565
594
  include Glimmer
566
595
 
567
- window('hello world', 300, 200, true) { |w|
596
+ window('hello world', 300, 200) { |w|
568
597
  button('Button') {
569
598
  on_clicked do
570
599
  msg_box(w, 'Information', 'You clicked the button')
@@ -577,23 +606,6 @@ window('hello world', 300, 200, true) { |w|
577
606
  }.show
578
607
  ```
579
608
 
580
- [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
581
-
582
- ```ruby
583
- require 'glimmer-dsl-libui'
584
-
585
- include Glimmer
586
-
587
- window { # first 3 args can be set via properties with 4th arg has_menubar=true by default
588
- title 'hello world'
589
- content_size 300, 200
590
-
591
- on_closing do
592
- puts 'Bye Bye'
593
- end
594
- }.show
595
- ```
596
-
597
609
  ### Basic Entry
598
610
 
599
611
  [examples/basic_entry.rb](examples/basic_entry.rb)
@@ -1873,6 +1885,366 @@ window('Animal sounds', 300, 200) {
1873
1885
  }.show
1874
1886
  ```
1875
1887
 
1888
+ ### Editable Table
1889
+
1890
+ [examples/editable_table.rb](examples/editable_table.rb)
1891
+
1892
+ Run with this command from the root of the project if you cloned the project:
1893
+
1894
+ ```
1895
+ ruby -r './lib/glimmer-dsl-libui' examples/editable_table.rb
1896
+ ```
1897
+
1898
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1899
+
1900
+ ```
1901
+ ruby -r glimmer-dsl-libui -e "require 'examples/editable_table'"
1902
+ ```
1903
+
1904
+ Mac
1905
+
1906
+ ![glimmer-dsl-libui-mac-editable-table.png](images/glimmer-dsl-libui-mac-editable-table.png)
1907
+ ![glimmer-dsl-libui-mac-editable-table-editing.png](images/glimmer-dsl-libui-mac-editable-table-editing.png)
1908
+ ![glimmer-dsl-libui-mac-editable-table-edited.png](images/glimmer-dsl-libui-mac-editable-table-edited.png)
1909
+
1910
+ Linux
1911
+
1912
+ ![glimmer-dsl-libui-linux-editable-table.png](images/glimmer-dsl-libui-linux-editable-table.png)
1913
+ ![glimmer-dsl-libui-linux-editable-table-editing.png](images/glimmer-dsl-libui-linux-editable-table-editing.png)
1914
+ ![glimmer-dsl-libui-linux-editable-table-edited.png](images/glimmer-dsl-libui-linux-editable-table-edited.png)
1915
+
1916
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1917
+
1918
+ ```ruby
1919
+ require 'glimmer-dsl-libui'
1920
+
1921
+ include Glimmer
1922
+
1923
+ data = [
1924
+ %w[cat meow],
1925
+ %w[dog woof],
1926
+ %w[chicken cock-a-doodle-doo],
1927
+ %w[hourse neigh],
1928
+ %w[cow moo]
1929
+ ]
1930
+
1931
+ window('Editable animal sounds', 300, 200) {
1932
+ horizontal_box {
1933
+ table {
1934
+ text_column('Animal')
1935
+ text_column('Description')
1936
+
1937
+ cell_rows data
1938
+ editable true
1939
+ }
1940
+ }
1941
+
1942
+ on_closing do
1943
+ puts 'Bye Bye'
1944
+ end
1945
+ }.show
1946
+ ```
1947
+
1948
+ ### Editable Column Table
1949
+
1950
+ [examples/editable_column_table.rb](examples/editable_column_table.rb)
1951
+
1952
+ Run with this command from the root of the project if you cloned the project:
1953
+
1954
+ ```
1955
+ ruby -r './lib/glimmer-dsl-libui' examples/editable_column_table.rb
1956
+ ```
1957
+
1958
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1959
+
1960
+ ```
1961
+ ruby -r glimmer-dsl-libui -e "require 'examples/editable_column_table'"
1962
+ ```
1963
+
1964
+ Mac
1965
+
1966
+ ![glimmer-dsl-libui-mac-editable-column-table-editing.png](images/glimmer-dsl-libui-mac-editable-column-table-editing.png)
1967
+ ![glimmer-dsl-libui-mac-editable-column-table-edited.png](images/glimmer-dsl-libui-mac-editable-column-table-edited.png)
1968
+
1969
+ Linux
1970
+
1971
+ ![glimmer-dsl-libui-linux-editable-column-table-editing.png](images/glimmer-dsl-libui-linux-editable-column-table-editing.png)
1972
+ ![glimmer-dsl-libui-linux-editable-column-table-edited.png](images/glimmer-dsl-libui-linux-editable-column-table-edited.png)
1973
+
1974
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1975
+
1976
+ ```ruby
1977
+ require 'glimmer-dsl-libui'
1978
+
1979
+ include Glimmer
1980
+
1981
+ data = [
1982
+ %w[cat calm meow],
1983
+ %w[dog loyal woof],
1984
+ %w[chicken bird cock-a-doodle-doo],
1985
+ %w[hourse fast neigh],
1986
+ %w[cow slow moo]
1987
+ ]
1988
+
1989
+ window('Editable column animal sounds', 400, 200) {
1990
+ horizontal_box {
1991
+ table {
1992
+ text_column('Animal')
1993
+ text_column('Description')
1994
+ text_column('Sound (Editable)') {
1995
+ editable true
1996
+ }
1997
+
1998
+ cell_rows data
1999
+ }
2000
+ }
2001
+
2002
+ on_closing do
2003
+ puts 'Bye Bye'
2004
+ end
2005
+ }.show
2006
+ ```
2007
+
2008
+ ### Basic Table Image
2009
+
2010
+ This example has a prerequisite of installing `chunky_png` Ruby gem:
2011
+
2012
+ ```
2013
+ gem install chunky_png -v1.4.0
2014
+ ```
2015
+
2016
+ Also, note that behavior varies per platform (i.e. how `table` chooses to size images by default).
2017
+
2018
+ [examples/basic_table_image.rb](examples/basic_table_image.rb)
2019
+
2020
+ Run with this command from the root of the project if you cloned the project:
2021
+
2022
+ ```
2023
+ ruby -r './lib/glimmer-dsl-libui' examples/basic_table_image.rb
2024
+ ```
2025
+
2026
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
2027
+
2028
+ ```
2029
+ ruby -r glimmer-dsl-libui -e "require 'examples/basic_table_image'"
2030
+ ```
2031
+
2032
+ Mac
2033
+
2034
+ ![glimmer-dsl-libui-mac-basic-table-image.png](images/glimmer-dsl-libui-mac-basic-table-image.png)
2035
+
2036
+ Linux
2037
+
2038
+ ![glimmer-dsl-libui-linux-basic-table-image.png](images/glimmer-dsl-libui-linux-basic-table-image.png)
2039
+
2040
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
2041
+
2042
+ ```ruby
2043
+ # NOTE:
2044
+ # This example displays images that can be freely downloaded from the Studio Ghibli website.
2045
+
2046
+ require 'libui'
2047
+ require 'chunky_png'
2048
+ require 'open-uri'
2049
+
2050
+ UI = LibUI
2051
+
2052
+ UI.init
2053
+
2054
+ main_window = UI.new_window('The Red Turtle', 310, 350, 0)
2055
+
2056
+ hbox = UI.new_horizontal_box
2057
+ UI.window_set_child(main_window, hbox)
2058
+
2059
+ IMAGES = []
2060
+
2061
+ 50.times do |i|
2062
+ url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
2063
+ puts "Processing Image: #{url}"
2064
+ f = URI.open(url)
2065
+ canvas = ChunkyPNG::Canvas.from_io(f)
2066
+ f.close
2067
+ data = canvas.to_rgba_stream
2068
+ width = canvas.width
2069
+ height = canvas.height
2070
+ image = UI.new_image(width, height)
2071
+ UI.image_append(image, data, width, height, width * 4)
2072
+ IMAGES << image
2073
+ rescue StandardError => e
2074
+ warn url, e.message
2075
+ end
2076
+
2077
+ # Protects BlockCaller objects from garbage collection.
2078
+ @blockcaller = []
2079
+ def rbcallback(*args, &block)
2080
+ args << [0] if args.size == 1 # Argument types are ommited
2081
+ blockcaller = Fiddle::Closure::BlockCaller.new(*args, &block)
2082
+ @blockcaller << blockcaller
2083
+ blockcaller
2084
+ end
2085
+
2086
+ model_handler = UI::FFI::TableModelHandler.malloc
2087
+ model_handler.NumColumns = rbcallback(4) { 1 }
2088
+ model_handler.ColumnType = rbcallback(4) { 1 } # Image
2089
+ model_handler.NumRows = rbcallback(4) { IMAGES.size }
2090
+ model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, _column|
2091
+ UI.new_table_value_image(IMAGES[row])
2092
+ end
2093
+ model_handler.SetCellValue = rbcallback(0, [0]) {}
2094
+
2095
+ model = UI.new_table_model(model_handler)
2096
+
2097
+ table_params = UI::FFI::TableParams.malloc
2098
+ table_params.Model = model
2099
+ table_params.RowBackgroundColorModelColumn = -1
2100
+
2101
+ table = UI.new_table(table_params)
2102
+ UI.table_append_image_column(table, 'www.ghibli.jp/works/red-turtle', 0)
2103
+
2104
+ UI.box_append(hbox, table, 1)
2105
+ UI.control_show(main_window)
2106
+
2107
+ UI.window_on_closing(main_window) do
2108
+ puts 'Bye Bye'
2109
+ UI.control_destroy(main_window)
2110
+ UI.free_table_model(model)
2111
+ IMAGES.each { |i| UI.free_image(i) }
2112
+ UI.quit
2113
+ 0
2114
+ end
2115
+
2116
+ UI.main
2117
+ UI.quit
2118
+ ```
2119
+
2120
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
2121
+
2122
+ ```ruby
2123
+ # NOTE:
2124
+ # This example displays images that can be freely downloaded from the Studio Ghibli website.
2125
+
2126
+ require 'glimmer-dsl-libui'
2127
+ require 'chunky_png'
2128
+ require 'open-uri'
2129
+
2130
+ include Glimmer
2131
+
2132
+ IMAGE_ROWS = []
2133
+
2134
+ 50.times do |i|
2135
+ url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
2136
+ puts "Processing Image: #{url}"
2137
+ f = URI.open(url)
2138
+ canvas = ChunkyPNG::Canvas.from_io(f)
2139
+ f.close
2140
+ data = canvas.to_rgba_stream
2141
+ width = canvas.width
2142
+ height = canvas.height
2143
+ img = image(width, height) {
2144
+ image_part(data, width, height, width * 4)
2145
+ }
2146
+ IMAGE_ROWS << [img] # array of one column cell
2147
+ rescue StandardError => e
2148
+ warn url, e.message
2149
+ end
2150
+
2151
+ window('The Red Turtle', 310, 350, false) {
2152
+ horizontal_box {
2153
+ table {
2154
+ image_column('www.ghibli.jp/works/red-turtle', 0)
2155
+
2156
+ cell_rows IMAGE_ROWS
2157
+ }
2158
+ }
2159
+
2160
+ on_closing do
2161
+ puts 'Bye Bye'
2162
+ end
2163
+ }.show
2164
+ ```
2165
+
2166
+ ### Basic Table Image Text
2167
+
2168
+ This example has a prerequisite of installing `chunky_png` Ruby gem:
2169
+
2170
+ ```
2171
+ gem install chunky_png -v1.4.0
2172
+ ```
2173
+
2174
+ Also, note that behavior varies per platform (i.e. how `table` chooses to size images by default).
2175
+
2176
+ [examples/basic_table_image_text.rb](examples/basic_table_image_text.rb)
2177
+
2178
+ Run with this command from the root of the project if you cloned the project:
2179
+
2180
+ ```
2181
+ ruby -r './lib/glimmer-dsl-libui' examples/basic_table_image_text.rb
2182
+ ```
2183
+
2184
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
2185
+
2186
+ ```
2187
+ ruby -r glimmer-dsl-libui -e "require 'examples/basic_table_image_text'"
2188
+ ```
2189
+
2190
+ Mac
2191
+
2192
+ ![glimmer-dsl-libui-mac-basic-table-image-text.png](images/glimmer-dsl-libui-mac-basic-table-image-text.png)
2193
+
2194
+ Linux
2195
+
2196
+ ![glimmer-dsl-libui-linux-basic-table-image-text.png](images/glimmer-dsl-libui-linux-basic-table-image-text.png)
2197
+
2198
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
2199
+
2200
+ ```ruby
2201
+ # NOTE:
2202
+ # This example displays images that can be freely downloaded from the Studio Ghibli website.
2203
+
2204
+ require 'glimmer-dsl-libui'
2205
+ require 'chunky_png'
2206
+ require 'open-uri'
2207
+
2208
+ include Glimmer
2209
+
2210
+ IMAGE_ROWS = []
2211
+
2212
+ 5.times do |i|
2213
+ url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
2214
+ puts "Processing Image: #{url}"
2215
+ f = URI.open(url)
2216
+ canvas = ChunkyPNG::Canvas.from_io(f)
2217
+ f.close
2218
+ data = canvas.to_rgba_stream
2219
+ width = canvas.width
2220
+ height = canvas.height
2221
+ img = image(width, height) {
2222
+ image_part(data, width, height, width * 4)
2223
+ }
2224
+ text = url.sub('https://www.ghibli.jp/gallery/thumb-redturtle', '').sub('.png', '')
2225
+ IMAGE_ROWS << [[img, text], text, text, [img, text]]
2226
+ rescue StandardError => e
2227
+ warn url, e.message
2228
+ end
2229
+
2230
+ window('The Red Turtle', 900, 350) {
2231
+ horizontal_box {
2232
+ table {
2233
+ image_text_column('image/number')
2234
+ text_column('number')
2235
+ text_column('number (editable)') {
2236
+ editable true
2237
+ }
2238
+ image_text_column('image/number (editable)') {
2239
+ editable true
2240
+ }
2241
+
2242
+ cell_rows IMAGE_ROWS
2243
+ }
2244
+ }
2245
+ }.show
2246
+ ```
2247
+
1876
2248
  ## Contributing to glimmer-dsl-libui
1877
2249
 
1878
2250
  - Check out the latest master to make sure the feature hasn't been
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.17
1
+ 0.0.21
@@ -0,0 +1,43 @@
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
+ f = URI.open(url)
18
+ canvas = ChunkyPNG::Canvas.from_io(f)
19
+ f.close
20
+ data = canvas.to_rgba_stream
21
+ width = canvas.width
22
+ height = canvas.height
23
+ img = image(width, height) {
24
+ image_part(data, width, height, width * 4)
25
+ }
26
+ IMAGE_ROWS << [img] # array of one column cell
27
+ rescue StandardError => e
28
+ warn url, e.message
29
+ end
30
+
31
+ window('The Red Turtle', 310, 350, false) {
32
+ horizontal_box {
33
+ table {
34
+ image_column('www.ghibli.jp/works/red-turtle')
35
+
36
+ cell_rows IMAGE_ROWS
37
+ }
38
+ }
39
+
40
+ on_closing do
41
+ puts 'Bye Bye'
42
+ end
43
+ }.show
@@ -0,0 +1,47 @@
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
+ f = URI.open(url)
18
+ canvas = ChunkyPNG::Canvas.from_io(f)
19
+ f.close
20
+ data = canvas.to_rgba_stream
21
+ width = canvas.width
22
+ height = canvas.height
23
+ img = image(width, height) {
24
+ image_part(data, width, height, width * 4)
25
+ }
26
+ text = url.sub('https://www.ghibli.jp/gallery/thumb-redturtle', '').sub('.png', '')
27
+ IMAGE_ROWS << [[img, text], text, text, [img, text]]
28
+ rescue StandardError => e
29
+ warn url, e.message
30
+ end
31
+
32
+ window('The Red Turtle', 900, 350) {
33
+ horizontal_box {
34
+ table {
35
+ image_text_column('image/number')
36
+ text_column('number')
37
+ text_column('number (editable)') {
38
+ editable true
39
+ }
40
+ image_text_column('image/number (editable)') {
41
+ editable true
42
+ }
43
+
44
+ cell_rows IMAGE_ROWS
45
+ }
46
+ }
47
+ }.show
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'glimmer-dsl-libui'
4
+
5
+ include Glimmer
6
+
7
+ data = [
8
+ %w[cat calm meow],
9
+ %w[dog loyal woof],
10
+ %w[chicken bird cock-a-doodle-doo],
11
+ %w[hourse fast neigh],
12
+ %w[cow slow moo]
13
+ ]
14
+
15
+ window('Editable column animal sounds', 400, 200) {
16
+ horizontal_box {
17
+ table {
18
+ text_column('Animal')
19
+ text_column('Description')
20
+ text_column('Sound (Editable)') {
21
+ editable true
22
+ }
23
+
24
+ cell_rows data
25
+ }
26
+ }
27
+
28
+ on_closing do
29
+ puts 'Bye Bye'
30
+ end
31
+ }.show
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'glimmer-dsl-libui'
4
+
5
+ include Glimmer
6
+
7
+ data = [
8
+ %w[cat meow],
9
+ %w[dog woof],
10
+ %w[chicken cock-a-doodle-doo],
11
+ %w[hourse neigh],
12
+ %w[cow moo]
13
+ ]
14
+
15
+ window('Editable animal sounds', 300, 200) {
16
+ horizontal_box {
17
+ table {
18
+ text_column('Animal')
19
+ text_column('Description')
20
+
21
+ cell_rows data
22
+ editable true
23
+ }
24
+ }
25
+
26
+ on_closing do
27
+ puts 'Bye Bye'
28
+ end
29
+ }.show
Binary file
@@ -42,7 +42,7 @@ module Glimmer
42
42
 
43
43
  def destroy_child(child)
44
44
  ::LibUI.send("box_delete", @libui, children.index(child))
45
- ControlProxy.all_control_proxies.delete(child)
45
+ ControlProxy.control_proxies.delete(child)
46
46
  end
47
47
 
48
48
  private
@@ -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
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Common logic for all column proxy objects
27
+ module Column
28
+ def initialize(keyword, parent, args, &block)
29
+ @keyword = keyword
30
+ @parent_proxy = parent
31
+ @args = args
32
+ @block = block
33
+ @enabled = true
34
+ post_add_content if @block.nil?
35
+ end
36
+
37
+ def name
38
+ @args.first
39
+ end
40
+
41
+ # column index used in table append column API call
42
+ # expanded to ensure DualColumn index accounts for two columns acting as one
43
+ def column_index
44
+ @column_index ||= @parent_proxy.send(:next_column_index)
45
+ end
46
+
47
+ # actual index within table columns (disregarding nil fillings that account for DualColumn instances)
48
+ def index
49
+ @parent_proxy.columns.compact.index(self)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -33,7 +33,7 @@ module Glimmer
33
33
  end
34
34
 
35
35
  def create(keyword, parent, args, &block)
36
- widget_proxy_class(keyword).new(keyword, parent, args, &block).tap {|c| all_control_proxies << c}
36
+ widget_proxy_class(keyword).new(keyword, parent, args, &block).tap {|c| control_proxies << c}
37
37
  end
38
38
 
39
39
  def widget_proxy_class(keyword)
@@ -46,13 +46,13 @@ module Glimmer
46
46
  end
47
47
 
48
48
  # autosave all controls in this array to avoid garbage collection
49
- def all_control_proxies
50
- @@all_control_proxies = [] unless defined?(@@all_control_proxies)
51
- @@all_control_proxies
49
+ def control_proxies
50
+ @@control_proxies = [] unless defined?(@@control_proxies)
51
+ @@control_proxies
52
52
  end
53
53
 
54
54
  def main_window_proxy
55
- all_control_proxies.find {|c| c.is_a?(Glimmer::LibUI::WindowProxy)}
55
+ control_proxies.find {|c| c.is_a?(Glimmer::LibUI::WindowProxy)}
56
56
  end
57
57
 
58
58
  def integer_to_boolean(int)
@@ -64,7 +64,11 @@ module Glimmer
64
64
  end
65
65
 
66
66
  def menu_proxies
67
- all_control_proxies.select {|c| c.keyword == 'menu' }
67
+ control_proxies.select {|c| c.keyword == 'menu' }
68
+ end
69
+
70
+ def image_proxies
71
+ control_proxies.select {|c| c.keyword == 'image' }
68
72
  end
69
73
 
70
74
  def new_control(keyword, args)
@@ -220,7 +224,7 @@ module Glimmer
220
224
 
221
225
  def default_destroy
222
226
  send_to_libui('destroy')
223
- ControlProxy.all_control_proxies.delete(self)
227
+ ControlProxy.control_proxies.delete(self)
224
228
  end
225
229
 
226
230
  def enabled(value = nil)
@@ -0,0 +1,40 @@
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
+
24
+ module Glimmer
25
+ module LibUI
26
+ # A dual column is one that represents two values (e.g. image and text or checkbox and text)
27
+ # It is meant to be included in a column proxy class that already includes Column
28
+ module DualColumn
29
+ def second_column_index
30
+ column_index + 1
31
+ end
32
+
33
+ def column_index
34
+ @column_index ||= @parent_proxy.send(:next_column_index).tap do
35
+ @parent_proxy.send(:next_column_index)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -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
+ require 'glimmer/libui/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ module EditableColumn
27
+ def editable(value = nil)
28
+ if value.nil?
29
+ @editable
30
+ else
31
+ @editable = !!value
32
+ end
33
+ end
34
+ alias editable= editable
35
+ alias set_editable editable
36
+ alias editable? editable
37
+
38
+ private
39
+
40
+ def editable_value
41
+ (@parent_proxy.editable? || editable?) ? -2 : -1
42
+ end
43
+ end
44
+ end
45
+ end
@@ -39,7 +39,7 @@ module Glimmer
39
39
 
40
40
  def destroy_child(child)
41
41
  ::LibUI.send("form_delete", @libui, children.index(child))
42
- ControlProxy.all_control_proxies.delete(child)
42
+ ControlProxy.control_proxies.delete(child)
43
43
  end
44
44
 
45
45
  private
@@ -0,0 +1,40 @@
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/column'
24
+
25
+ module Glimmer
26
+ module LibUI
27
+ # Proxy for LibUI image column objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class ImageColumnProxy < ControlProxy
31
+ include Column
32
+
33
+ private
34
+
35
+ def build_control
36
+ @parent_proxy.append_image_column(name, column_index)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,37 @@
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
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI image part objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class ImagePartProxy < ControlProxy
30
+ private
31
+
32
+ def build_control
33
+ @libui = @parent_proxy.append(*@args)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,42 @@
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/column'
24
+
25
+ module Glimmer
26
+ module LibUI
27
+ # Proxy for LibUI image text column objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class ImageTextColumnProxy < ControlProxy
31
+ include Column
32
+ include DualColumn
33
+ include EditableColumn
34
+
35
+ private
36
+
37
+ def build_control
38
+ @parent_proxy.append_image_text_column(name, column_index, second_column_index, editable_value)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -50,6 +50,8 @@ module Glimmer
50
50
 
51
51
  def post_initialize_child(child)
52
52
  @columns << child
53
+ # add an extra complementary nil column if it is a dual column (i.e. ImageTextColumnProxy or CheckboxTextColumnProxy
54
+ @columns << nil if child.is_a?(DualColumn)
53
55
  end
54
56
 
55
57
  def destroy
@@ -61,21 +63,82 @@ module Glimmer
61
63
  if rows.nil?
62
64
  @cell_rows
63
65
  else
66
+ rows = rows.map do |row|
67
+ row.map do |cell|
68
+ if cell.respond_to?(:libui)
69
+ cell.libui
70
+ elsif cell.is_a?(Array)
71
+ cell.map { |inner_cell| inner_cell.respond_to?(:libui) ? inner_cell.libui : inner_cell }
72
+ else
73
+ cell
74
+ end
75
+ end
76
+ end
64
77
  @cell_rows = rows
65
78
  end
66
79
  end
67
80
  alias cell_rows= cell_rows
68
81
  alias set_cell_rows cell_rows
69
82
 
83
+ def expanded_cell_rows
84
+ cell_rows.map do |row|
85
+ row.flatten(1)
86
+ end
87
+ end
88
+
89
+ def editable(value = nil)
90
+ if value.nil?
91
+ @editable
92
+ else
93
+ @editable = !!value
94
+ end
95
+ end
96
+ alias editable= editable
97
+ alias set_editable editable
98
+ alias editable? editable
99
+
70
100
  private
71
101
 
72
102
  def build_control
73
103
  @model_handler = ::LibUI::FFI::TableModelHandler.malloc
74
- @model_handler.NumColumns = rbcallback(4) { @columns.count }
75
- @model_handler.ColumnType = rbcallback(4) { 0 } # TODO derive from @columns when supporting multiple column types in the future
104
+ @model_handler.NumColumns = rbcallback(4) { @columns.map {|c| c.is_a?(DualColumn) ? 2 : 1}.sum }
105
+ @model_handler.ColumnType = rbcallback(4, [1, 1, 4]) do |_, _, column|
106
+ case @columns[column]
107
+ when TextColumnProxy, NilClass
108
+ 0
109
+ when ImageColumnProxy, ImageTextColumnProxy
110
+ 1
111
+ # when CheckboxColumnProxy
112
+ # 2
113
+ # when CheckboxTextColumnProxy
114
+ # 2
115
+ # when ProgressBarColumnProxy
116
+ # 2
117
+ # when ButtonColumnProxy
118
+ # 0
119
+ end
120
+ end
76
121
  @model_handler.NumRows = rbcallback(4) { cell_rows.count }
77
122
  @model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
78
- ::LibUI.new_table_value_string((@cell_rows[row] && @cell_rows[row][column]).to_s)
123
+ the_cell_rows = expanded_cell_rows
124
+ case @columns[column]
125
+ when TextColumnProxy, NilClass
126
+ ::LibUI.new_table_value_string((expanded_cell_rows[row] && expanded_cell_rows[row][column]).to_s)
127
+ when ImageColumnProxy, ImageTextColumnProxy
128
+ ::LibUI.new_table_value_image((expanded_cell_rows[row] && expanded_cell_rows[row][column]))
129
+ end
130
+ end
131
+ @model_handler.SetCellValue = rbcallback(0, [1, 1, 4, 4, 1]) do |_, _, row, column, val|
132
+ case @columns[column]
133
+ when TextColumnProxy
134
+ column = @columns[column].index
135
+ @cell_rows[row] ||= []
136
+ @cell_rows[row][column] = ::LibUI.table_value_string(val).to_s
137
+ when NilClass
138
+ # TODO ensure this works for editable table
139
+ column = @columns[column - 1].index
140
+ @cell_rows[row][column][1] = ::LibUI.table_value_string(val).to_s
141
+ end
79
142
  end
80
143
 
81
144
  @model = ::LibUI.new_table_model(@model_handler)
@@ -86,7 +149,7 @@ module Glimmer
86
149
 
87
150
  @libui = ControlProxy.new_control(@keyword, [@table_params])
88
151
  @libui.tap do
89
- @columns.each {|column| column.send(:build_control) }
152
+ @columns.each {|column| column&.send(:build_control) }
90
153
  end
91
154
  end
92
155
 
@@ -100,6 +163,11 @@ module Glimmer
100
163
  blockcaller
101
164
  end
102
165
 
166
+ def next_column_index
167
+ @next_column_index ||= -1
168
+ @next_column_index += 1
169
+ end
170
+
103
171
  end
104
172
  end
105
173
  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/column'
23
24
 
24
25
  module Glimmer
25
26
  module LibUI
@@ -27,24 +28,13 @@ module Glimmer
27
28
  #
28
29
  # Follows the Proxy Design Pattern
29
30
  class TextColumnProxy < ControlProxy
30
- def initialize(keyword, parent, args, &block)
31
- # TODO eventually move this to a supermodule ColumnProxy
32
- @keyword = keyword
33
- @parent_proxy = parent
34
- @args = args
35
- @block = block
36
- @enabled = true
37
- post_add_content if @block.nil?
38
- end
39
-
40
- def name
41
- @args.first
42
- end
43
-
31
+ include Column
32
+ include EditableColumn
33
+
44
34
  private
45
35
 
46
36
  def build_control
47
- @libui = @parent_proxy.append_text_column(name, @parent_proxy.columns.map(&:libui).compact.count, -1) # -1 for non-editable for now until editing is supported
37
+ @parent_proxy.append_text_column(name, column_index, editable_value)
48
38
  end
49
39
  end
50
40
  end
@@ -43,6 +43,7 @@ module Glimmer
43
43
 
44
44
  def destroy
45
45
  super
46
+ ControlProxy.image_proxies.each { |image_proxy| ::LibUI.free_image(image_proxy.libui) }
46
47
  @on_destroy_procs&.each { |on_destroy_proc| on_destroy_proc.call(self)}
47
48
  end
48
49
 
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.0.17
4
+ version: 0.0.21
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-09-23 00:00:00.000000000 Z
11
+ date: 2021-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -162,8 +162,22 @@ dependencies:
162
162
  - - "~>"
163
163
  - !ruby/object:Gem::Version
164
164
  version: 0.7.0
165
+ - !ruby/object:Gem::Dependency
166
+ name: chunky_png
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: 1.4.0
172
+ type: :development
173
+ prerelease: false
174
+ version_requirements: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - "~>"
177
+ - !ruby/object:Gem::Version
178
+ version: 1.4.0
165
179
  description: Glimmer DSL for LibUI - Prerequisite-Free Ruby Desktop Development GUI
166
- Library (no need to pre-install any prerequisites. Just install the gem and have
180
+ Library (No need to pre-install any prerequisites. Just install the gem and have
167
181
  platform-independent native GUI that just works!)
168
182
  email: andy.am@gmail.com
169
183
  executables:
@@ -183,11 +197,15 @@ files:
183
197
  - examples/basic_button.rb
184
198
  - examples/basic_entry.rb
185
199
  - examples/basic_table.rb
200
+ - examples/basic_table_image.rb
201
+ - examples/basic_table_image_text.rb
186
202
  - examples/basic_window.rb
187
203
  - examples/basic_window2.rb
188
204
  - examples/color_button.rb
189
205
  - examples/control_gallery.rb
190
206
  - examples/date_time_picker.rb
207
+ - examples/editable_column_table.rb
208
+ - examples/editable_table.rb
191
209
  - examples/font_button.rb
192
210
  - examples/form.rb
193
211
  - examples/grid.rb
@@ -210,16 +228,22 @@ files:
210
228
  - lib/glimmer/libui/check_menu_item_proxy.rb
211
229
  - lib/glimmer/libui/checkbox_proxy.rb
212
230
  - lib/glimmer/libui/color_button_proxy.rb
231
+ - lib/glimmer/libui/column.rb
213
232
  - lib/glimmer/libui/combobox_proxy.rb
214
233
  - lib/glimmer/libui/control_proxy.rb
215
234
  - lib/glimmer/libui/date_picker_proxy.rb
216
235
  - lib/glimmer/libui/date_time_picker_proxy.rb
236
+ - lib/glimmer/libui/dual_column.rb
237
+ - lib/glimmer/libui/editable_column.rb
217
238
  - lib/glimmer/libui/editable_combobox_proxy.rb
218
239
  - lib/glimmer/libui/font_button_proxy.rb
219
240
  - lib/glimmer/libui/form_proxy.rb
220
241
  - lib/glimmer/libui/grid_proxy.rb
221
242
  - lib/glimmer/libui/group_proxy.rb
222
243
  - lib/glimmer/libui/horizontal_box_proxy.rb
244
+ - lib/glimmer/libui/image_column_proxy.rb
245
+ - lib/glimmer/libui/image_part_proxy.rb
246
+ - lib/glimmer/libui/image_text_column_proxy.rb
223
247
  - lib/glimmer/libui/label_proxy.rb
224
248
  - lib/glimmer/libui/menu_item_proxy.rb
225
249
  - lib/glimmer/libui/menu_proxy.rb