glimmer-dsl-libui 0.0.14 → 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: daf22d736dce460dde98ce6cb9d10d50433cce189b648b7b9f4fccd1a4e6cefc
4
- data.tar.gz: 36f38bc99b47ae56d321986e9e27e3dfce18dacb3cc3f4722966c36ab329a896
3
+ metadata.gz: fc7805628b0893f2d955c437f8e46932acfbac8db7576cdd28021b12cfe8d942
4
+ data.tar.gz: 4915a6b72d733ca9d4ba7fedf08abc66377bf9a9cd6eca288f1b1a60556951f2
5
5
  SHA512:
6
- metadata.gz: 0fcd083428bfdb29db1428012a8dab67516ea5525e37aa5bdb0c7aa0b9679b78e3a01090b8ec20ca4d799b1ea48c41b0983d2570fd12a470246bb2b7fb7eae4c
7
- data.tar.gz: b5824e2efefc6ccc319a029d4f5eadd976658c3c85bac6fe993ff6da4a9eb2cd5484ccea877b8557c49e2454ac8bb77599eb12219e1eff9fffddeda2489c67ee
6
+ metadata.gz: ef4ac023c7fcb8638a335fd4cf28db03b8d784cb27f63b3edb411c05c5395740d7eb0593f9716657a516314bd6d1effd581abfdbb07de6c1a18225d037344472
7
+ data.tar.gz: 2ee4dab775fd3ae4235b924f37879d84a61dffce138b0b25cd495464931ae20efc5f45ed34d4c6f9767dc2fc15bbb30eafb70fe37efa56de0d8505ea144be010
data/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
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
+
11
+ ## 0.0.17
12
+
13
+ - Support examples/basic_table.rb
14
+ - Support non-editable `table` control
15
+ - Support table `text_column`
16
+ - Support table `cell_rows` property as an `Array` (rows) of `Array`s (row columns) of cell values
17
+
18
+ ## 0.0.16
19
+
20
+ - 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'}} }`)
21
+ - window (was supported before, but changed default title to empty string)
22
+ - button
23
+ - checkbox
24
+ - group
25
+ - label
26
+
27
+ ## 0.0.15
28
+
29
+ - New examples/form.rb
30
+ - Support `form` control and child attributes of `stretchy` and `label`
31
+ - Smart defaults for `form` child attributes `stretchy` (`true`) and `label` (`''`)
32
+
3
33
  ## 0.0.14
4
34
 
