glimmer-dsl-libui 0.0.15 → 0.0.19

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: 45785cccb2a89070b2230fdae1c7418b48c6b8ac4682bf6ee0c2eb832f35bc1c
4
- data.tar.gz: 0a5544bef68a214ddb4ed55eb4ff71efa5916ce8c7e2d0b1c6d8f36d5b5fbd6f
3
+ metadata.gz: 032f3de542f72c7bec706935b9e233b59a861fc88568fef5dd1b1b788137674c
4
+ data.tar.gz: 9791ad59faff6d21dd4fa59668d65266b5da1ffbfa49c0bd5cfaf900ee2a2c8c
5
5
  SHA512:
6
- metadata.gz: '08005e8f56a310c7b534bfafde7e958617ee483985f30facf02a62a015d860a6378e4f7d5399b37fa5a247ef899a7092c313f120d5599a72d288bd3781a43820'
7
- data.tar.gz: befd92a20a6bc56c19049cfc385970bd8e113ae191c45ac3c3fffb513dd9140838229b79859392aed2e452d6e235d95059fe5d7847b3ac48cc5b4261aae50b26
6
+ metadata.gz: 013d2d62c31f7738a06bd41aefcef7b7646a570148d7e6f413971df7f938cdb2781d050ae25143c56d8c77cc9b50537f783991415b5a5169dfab75741f9f4dd2
7
+ data.tar.gz: 8bd2666d00a15e966f3ea7e5c391cb88a1307249e9af63a576b2d6f29989c79a89b245bcc6fc9a36286f38aa2cc2b386586b4328eecb08b58a53119b347b8162
data/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.19
4
+
5
+ - New examples/editable_table.rb
6
+ - Support editable `table` control
7
+ - Fix issue with table `text_column` repeating the first column as the second
8
+
9
+ ## 0.0.18
10
+
11
+ - Support examples/basic_table_image.rb
12
+ - Support table `image_column`
13
+ - Support `image` and `image_part` for building images from rgba byte arrays
14
+ - Rename `Glimmer::LibUI::ControlProxy.all_control_proxies` to `Glimmer::LibUI::ControlProxy.control_proxies`
15
+ - Add `Glimmer::LibUI::ControlProxy.image_proxies`
16
+
17
+ ## 0.0.17
18
+
19
+ - Support examples/basic_table.rb
20
+ - Support non-editable `table` control
21
+ - Support table `text_column`
22
+ - Support table `cell_rows` property as an `Array` (rows) of `Array`s (row columns) of cell values
23
+
24
+ ## 0.0.16
25
+
26
+ - Support ability to instantiate without args and set args as properties afterwards inside block (e.g. `window { title 'Greeter'; content_size 300, 400; button {text 'Greet'; on_clicked {puts 'Hi'}} }`)
27
+ - window (was supported before, but changed default title to empty string)
28
+ - button
29
+ - checkbox
30
+ - group
31
+ - label
32
+
3
33
  ## 0.0.15
4
34
 
