glimmer-dsl-libui 0.0.17 → 0.0.18

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: fc7805628b0893f2d955c437f8e46932acfbac8db7576cdd28021b12cfe8d942
4
+ data.tar.gz: 4915a6b72d733ca9d4ba7fedf08abc66377bf9a9cd6eca288f1b1a60556951f2
5
5
  SHA512:
6
- metadata.gz: 326d75305142c5773a9dfd487fb595e7271c26a003ff1db10771a5e805e8c77eb567f6f56b54ac7ab721e2ed532f70ccdd9fa42437f6fd12c616f98d28c91f0e
7
- data.tar.gz: a60432231078bf85d00e8882657eae577eeb99cf0b71a57f12c485c933577f8f4f7d98ec1cb6337f4ab4f1d02bf0c0061a618b9f998c16dc05641ad6efc8352f
6
+ metadata.gz: ef4ac023c7fcb8638a335fd4cf28db03b8d784cb27f63b3edb411c05c5395740d7eb0593f9716657a516314bd6d1effd581abfdbb07de6c1a18225d037344472
7
+ data.tar.gz: 2ee4dab775fd3ae4235b924f37879d84a61dffce138b0b25cd495464931ae20efc5f45ed34d4c6f9767dc2fc15bbb30eafb70fe37efa56de0d8505ea144be010
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.18
4
+
5
+ - Support examples/basic_table_image.rb
6
+ - Support table `image_column`
7
+ - Support `image` and `image_part` for building images from rgba byte arrays
8
+ - Rename `Glimmer::LibUI::ControlProxy.all_control_proxies` to `Glimmer::LibUI::ControlProxy.control_proxies`
9
+ - Add `Glimmer::LibUI::ControlProxy.image_proxies`
10
+
3
11
  ## 0.0.17
4
12
 