5
35
  - New examples/grid.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.14
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.14](#-glimmer-dsl-for-libui-0014)
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)
@@ -68,6 +68,8 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
68
68
  - [Color Button](#color-button)
69
69
  - [Date Time Picker](#date-time-picker)
70
70
  - [Grid](#grid)
71
+ - [Form](#form)
72
+ - [Basic Table](#basic-table)
71
73
  - [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
72
74
  - [Help](#help)
73
75
  - [Issues](#issues)
@@ -155,7 +157,7 @@ gem install glimmer-dsl-libui
155
157
  Or install via Bundler `Gemfile`:
156
158
 
157
159
  ```ruby
158
- gem 'glimmer-dsl-libui', '~> 0.0.14'
160
+ gem 'glimmer-dsl-libui', '~> 0.0.18'
159
161
  ```
160
162
 
161
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.
@@ -220,10 +222,14 @@ Control(Args) | Properties | Listeners
220
222
  `editable_combobox` | `items` (`Array` of `String`), `text` (`String`) | `on_changed`
221
223
  `entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
222
224
  `font_button` | `font` [read-only] (`Hash` of keys: `:family`, `:size`, `:weight`, `:italic`, `:stretch`), `family` as `String`, `size` as `Float`, `weight` as `Integer`, `italic` as `Integer`, `stretch` as `Integer` | `on_changed`
225
+ `form` | `padded` (Boolean) | None
223
226
  `grid` | `padded` (Boolean) | None
224
227
  `group(text as String)` | `margined` (Boolean), `title` (`String`) | None
225
228
  `horizontal_box` | `padded` (Boolean) | None
226
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
227
233
  `label(text as String)` | `text` (`String`) | None
228
234
  `menu(text as String)` | None | None
229
235
  `menu_item(text as String)` | `checked` (Boolean) | `on_clicked`
@@ -239,9 +245,11 @@ Control(Args) | Properties | Listeners
239
245
  `spinbox(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
240
246
  `tab` | `margined` (Boolean), `num_pages` (`Integer`) | None
241
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)) | None
249
+ `text_column(name as String)` | None | None
242
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`
243
251
  `vertical_box` | `padded` (Boolean) | None
244
- `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`
245
253
 
246
254
  ### Common Control Properties
247
255
  - `enabled` (Boolean)
@@ -250,7 +258,7 @@ Control(Args) | Properties | Listeners
250
258
  - `parent` (`Fiddle::Pointer`)
251
259
  - `toplevel` [read-only] (Boolean)
252
260
  - `visible` (Boolean)
253
- - `stretchy` [dsl-only] (Boolean) [default=`true`]: available in [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) when nested under `horizontal_box` or `vertical_box`
261
+ - `stretchy` [dsl-only] (Boolean) [default=`true`]: available in [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) when nested under `horizontal_box`, `vertical_box`, or `form`
254
262
  - `left` [dsl-only] (`Integer`) [default=`0`]: available in [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) when nested under `grid`
255
263
  - `top` [dsl-only] (`Integer`) [default=`0`]: available in [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) when nested under `grid`
256
264
  - `xspan` [dsl-only] (`Integer`) [default=`1`]: available in [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) when nested under `grid`
@@ -274,17 +282,21 @@ Control(Args) | Properties | Listeners
274
282
 
275
283
  ### Extra Operations
276
284
 
277
- - `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
278
288
  - `ControlProxy::main_window_proxy`: returns the first window proxy instantiated in the application
279
289
  - `ControlProxy#window_proxy`: returns the window proxy parent for a control
280
290
 
281
291
  ### Smart Defaults and Conventions
282
292
 
283
- - `horizontal_box`, `vertical_box`, and `grid` controls have `padded` as `true` upon instantiation to ensure more user-friendly GUI by default
293
+ - `horizontal_box`, `vertical_box`, `grid`, and `form` controls have `padded` as `true` upon instantiation to ensure more user-friendly GUI by default
284
294
  - `group` controls have `margined` as `true` upon instantiation to ensure more user-friendly GUI by default
285
- - 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)
286
- - `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`)
287
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'}}`)
288
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)
289
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`).
290
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`).
@@ -295,13 +307,17 @@ Control(Args) | Properties | Listeners
295
307
  - Automatically allocate color value pointers upon instantiating `color_button` controls and free them when destorying `color_button` controls
296
308
  - On the Mac, if no `menu` items were added, an automatic `quit_menu_item` is added to enable quitting with CTRL+Q
297
309
  - When destroying a control nested under a `horizontal_box` or `vertical_box`, it is automatically deleted from the box's children
310
+ - When destroying a control nested under a `form`, it is automatically deleted from the form's children
298
311
  - When destroying a control nested under a `window` or `group`, it is automatically unset as their child to allow successful destruction
299
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`
300
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.
301
317
 
302
318
  ### API Gotchas
303
319
 
304
- There is no proper was to destroy `grid` children due to [libui](https://github.com/andlabs/libui) not offering any API for deleting them from `grid` (no `grid_delete` similar to `box_delete` for `horizontal_box` and `vertical_box`)
320
+ There is no proper way to destroy `grid` children due to [libui](https://github.com/andlabs/libui) not offering any API for deleting them from `grid` (no `grid_delete` similar to `box_delete` for `horizontal_box` and `vertical_box`)
305
321
 
306
322
  ### Original API
307
323
 
@@ -491,6 +507,23 @@ window('hello world', 300, 200, true) {
491
507
  }.show
492
508
  ```
493
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
+
494
527
  ### Basic Button
495
528
 
496
529
  [examples/basic_button.rb](examples/basic_button.rb)
@@ -555,7 +588,7 @@ require 'glimmer-dsl-libui'
555
588
 
556
589
  include Glimmer
557
590
 
558
- window('hello world', 300, 200, true) { |w|
591
+ window('hello world', 300, 200) { |w|
559
592
  button('Button') {
560
593
  on_clicked do
561
594
  msg_box(w, 'Information', 'You clicked the button')
@@ -568,23 +601,6 @@ window('hello world', 300, 200, true) { |w|
568
601
  }.show
569
602
  ```
570
603
 
571
- [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
572
-
573
- ```ruby
574
- require 'glimmer-dsl-libui'
575
-
576
- include Glimmer
577
-
578
- window { # first 3 args can be set via properties with 4th arg has_menubar=true by default
579
- title 'hello world'
580
- content_size 300, 200
581
-
582
- on_closing do
583
- puts 'Bye Bye'
584
- end
585
- }.show
586
- ```
587
-
588
604
  ### Basic Entry
589
605
 
590
606
  [examples/basic_entry.rb](examples/basic_entry.rb)
@@ -671,7 +687,7 @@ window('Basic Entry', 300, 50) { |w|
671
687
  }
672
688
 
673
689
  button('Button') {
674
- stretchy false
690
+ stretchy false # stretchy property is available when control is nested under horizontal_box
675
691
 
676
692
  on_clicked do
677
693
  text = e.text
@@ -1624,8 +1640,8 @@ window('Grid') {
1624
1640
  tab {
1625
1641
  tab_item('Spanning') {
1626
1642
  grid {
1627
- 4.times { |left_value|
1628
- 4.times { |top_value|
1643
+ 4.times { |top_value|
1644
+ 4.times { |left_value|
1629
1645
  label("(#{left_value}, #{top_value}) xspan1\nyspan1") {
1630
1646
  left left_value
1631
1647
  top top_value
@@ -1688,6 +1704,340 @@ window('Grid') {
1688
1704
  }.show
1689
1705
  ```
1690
1706
 
1707
+ ### Form
1708
+
1709
+ [examples/form.rb](examples/form.rb)
1710
+
1711
+ Run with this command from the root of the project if you cloned the project:
1712
+
1713
+ ```
1714
+ ruby -r './lib/glimmer-dsl-libui' examples/form.rb
1715
+ ```
1716
+
1717
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1718
+
1719
+ ```
1720
+ ruby -r glimmer-dsl-libui -e "require 'examples/form'"
1721
+ ```
1722
+
1723
+ Mac
1724
+
1725
+ ![glimmer-dsl-libui-mac-form.png](images/glimmer-dsl-libui-mac-form.png)
1726
+ ![glimmer-dsl-libui-mac-form-msg-box.png](images/glimmer-dsl-libui-mac-form-msg-box.png)
1727
+
1728
+ Linux
1729
+
1730
+ ![glimmer-dsl-libui-linux-form.png](images/glimmer-dsl-libui-linux-form.png)
1731
+ ![glimmer-dsl-libui-linux-form-msg-box.png](images/glimmer-dsl-libui-linux-form-msg-box.png)
1732
+
1733
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1734
+
1735
+ ```ruby
1736
+ require 'glimmer-dsl-libui'
1737
+
1738
+ include Glimmer
1739
+
1740
+ window('Form') { |w|
1741
+ margined true
1742
+
1743
+ vertical_box {
1744
+ form {
1745
+ @first_name_entry = entry {
1746
+ label 'First Name' # label property is available when control is nested under form
1747
+ }
1748
+
1749
+ @last_name_entry = entry {
1750
+ label 'Last Name' # label property is available when control is nested under form
1751
+ }
1752
+ }
1753
+
1754
+ button('Display Name') {
1755
+ on_clicked do
1756
+ msg_box(w, 'Name', "#{@first_name_entry.text} #{@last_name_entry.text}")
1757
+ end
1758
+ }
1759
+ }
1760
+ }.show
1761
+ ```
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
+ ### 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
+
1691
2041
  ## Contributing to glimmer-dsl-libui
1692
2042
 
1693
2043
  - Check out the latest master to make sure the feature hasn't been
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.14
1
+ 0.0.18
@@ -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
data/examples/form.rb ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'glimmer-dsl-libui'
4
+
5
+ include Glimmer
6
+
7
+ window('Form') { |w|
8
+ margined true
9
+
10
+ vertical_box {
11
+ form {
12
+ @first_name_entry = entry {
13
+ label 'First Name' # label property is available when control is nested under form
14
+ }
15
+
16
+ @last_name_entry = entry {
17
+ label 'Last Name' # label property is available when control is nested under form
18
+ }
19
+ }
20
+
21
+ button('Display Name') {
22
+ on_clicked do
23
+ msg_box(w, 'Name', "#{@first_name_entry.text} #{@last_name_entry.text}")
24
+ end
25
+ }
26
+ }
27
+ }.show