5
35
  - New examples/form.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.15
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.19
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.15](#-glimmer-dsl-for-libui-0015)
46
+ - [Glimmer DSL for LibUI 0.0.19](#-glimmer-dsl-for-libui-0019)
47
47
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
48
48
  - [Usage](#usage)
49
49
  - [API](#api)
@@ -69,6 +69,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
69
69
  - [Date Time Picker](#date-time-picker)
70
70
  - [Grid](#grid)
71
71
  - [Form](#form)
72
+ - [Basic Table](#basic-table)
72
73
  - [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
73
74
  - [Help](#help)
74
75
  - [Issues](#issues)
@@ -156,7 +157,7 @@ gem install glimmer-dsl-libui
156
157
  Or install via Bundler `Gemfile`:
157
158
 
158
159
  ```ruby
159
- gem 'glimmer-dsl-libui', '~> 0.0.15'
160
+ gem 'glimmer-dsl-libui', '~> 0.0.19'
160
161
  ```
161
162
 
162
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.
@@ -226,6 +227,9 @@ Control(Args) | Properties | Listeners
226
227
  `group(text as String)` | `margined` (Boolean), `title` (`String`) | None
227
228
  `horizontal_box` | `padded` (Boolean) | None
228
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
229
233
  `label(text as String)` | `text` (`String`) | None
230
234
  `menu(text as String)` | None | None
231
235
  `menu_item(text as String)` | `checked` (Boolean) | `on_clicked`
@@ -241,9 +245,11 @@ Control(Args) | Properties | Listeners
241
245
  `spinbox(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
242
246
  `tab` | `margined` (Boolean), `num_pages` (`Integer`) | None
243
247
  `tab_item(name as String)` | `index` [read-only] (`Integer`), `margined` (Boolean), `name` [read-only] (`String`) | None
248
+ `table` | `cell_rows` (`Array` (rows) of `Arrays` (row columns) of cell values (e.g. `String` values)), `editable` as Boolean | None
249
+ `text_column(name as String)` | None | None
244
250
  `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`
245
251
  `vertical_box` | `padded` (Boolean) | None
246
- `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`
252
+ `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`
247
253
 
248
254
  ### Common Control Properties
249
255
  - `enabled` (Boolean)
@@ -276,7 +282,9 @@ Control(Args) | Properties | Listeners
276
282
 
277
283
  ### Extra Operations
278
284
 
279
- - `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
280
288
  - `ControlProxy::main_window_proxy`: returns the first window proxy instantiated in the application
281
289
  - `ControlProxy#window_proxy`: returns the window proxy parent for a control
282
290
 
@@ -284,9 +292,11 @@ Control(Args) | Properties | Listeners
284
292
 
285
293
  - `horizontal_box`, `vertical_box`, `grid`, and `form` controls have `padded` as `true` upon instantiation to ensure more user-friendly GUI by default
286
294
  - `group` controls have `margined` as `true` upon instantiation to ensure more user-friendly GUI by default
287
- - All controls nested under a `horizontal_box` or `vertical_box` have `stretchy` property (passed to `box_append` method) as `true` by default (filling maximum space)
288
- - `window` constructor args can be left off and have the following defaults when unspecified: `title` as `'Glimmer'`, `width` as `150`, `height` as `150`, and `has_menubar` as `true`)
295
+ - All controls nested under a `horizontal_box`, `vertical_box`, and `form` have `stretchy` property (fill maximum space) as `true` by default (passed to `box_append`/`form_append` method)
296
+ - `window` instatiation args can be left off, having the following defaults when unspecified: `title` as `''`, `width` as `150`, `height` as `150`, and `has_menubar` as `true`)
289
297
  - `window` has an `on_closing` listener by default that quits application upon hitting the close button (can be overridden with a manual `on_closing` implementation that returns integer `0` for success)
298
+ - `group` has `title` property default to `''` if not specified in instantiation args, so it can be instantiated without args with `title` property specified in nested block (e.g. `group {title 'Address'; ...}`)
299
+ - `button`, `checkbox`, and `label` have `text` default to `''` if not specified in instantiation args, so they can be instantiated without args with `text` property specified in nested block (e.g. `button {text 'Greet'; on_clicked {puts 'Hello'}}`)
290
300
  - `quit_menu_item` has an `on_clicked` listener by default that quits application upon selecting the quit menu item (can be overridden with a manual `on_clicked` implementation that returns integer `0` for success)
291
301
  - If an `on_closing` listener was defined on `window` and it does not return an integer, default exit behavior is assumed (`window.destroy` is called followed by `LibUI.quit`, returning `0`).
292
302
  - If an `on_clicked` listener was defined on `quit_menu_item` and it does not return an integer, default exit behavior is assumed (`main_window.destroy` is called followed by `LibUI.quit`, returning `0`).
@@ -301,6 +311,9 @@ Control(Args) | Properties | Listeners
301
311
  - When destroying a control nested under a `window` or `group`, it is automatically unset as their child to allow successful destruction
302
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`
303
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`)
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.
304
317
 
305
318
  ### API Gotchas
306
319
 
@@ -494,6 +507,23 @@ window('hello world', 300, 200, true) {
494
507
  }.show
495
508
  ```
496
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
+
497
527
  ### Basic Button
498
528
 
499
529
  [examples/basic_button.rb](examples/basic_button.rb)
@@ -558,7 +588,7 @@ require 'glimmer-dsl-libui'
558
588
 
559
589
  include Glimmer
560
590
 
561
- window('hello world', 300, 200, true) { |w|
591
+ window('hello world', 300, 200) { |w|
562
592
  button('Button') {
563
593
  on_clicked do
564
594
  msg_box(w, 'Information', 'You clicked the button')
@@ -571,23 +601,6 @@ window('hello world', 300, 200, true) { |w|
571
601
  }.show
572
602
  ```
573
603
 
574
- [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
575
-
576
- ```ruby
577
- require 'glimmer-dsl-libui'
578
-
579
- include Glimmer
580
-
581
- window { # first 3 args can be set via properties with 4th arg has_menubar=true by default
582
- title 'hello world'
583
- content_size 300, 200
584
-
585
- on_closing do
586
- puts 'Bye Bye'
587
- end
588
- }.show
589
- ```
590
-
591
604
  ### Basic Entry
592
605
 
593
606
  [examples/basic_entry.rb](examples/basic_entry.rb)
@@ -674,7 +687,7 @@ window('Basic Entry', 300, 50) { |w|
674
687
  }
675
688
 
676
689
  button('Button') {
677
- stretchy false
690
+ stretchy false # stretchy property is available when control is nested under horizontal_box
678
691
 
679
692
  on_clicked do
680
693
  text = e.text
@@ -1627,8 +1640,8 @@ window('Grid') {
1627
1640
  tab {
1628
1641
  tab_item('Spanning') {
1629
1642
  grid {
1630
- 4.times { |left_value|
1631
- 4.times { |top_value|
1643
+ 4.times { |top_value|
1644
+ 4.times { |left_value|
1632
1645
  label("(#{left_value}, #{top_value}) xspan1\nyspan1") {
1633
1646
  left left_value
1634
1647
  top top_value
@@ -1730,13 +1743,11 @@ window('Form') { |w|
1730
1743
  vertical_box {
1731
1744
  form {
1732
1745
  @first_name_entry = entry {
1733
- # stretchy true # Smart default option for appending to form
1734
- label 'First Name'
1746
+ label 'First Name' # label property is available when control is nested under form
1735
1747
  }
1736
1748
 
1737
1749
  @last_name_entry = entry {
1738
- # stretchy true # Smart default option for appending to form
1739
- label 'Last Name'
1750
+ label 'Last Name' # label property is available when control is nested under form
1740
1751
  }
1741
1752
  }
1742
1753
 
@@ -1749,6 +1760,345 @@ window('Form') { |w|
1749
1760
  }.show
1750
1761
  ```
1751
1762
 
1763
+ ### Basic Table
1764
+
1765
+ [examples/basic_table.rb](examples/basic_table.rb)
1766
+
1767
+ Run with this command from the root of the project if you cloned the project:
1768
+
1769
+ ```
1770
+ ruby -r './lib/glimmer-dsl-libui' examples/basic_table.rb
1771
+ ```
1772
+
1773
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1774
+
1775
+ ```
1776
+ ruby -r glimmer-dsl-libui -e "require 'examples/basic_table'"
1777
+ ```
1778
+
1779
+ Mac
1780
+
1781
+ ![glimmer-dsl-libui-mac-basic-table.png](images/glimmer-dsl-libui-mac-basic-table.png)
1782
+
1783
+ Linux
1784
+
1785
+ ![glimmer-dsl-libui-linux-basic-table.png](images/glimmer-dsl-libui-linux-basic-table.png)
1786
+
1787
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
1788
+
1789
+ ```ruby
1790
+ require 'libui'
1791
+
1792
+ UI = LibUI
1793
+
1794
+ UI.init
1795
+
1796
+ main_window = UI.new_window('Animal sounds', 300, 200, 1)
1797
+
1798
+ hbox = UI.new_horizontal_box
1799
+ UI.window_set_child(main_window, hbox)
1800
+
1801
+ data = [
1802
+ %w[cat meow],
1803
+ %w[dog woof],
1804
+ %w[checken cock-a-doodle-doo],
1805
+ %w[hourse neigh],
1806
+ %w[cow moo]
1807
+ ]
1808
+
1809
+ # Protects BlockCaller objects from garbage collection.
1810
+ @blockcaller = []
1811
+ def rbcallback(*args, &block)
1812
+ args << [0] if args.size == 1 # Argument types are ommited
1813
+ blockcaller = Fiddle::Closure::BlockCaller.new(*args, &block)
1814
+ @blockcaller << blockcaller
1815
+ blockcaller
1816
+ end
1817
+
1818
+ model_handler = UI::FFI::TableModelHandler.malloc
1819
+ model_handler.NumColumns = rbcallback(4) { 2 }
1820
+ model_handler.ColumnType = rbcallback(4) { 0 }
1821
+ model_handler.NumRows = rbcallback(4) { 5 }
1822
+ model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
1823
+ UI.new_table_value_string(data[row][column])
1824
+ end
1825
+ model_handler.SetCellValue = rbcallback(0, [0]) {}
1826
+
1827
+ model = UI.new_table_model(model_handler)
1828
+
1829
+ table_params = UI::FFI::TableParams.malloc
1830
+ table_params.Model = model
1831
+ table_params.RowBackgroundColorModelColumn = -1
1832
+
1833
+ table = UI.new_table(table_params)
1834
+ UI.table_append_text_column(table, 'Animal', 0, -1)
1835
+ UI.table_append_text_column(table, 'Description', 1, -1)
1836
+
1837
+ UI.box_append(hbox, table, 1)
1838
+ UI.control_show(main_window)
1839
+
1840
+ UI.window_on_closing(main_window) do
1841
+ puts 'Bye Bye'
1842
+ UI.control_destroy(main_window)
1843
+ UI.free_table_model(model)
1844
+ UI.quit
1845
+ 0
1846
+ end
1847
+
1848
+ UI.main
1849
+ UI.quit
1850
+ ```
1851
+
1852
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1853
+
1854
+ ```ruby
1855
+ require 'glimmer-dsl-libui'
1856
+
1857
+ include Glimmer
1858
+
1859
+ data = [
1860
+ %w[cat meow],
1861
+ %w[dog woof],
1862
+ %w[chicken cock-a-doodle-doo],
1863
+ %w[hourse neigh],
1864
+ %w[cow moo]
1865
+ ]
1866
+
1867
+ window('Animal sounds', 300, 200) {
1868
+ horizontal_box {
1869
+ table {
1870
+ text_column('Animal')
1871
+ text_column('Description')
1872
+
1873
+ cell_rows data
1874
+ }
1875
+ }
1876
+
1877
+ on_closing do
1878
+ puts 'Bye Bye'
1879
+ end
1880
+ }.show
1881
+ ```
1882
+
1883
+ ### Editable Table
1884
+
1885
+ [examples/editable_table.rb](examples/editable_table.rb)
1886
+
1887
+ Run with this command from the root of the project if you cloned the project:
1888
+
1889
+ ```
1890
+ ruby -r './lib/glimmer-dsl-libui' examples/editable_table.rb
1891
+ ```
1892
+
1893
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1894
+
1895
+ ```
1896
+ ruby -r glimmer-dsl-libui -e "require 'examples/editable_table'"
1897
+ ```
1898
+
1899
+ Mac
1900
+
1901
+ ![glimmer-dsl-libui-mac-editable-table.png](images/glimmer-dsl-libui-mac-editable-table.png)
1902
+ ![glimmer-dsl-libui-mac-editable-table-editing.png](images/glimmer-dsl-libui-mac-editable-table-editing.png)
1903
+ ![glimmer-dsl-libui-mac-editable-table-edited.png](images/glimmer-dsl-libui-mac-editable-table-edited.png)
1904
+
1905
+ Linux
1906
+
1907
+ ![glimmer-dsl-libui-linux-editable-table.png](images/glimmer-dsl-libui-linux-editable-table.png)
1908
+ ![glimmer-dsl-libui-linux-editable-table-editing.png](images/glimmer-dsl-libui-linux-editable-table-editing.png)
1909
+ ![glimmer-dsl-libui-linux-editable-table-edited.png](images/glimmer-dsl-libui-linux-editable-table-edited.png)
1910
+
1911
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1912
+
1913
+ ```ruby
1914
+ require 'glimmer-dsl-libui'
1915
+
1916
+ include Glimmer
1917
+
1918
+ data = [
1919
+ %w[cat meow],
1920
+ %w[dog woof],
1921
+ %w[chicken cock-a-doodle-doo],
1922
+ %w[hourse neigh],
1923
+ %w[cow moo]
1924
+ ]
1925
+
1926
+ window('Editable animal sounds', 300, 200) {
1927
+ horizontal_box {
1928
+ table {
1929
+ text_column('Animal')
1930
+ text_column('Description')
1931
+
1932
+ cell_rows data
1933
+ editable true
1934
+ }
1935
+ }
1936
+
1937
+ on_closing do
1938
+ puts 'Bye Bye'
1939
+ end
1940
+ }.show
1941
+ ```
1942
+
1943
+
1944
+ ### Basic Table Image
1945
+
1946
+ This example has a prerequisite of installing `chunky_png` Ruby gem:
1947
+
1948
+ ```
1949
+ gem install chunky_png -v1.4.0
1950
+ ```
1951
+
1952
+ Also, note that behavior varies per platform (i.e. how `table` chooses to size images by default).
1953
+
1954
+ [examples/basic_table_image.rb](examples/basic_table_image.rb)
1955
+
1956
+ Run with this command from the root of the project if you cloned the project:
1957
+
1958
+ ```
1959
+ ruby -r './lib/glimmer-dsl-libui' examples/basic_table_image.rb
1960
+ ```
1961
+
1962
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1963
+
1964
+ ```
1965
+ ruby -r glimmer-dsl-libui -e "require 'examples/basic_table_image'"
1966
+ ```
1967
+
1968
+ Mac
1969
+
1970
+ ![glimmer-dsl-libui-mac-basic-table-image.png](images/glimmer-dsl-libui-mac-basic-table-image.png)
1971
+
1972
+ Linux
1973
+
1974
+ ![glimmer-dsl-libui-linux-basic-table-image.png](images/glimmer-dsl-libui-linux-basic-table-image.png)
1975
+
1976
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
1977
+
1978
+ ```ruby
1979
+ # NOTE:
1980
+ # This example displays images that can be freely downloaded from the Studio Ghibli website.
1981
+
1982
+ require 'libui'
1983
+ require 'chunky_png'
1984
+ require 'open-uri'
1985
+
1986
+ UI = LibUI
1987
+
1988
+ UI.init
1989
+
1990
+ main_window = UI.new_window('The Red Turtle', 310, 350, 0)
1991
+
1992
+ hbox = UI.new_horizontal_box
1993
+ UI.window_set_child(main_window, hbox)
1994
+
1995
+ IMAGES = []
1996
+
1997
+ 50.times do |i|
1998
+ url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
1999
+ puts "Processing Image: #{url}"
2000
+ f = URI.open(url)
2001
+ canvas = ChunkyPNG::Canvas.from_io(f)
2002
+ f.close
2003
+ data = canvas.to_rgba_stream
2004
+ width = canvas.width
2005
+ height = canvas.height
2006
+ image = UI.new_image(width, height)
2007
+ UI.image_append(image, data, width, height, width * 4)
2008
+ IMAGES << image
2009
+ rescue StandardError => e
2010
+ warn url, e.message
2011
+ end
2012
+
2013
+ # Protects BlockCaller objects from garbage collection.
2014
+ @blockcaller = []
2015
+ def rbcallback(*args, &block)
2016
+ args << [0] if args.size == 1 # Argument types are ommited
2017
+ blockcaller = Fiddle::Closure::BlockCaller.new(*args, &block)
2018
+ @blockcaller << blockcaller
2019
+ blockcaller
2020
+ end
2021
+
2022
+ model_handler = UI::FFI::TableModelHandler.malloc
2023
+ model_handler.NumColumns = rbcallback(4) { 1 }
2024
+ model_handler.ColumnType = rbcallback(4) { 1 } # Image
2025
+ model_handler.NumRows = rbcallback(4) { IMAGES.size }
2026
+ model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, _column|
2027
+ UI.new_table_value_image(IMAGES[row])
2028
+ end
2029
+ model_handler.SetCellValue = rbcallback(0, [0]) {}
2030
+
2031
+ model = UI.new_table_model(model_handler)
2032
+
2033
+ table_params = UI::FFI::TableParams.malloc
2034
+ table_params.Model = model
2035
+ table_params.RowBackgroundColorModelColumn = -1
2036
+
2037
+ table = UI.new_table(table_params)
2038
+ UI.table_append_image_column(table, 'www.ghibli.jp/works/red-turtle', 0)
2039
+
2040
+ UI.box_append(hbox, table, 1)
2041
+ UI.control_show(main_window)
2042
+
2043
+ UI.window_on_closing(main_window) do
2044
+ puts 'Bye Bye'
2045
+ UI.control_destroy(main_window)
2046
+ UI.free_table_model(model)
2047
+ IMAGES.each { |i| UI.free_image(i) }
2048
+ UI.quit
2049
+ 0
2050
+ end
2051
+
2052
+ UI.main
2053
+ UI.quit
2054
+ ```
2055
+
2056
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
2057
+
2058
+ ```ruby
2059
+ # NOTE:
2060
+ # This example displays images that can be freely downloaded from the Studio Ghibli website.
2061
+
2062
+ require 'glimmer-dsl-libui'
2063
+ require 'chunky_png'
2064
+ require 'open-uri'
2065
+
2066
+ include Glimmer
2067
+
2068
+ IMAGE_ROWS = []
2069
+
2070
+ 50.times do |i|
2071
+ url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
2072
+ puts "Processing Image: #{url}"
2073
+ f = URI.open(url)
2074
+ canvas = ChunkyPNG::Canvas.from_io(f)
2075
+ f.close
2076
+ data = canvas.to_rgba_stream
2077
+ width = canvas.width
2078
+ height = canvas.height
2079
+ img = image(width, height) {
2080
+ image_part(data, width, height, width * 4)
2081
+ }
2082
+ IMAGE_ROWS << [img] # array of one column cell
2083
+ rescue StandardError => e
2084
+ warn url, e.message
2085
+ end
2086
+
2087
+ window('The Red Turtle', 310, 350, false) {
2088
+ horizontal_box {
2089
+ table {
2090
+ image_column('www.ghibli.jp/works/red-turtle', 0)
2091
+
2092
+ cell_rows IMAGE_ROWS
2093
+ }
2094
+ }
2095
+
2096
+ on_closing do
2097
+ puts 'Bye Bye'
2098
+ end
2099
+ }.show
2100
+ ```
2101
+
1752
2102
  ## Contributing to glimmer-dsl-libui
1753
2103
 
1754
2104
  - Check out the latest master to make sure the feature hasn't been
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.15
1
+ 0.0.19
@@ -16,7 +16,7 @@ window('Basic Entry', 300, 50) { |w|
16
16
  }
17
17
 
18
18
  button('Button') {
19
- stretchy false
19
+ stretchy false # stretchy property is available when control is nested under horizontal_box
20
20
 
21
21
  on_clicked do
22
22
  text = e.text
@@ -0,0 +1,28 @@
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('Animal sounds', 300, 200) {
16
+ horizontal_box {
17
+ table {
18
+ text_column('Animal')
19
+ text_column('Description')
20
+
21
+ cell_rows data
22
+ }
23
+ }
24
+
25
+ on_closing do
26
+ puts 'Bye Bye'
27
+ end
28
+ }.show
@@ -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,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