5
13
  - 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.18
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.18](#-glimmer-dsl-for-libui-0018)
47
47
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
48
48
  - [Usage](#usage)
49
49
  - [API](#api)
@@ -157,7 +157,7 @@ gem install glimmer-dsl-libui
157
157
  Or install via Bundler `Gemfile`:
158
158
 
159
159
  ```ruby
160
- gem 'glimmer-dsl-libui', '~> 0.0.17'
160
+ gem 'glimmer-dsl-libui', '~> 0.0.18'
161
161
  ```
162
162
 
163
163
  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 +227,9 @@ Control(Args) | Properties | Listeners
227
227
  `group(text as String)` | `margined` (Boolean), `title` (`String`) | None
228
228
  `horizontal_box` | `padded` (Boolean) | None
229
229
  `horizontal_separator` | None | None
230
+ `image(width as Numeric, height as Numeric)` | None | None
231
+ `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
232
+ `image_column(name as String)` | None | None
230
233
  `label(text as String)` | `text` (`String`) | None
231
234
  `menu(text as String)` | None | None
232
235
  `menu_item(text as String)` | `checked` (Boolean) | `on_clicked`
@@ -279,7 +282,9 @@ Control(Args) | Properties | Listeners
279
282
 
280
283
  ### Extra Operations
281
284
 
282
- - `ControlProxy::all_control_proxies`: returns all instantiated control proxies in the application
285
+ - `ControlProxy::control_proxies`: returns all instantiated control proxies in the application
286
+ - `ControlProxy::menu_proxies`: returns all instantiated `menu` proxies in the application
287
+ - `ControlProxy::image_proxies`: returns all instantiated `image` proxies in the application
283
288
  - `ControlProxy::main_window_proxy`: returns the first window proxy instantiated in the application
284
289
  - `ControlProxy#window_proxy`: returns the window proxy parent for a control
285
290
 
@@ -307,6 +312,8 @@ Control(Args) | Properties | Listeners
307
312
  - 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
313
  - 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
314
  - The `table` control automatically constructs required `TableModelHandler`, `TableModel`, and `TableParams`, calculating all their arguments from `cell_rows` property (e.g. `NumRows`)
315
+ - Table model instances are automatically freed from memory after `window` is destroyed.
316
+ - `image` instances are automatically freed from memory after `window` is destroyed.
310
317
 
311
318
  ### API Gotchas
312
319
 
@@ -500,6 +507,23 @@ window('hello world', 300, 200, true) {
500
507
  }.show
501
508
  ```
502
509
 
510
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
511
+
512
+ ```ruby
513
+ require 'glimmer-dsl-libui'
514
+
515
+ include Glimmer
516
+
517
+ window { # first 3 args can be set via properties with 4th arg has_menubar=true by default
518
+ title 'hello world'
519
+ content_size 300, 200
520
+
521
+ on_closing do
522
+ puts 'Bye Bye'
523
+ end
524
+ }.show
525
+ ```
526
+
503
527
  ### Basic Button
504
528
 
505
529
  [examples/basic_button.rb](examples/basic_button.rb)
@@ -564,7 +588,7 @@ require 'glimmer-dsl-libui'
564
588
 
565
589
  include Glimmer
566
590
 
567
- window('hello world', 300, 200, true) { |w|
591
+ window('hello world', 300, 200) { |w|
568
592
  button('Button') {
569
593
  on_clicked do
570
594
  msg_box(w, 'Information', 'You clicked the button')
@@ -577,23 +601,6 @@ window('hello world', 300, 200, true) { |w|
577
601
  }.show
578
602
  ```
579
603
 
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
604
  ### Basic Entry
598
605
 
599
606
  [examples/basic_entry.rb](examples/basic_entry.rb)
@@ -1873,6 +1880,164 @@ window('Animal sounds', 300, 200) {
1873
1880
  }.show
1874
1881
  ```
1875
1882
 
1883
+ ### Basic Table Image
1884
+
1885
+ This example has a prerequisite of installing `chunky_png` Ruby gem:
1886
+
1887
+ ```
1888
+ gem install chunky_png -v1.4.0
1889
+ ```
1890
+
1891
+ Also, note that behavior varies per platform (i.e. how `table` chooses to size images by default).
1892
+
1893
+ [examples/basic_table_image.rb](examples/basic_table_image.rb)
1894
+
1895
+ Run with this command from the root of the project if you cloned the project:
1896
+
1897
+ ```
1898
+ ruby -r './lib/glimmer-dsl-libui' examples/basic_table_image.rb
1899
+ ```
1900
+
1901
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1902
+
1903
+ ```
1904
+ ruby -r glimmer-dsl-libui -e "require 'examples/basic_table_image'"
1905
+ ```
1906
+
1907
+ Mac
1908
+
1909
+ ![glimmer-dsl-libui-mac-basic-table-image.png](images/glimmer-dsl-libui-mac-basic-table-image.png)
1910
+
1911
+ Linux
1912
+
1913
+ ![glimmer-dsl-libui-linux-basic-table-image.png](images/glimmer-dsl-libui-linux-basic-table-image.png)
1914
+
1915
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
1916
+
1917
+ ```ruby
1918
+ # NOTE:
1919
+ # This example displays images that can be freely downloaded from the Studio Ghibli website.
1920
+
1921
+ require 'libui'
1922
+ require 'chunky_png'
1923
+ require 'open-uri'
1924
+
1925
+ UI = LibUI
1926
+
1927
+ UI.init
1928
+
1929
+ main_window = UI.new_window('The Red Turtle', 310, 350, 0)
1930
+
1931
+ hbox = UI.new_horizontal_box
1932
+ UI.window_set_child(main_window, hbox)
1933
+
1934
+ IMAGES = []
1935
+
1936
+ 50.times do |i|
1937
+ url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
1938
+ puts "Processing Image: #{url}"
1939
+ f = URI.open(url)
1940
+ canvas = ChunkyPNG::Canvas.from_io(f)
1941
+ f.close
1942
+ data = canvas.to_rgba_stream
1943
+ width = canvas.width
1944
+ height = canvas.height
1945
+ image = UI.new_image(width, height)
1946
+ UI.image_append(image, data, width, height, width * 4)
1947
+ IMAGES << image
1948
+ rescue StandardError => e
1949
+ warn url, e.message
1950
+ end
1951
+
1952
+ # Protects BlockCaller objects from garbage collection.
1953
+ @blockcaller = []
1954
+ def rbcallback(*args, &block)
1955
+ args << [0] if args.size == 1 # Argument types are ommited
1956
+ blockcaller = Fiddle::Closure::BlockCaller.new(*args, &block)
1957
+ @blockcaller << blockcaller
1958
+ blockcaller
1959
+ end
1960
+
1961
+ model_handler = UI::FFI::TableModelHandler.malloc
1962
+ model_handler.NumColumns = rbcallback(4) { 1 }
1963
+ model_handler.ColumnType = rbcallback(4) { 1 } # Image
1964
+ model_handler.NumRows = rbcallback(4) { IMAGES.size }
1965
+ model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, _column|
1966
+ UI.new_table_value_image(IMAGES[row])
1967
+ end
1968
+ model_handler.SetCellValue = rbcallback(0, [0]) {}
1969
+
1970
+ model = UI.new_table_model(model_handler)
1971
+
1972
+ table_params = UI::FFI::TableParams.malloc
1973
+ table_params.Model = model
1974
+ table_params.RowBackgroundColorModelColumn = -1
1975
+
1976
+ table = UI.new_table(table_params)
1977
+ UI.table_append_image_column(table, 'www.ghibli.jp/works/red-turtle', 0)
1978
+
1979
+ UI.box_append(hbox, table, 1)
1980
+ UI.control_show(main_window)
1981
+
1982
+ UI.window_on_closing(main_window) do
1983
+ puts 'Bye Bye'
1984
+ UI.control_destroy(main_window)
1985
+ UI.free_table_model(model)
1986
+ IMAGES.each { |i| UI.free_image(i) }
1987
+ UI.quit
1988
+ 0
1989
+ end
1990
+
1991
+ UI.main
1992
+ UI.quit
1993
+ ```
1994
+
1995
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1996
+
1997
+ ```ruby
1998
+ # NOTE:
1999
+ # This example displays images that can be freely downloaded from the Studio Ghibli website.
2000
+
2001
+ require 'glimmer-dsl-libui'
2002
+ require 'chunky_png'
2003
+ require 'open-uri'
2004
+
2005
+ include Glimmer
2006
+
2007
+ IMAGE_ROWS = []
2008
+
2009
+ 50.times do |i|
2010
+ url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
2011
+ puts "Processing Image: #{url}"
2012
+ f = URI.open(url)
2013
+ canvas = ChunkyPNG::Canvas.from_io(f)
2014
+ f.close
2015
+ data = canvas.to_rgba_stream
2016
+ width = canvas.width
2017
+ height = canvas.height
2018
+ img = image(width, height) {
2019
+ image_part(data, width, height, width * 4)
2020
+ }
2021
+ IMAGE_ROWS << [img] # array of one column cell
2022
+ rescue StandardError => e
2023
+ warn url, e.message
2024
+ end
2025
+
2026
+ window('The Red Turtle', 310, 350, false) {
2027
+ horizontal_box {
2028
+ table {
2029
+ image_column('www.ghibli.jp/works/red-turtle', 0)
2030
+
2031
+ cell_rows IMAGE_ROWS
2032
+ }
2033
+
2034
+ }
2035
+ on_closing do
2036
+ puts 'Bye Bye'
2037
+ end
2038
+ }.show
2039
+ ```
2040
+
1876
2041
  ## Contributing to glimmer-dsl-libui
1877
2042
 
1878
2043
  - 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.18
@@ -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
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,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
+
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
+ end
41
+ end
42
+ 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)
@@ -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
+ @libui = @parent_proxy.append_image_column(name, @parent_proxy.columns.map(&:libui).compact.count)
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
@@ -61,6 +61,7 @@ module Glimmer
61
61
  if rows.nil?
62
62
  @cell_rows
63
63
  else
64
+ rows = rows.map {|row| row.map {|cell| cell.respond_to?(:libui) ? cell.libui : cell }}
64
65
  @cell_rows = rows
65
66
  end
66
67
  end
@@ -72,10 +73,23 @@ module Glimmer
72
73
  def build_control
73
74
  @model_handler = ::LibUI::FFI::TableModelHandler.malloc
74
75
  @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
76
+ @model_handler.ColumnType = rbcallback(4) do
77
+ # TODO support different values for different columns
78
+ case @columns.first
79
+ when TextColumnProxy
80
+ 0
81
+ when ImageColumnProxy
82
+ 1
83
+ end
84
+ end
76
85
  @model_handler.NumRows = rbcallback(4) { cell_rows.count }
77
86
  @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)
87
+ case @columns[column]
88
+ when TextColumnProxy
89
+ ::LibUI.new_table_value_string((@cell_rows[row] && @cell_rows[row][column]).to_s)
90
+ when ImageColumnProxy
91
+ ::LibUI.new_table_value_image((@cell_rows[row] && @cell_rows[row][column]))
92
+ end
79
93
  end
80
94
 
81
95
  @model = ::LibUI.new_table_model(@model_handler)
@@ -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,20 +28,8 @@ 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
31
+ include Column
39
32
 
40
- def name
41
- @args.first
42
- end
43
-
44
33
  private
45
34
 
46
35
  def build_control
@@ -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.18
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-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -162,6 +162,20 @@ 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
180
  Library (no need to pre-install any prerequisites. Just install the gem and have
167
181
  platform-independent native GUI that just works!)
@@ -183,6 +197,7 @@ 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
186
201
  - examples/basic_window.rb
187
202
  - examples/basic_window2.rb
188
203
  - examples/color_button.rb
@@ -210,6 +225,7 @@ files:
210
225
  - lib/glimmer/libui/check_menu_item_proxy.rb
211
226
  - lib/glimmer/libui/checkbox_proxy.rb
212
227
  - lib/glimmer/libui/color_button_proxy.rb
228
+ - lib/glimmer/libui/column.rb
213
229
  - lib/glimmer/libui/combobox_proxy.rb
214
230
  - lib/glimmer/libui/control_proxy.rb
215
231
  - lib/glimmer/libui/date_picker_proxy.rb
@@ -220,6 +236,8 @@ files:
220
236
  - lib/glimmer/libui/grid_proxy.rb
221
237
  - lib/glimmer/libui/group_proxy.rb
222
238
  - lib/glimmer/libui/horizontal_box_proxy.rb
239
+ - lib/glimmer/libui/image_column_proxy.rb
240
+ - lib/glimmer/libui/image_part_proxy.rb
223
241
  - lib/glimmer/libui/label_proxy.rb
224
242
  - lib/glimmer/libui/menu_item_proxy.rb
225
243
  - lib/glimmer/libui/menu_proxy.rb