glimmer-dsl-libui 0.0.16 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/README.md +437 -25
- data/VERSION +1 -1
- data/examples/basic_table.rb +28 -0
- data/examples/basic_table_image.rb +43 -0
- data/examples/editable_column_table.rb +31 -0
- data/examples/editable_table.rb +29 -0
- data/examples/grid.rb +2 -2
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/libui/box.rb +1 -1
- data/lib/glimmer/libui/column.rb +55 -0
- data/lib/glimmer/libui/control_proxy.rb +11 -7
- data/lib/glimmer/libui/form_proxy.rb +1 -1
- data/lib/glimmer/libui/image_column_proxy.rb +41 -0
- data/lib/glimmer/libui/image_part_proxy.rb +37 -0
- data/lib/glimmer/libui/table_proxy.rb +138 -0
- data/lib/glimmer/libui/text_column_proxy.rb +52 -0
- data/lib/glimmer/libui/window_proxy.rb +11 -0
- metadata +26 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4f4c60e8967700c477acdd623d75af1b119ab243f90e22b4f9861d9fbde3705
|
4
|
+
data.tar.gz: f92952b04a511a54107114cad3b7b336b4731720b4a6844097353c97fd16f4a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fb3cd049cadd55cfb9750c6167804a8af54d793498bc3a67ac1efe913ec4497e2dec7ed19c176d644ecf8f49e721ad33e5b4d49fc32cafb073ccf5b0b08cc9c
|
7
|
+
data.tar.gz: bf246270c2651c86fa311ac72e02dd75c1ba03074286e254edfb6a99ae2dc59a1084e4317649d04cea31abf1c6b68908bf962d5b091a5a205d56830b138eb0ee
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.0.20
|
4
|
+
|
5
|
+
- New examples/editable_column_table.rb
|
6
|
+
- Support `editable` property for `text_column`
|
7
|
+
|
8
|
+
## 0.0.19
|
9
|
+
|
10
|
+
- New examples/editable_table.rb
|
11
|
+
- Support editable `table` control
|
12
|
+
- Fix issue with table `text_column` repeating the first column as the second
|
13
|
+
|
14
|
+
## 0.0.18
|
15
|
+
|
16
|
+
- Support examples/basic_table_image.rb
|
17
|
+
- Support table `image_column`
|
18
|
+
- Support `image` and `image_part` for building images from rgba byte arrays
|
19
|
+
- Rename `Glimmer::LibUI::ControlProxy.all_control_proxies` to `Glimmer::LibUI::ControlProxy.control_proxies`
|
20
|
+
- Add `Glimmer::LibUI::ControlProxy.image_proxies`
|
21
|
+
|
22
|
+
## 0.0.17
|
23
|
+
|
24
|
+
- Support examples/basic_table.rb
|
25
|
+
- Support non-editable `table` control
|
26
|
+
- Support table `text_column`
|
27
|
+
- Support table `cell_rows` property as an `Array` (rows) of `Array`s (row columns) of cell values
|
28
|
+
|
3
29
|
## 0.0.16
|
4
30
|
|
5
31
|
- 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'}} }`)
|
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.
|
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.20
|
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.
|
46
|
+
- [Glimmer DSL for LibUI 0.0.20](#-glimmer-dsl-for-libui-0020)
|
47
47
|
- [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
|
48
48
|
- [Usage](#usage)
|
49
49
|
- [API](#api)
|
@@ -69,6 +69,10 @@ 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)
|
73
|
+
- [Editable Table](#editable-table)
|
74
|
+
- [Editable Column Table](#editable-column-table)
|
75
|
+
- [Basic Table Image](#basic-table-image)
|
72
76
|
- [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
|
73
77
|
- [Help](#help)
|
74
78
|
- [Issues](#issues)
|
@@ -156,7 +160,7 @@ gem install glimmer-dsl-libui
|
|
156
160
|
Or install via Bundler `Gemfile`:
|
157
161
|
|
158
162
|
```ruby
|
159
|
-
gem 'glimmer-dsl-libui', '~> 0.0.
|
163
|
+
gem 'glimmer-dsl-libui', '~> 0.0.20'
|
160
164
|
```
|
161
165
|
|
162
166
|
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 +230,9 @@ Control(Args) | Properties | Listeners
|
|
226
230
|
`group(text as String)` | `margined` (Boolean), `title` (`String`) | None
|
227
231
|
`horizontal_box` | `padded` (Boolean) | None
|
228
232
|
`horizontal_separator` | None | None
|
233
|
+
`image(width as Numeric, height as Numeric)` | None | None
|
234
|
+
`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
|
235
|
+
`image_column(name as String)` | None | None
|
229
236
|
`label(text as String)` | `text` (`String`) | None
|
230
237
|
`menu(text as String)` | None | None
|
231
238
|
`menu_item(text as String)` | `checked` (Boolean) | `on_clicked`
|
@@ -241,9 +248,11 @@ Control(Args) | Properties | Listeners
|
|
241
248
|
`spinbox(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
|
242
249
|
`tab` | `margined` (Boolean), `num_pages` (`Integer`) | None
|
243
250
|
`tab_item(name as String)` | `index` [read-only] (`Integer`), `margined` (Boolean), `name` [read-only] (`String`) | None
|
251
|
+
`table` | `cell_rows` (`Array` (rows) of `Arrays` (row columns) of cell values (e.g. `String` values)), `editable` as Boolean | None
|
252
|
+
`text_column(name as String)` | `editable` as Boolean | None
|
244
253
|
`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
254
|
`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`
|
255
|
+
`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
256
|
|
248
257
|
### Common Control Properties
|
249
258
|
- `enabled` (Boolean)
|
@@ -276,7 +285,9 @@ Control(Args) | Properties | Listeners
|
|
276
285
|
|
277
286
|
### Extra Operations
|
278
287
|
|
279
|
-
- `ControlProxy::
|
288
|
+
- `ControlProxy::control_proxies`: returns all instantiated control proxies in the application
|
289
|
+
- `ControlProxy::menu_proxies`: returns all instantiated `menu` proxies in the application
|
290
|
+
- `ControlProxy::image_proxies`: returns all instantiated `image` proxies in the application
|
280
291
|
- `ControlProxy::main_window_proxy`: returns the first window proxy instantiated in the application
|
281
292
|
- `ControlProxy#window_proxy`: returns the window proxy parent for a control
|
282
293
|
|
@@ -303,6 +314,9 @@ Control(Args) | Properties | Listeners
|
|
303
314
|
- When destroying a control nested under a `window` or `group`, it is automatically unset as their child to allow successful destruction
|
304
315
|
- 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`
|
305
316
|
- Smart defaults for `grid` child attributes are `left` (`0`), `top` (`0`), `xspan` (`1`), `yspan` (`1`), `hexpand` (`false`), `halign` (`0`), `vexpand` (`false`), and `valign` (`0`)
|
317
|
+
- 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`)
|
318
|
+
- Table model instances are automatically freed from memory after `window` is destroyed.
|
319
|
+
- `image` instances are automatically freed from memory after `window` is destroyed.
|
306
320
|
|
307
321
|
### API Gotchas
|
308
322
|
|
@@ -496,6 +510,23 @@ window('hello world', 300, 200, true) {
|
|
496
510
|
}.show
|
497
511
|
```
|
498
512
|
|
513
|
+
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
|
514
|
+
|
515
|
+
```ruby
|
516
|
+
require 'glimmer-dsl-libui'
|
517
|
+
|
518
|
+
include Glimmer
|
519
|
+
|
520
|
+
window { # first 3 args can be set via properties with 4th arg has_menubar=true by default
|
521
|
+
title 'hello world'
|
522
|
+
content_size 300, 200
|
523
|
+
|
524
|
+
on_closing do
|
525
|
+
puts 'Bye Bye'
|
526
|
+
end
|
527
|
+
}.show
|
528
|
+
```
|
529
|
+
|
499
530
|
### Basic Button
|
500
531
|
|
501
532
|
[examples/basic_button.rb](examples/basic_button.rb)
|
@@ -560,7 +591,7 @@ require 'glimmer-dsl-libui'
|
|
560
591
|
|
561
592
|
include Glimmer
|
562
593
|
|
563
|
-
window('hello world', 300, 200
|
594
|
+
window('hello world', 300, 200) { |w|
|
564
595
|
button('Button') {
|
565
596
|
on_clicked do
|
566
597
|
msg_box(w, 'Information', 'You clicked the button')
|
@@ -573,23 +604,6 @@ window('hello world', 300, 200, true) { |w|
|
|
573
604
|
}.show
|
574
605
|
```
|
575
606
|
|
576
|
-
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2:
|
577
|
-
|
578
|
-
```ruby
|
579
|
-
require 'glimmer-dsl-libui'
|
580
|
-
|
581
|
-
include Glimmer
|
582
|
-
|
583
|
-
window { # first 3 args can be set via properties with 4th arg has_menubar=true by default
|
584
|
-
title 'hello world'
|
585
|
-
content_size 300, 200
|
586
|
-
|
587
|
-
on_closing do
|
588
|
-
puts 'Bye Bye'
|
589
|
-
end
|
590
|
-
}.show
|
591
|
-
```
|
592
|
-
|
593
607
|
### Basic Entry
|
594
608
|
|
595
609
|
[examples/basic_entry.rb](examples/basic_entry.rb)
|
@@ -1629,8 +1643,8 @@ window('Grid') {
|
|
1629
1643
|
tab {
|
1630
1644
|
tab_item('Spanning') {
|
1631
1645
|
grid {
|
1632
|
-
4.times { |
|
1633
|
-
4.times { |
|
1646
|
+
4.times { |top_value|
|
1647
|
+
4.times { |left_value|
|
1634
1648
|
label("(#{left_value}, #{top_value}) xspan1\nyspan1") {
|
1635
1649
|
left left_value
|
1636
1650
|
top top_value
|
@@ -1749,6 +1763,404 @@ window('Form') { |w|
|
|
1749
1763
|
}.show
|
1750
1764
|
```
|
1751
1765
|
|
1766
|
+
### Basic Table
|
1767
|
+
|
1768
|
+
[examples/basic_table.rb](examples/basic_table.rb)
|
1769
|
+
|
1770
|
+
Run with this command from the root of the project if you cloned the project:
|
1771
|
+
|
1772
|
+
```
|
1773
|
+
ruby -r './lib/glimmer-dsl-libui' examples/basic_table.rb
|
1774
|
+
```
|
1775
|
+
|
1776
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
1777
|
+
|
1778
|
+
```
|
1779
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/basic_table'"
|
1780
|
+
```
|
1781
|
+
|
1782
|
+
Mac
|
1783
|
+
|
1784
|
+
![glimmer-dsl-libui-mac-basic-table.png](images/glimmer-dsl-libui-mac-basic-table.png)
|
1785
|
+
|
1786
|
+
Linux
|
1787
|
+
|
1788
|
+
![glimmer-dsl-libui-linux-basic-table.png](images/glimmer-dsl-libui-linux-basic-table.png)
|
1789
|
+
|
1790
|
+
[LibUI](https://github.com/kojix2/LibUI) Original Version:
|
1791
|
+
|
1792
|
+
```ruby
|
1793
|
+
require 'libui'
|
1794
|
+
|
1795
|
+
UI = LibUI
|
1796
|
+
|
1797
|
+
UI.init
|
1798
|
+
|
1799
|
+
main_window = UI.new_window('Animal sounds', 300, 200, 1)
|
1800
|
+
|
1801
|
+
hbox = UI.new_horizontal_box
|
1802
|
+
UI.window_set_child(main_window, hbox)
|
1803
|
+
|
1804
|
+
data = [
|
1805
|
+
%w[cat meow],
|
1806
|
+
%w[dog woof],
|
1807
|
+
%w[checken cock-a-doodle-doo],
|
1808
|
+
%w[hourse neigh],
|
1809
|
+
%w[cow moo]
|
1810
|
+
]
|
1811
|
+
|
1812
|
+
# Protects BlockCaller objects from garbage collection.
|
1813
|
+
@blockcaller = []
|
1814
|
+
def rbcallback(*args, &block)
|
1815
|
+
args << [0] if args.size == 1 # Argument types are ommited
|
1816
|
+
blockcaller = Fiddle::Closure::BlockCaller.new(*args, &block)
|
1817
|
+
@blockcaller << blockcaller
|
1818
|
+
blockcaller
|
1819
|
+
end
|
1820
|
+
|
1821
|
+
model_handler = UI::FFI::TableModelHandler.malloc
|
1822
|
+
model_handler.NumColumns = rbcallback(4) { 2 }
|
1823
|
+
model_handler.ColumnType = rbcallback(4) { 0 }
|
1824
|
+
model_handler.NumRows = rbcallback(4) { 5 }
|
1825
|
+
model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
|
1826
|
+
UI.new_table_value_string(data[row][column])
|
1827
|
+
end
|
1828
|
+
model_handler.SetCellValue = rbcallback(0, [0]) {}
|
1829
|
+
|
1830
|
+
model = UI.new_table_model(model_handler)
|
1831
|
+
|
1832
|
+
table_params = UI::FFI::TableParams.malloc
|
1833
|
+
table_params.Model = model
|
1834
|
+
table_params.RowBackgroundColorModelColumn = -1
|
1835
|
+
|
1836
|
+
table = UI.new_table(table_params)
|
1837
|
+
UI.table_append_text_column(table, 'Animal', 0, -1)
|
1838
|
+
UI.table_append_text_column(table, 'Description', 1, -1)
|
1839
|
+
|
1840
|
+
UI.box_append(hbox, table, 1)
|
1841
|
+
UI.control_show(main_window)
|
1842
|
+
|
1843
|
+
UI.window_on_closing(main_window) do
|
1844
|
+
puts 'Bye Bye'
|
1845
|
+
UI.control_destroy(main_window)
|
1846
|
+
UI.free_table_model(model)
|
1847
|
+
UI.quit
|
1848
|
+
0
|
1849
|
+
end
|
1850
|
+
|
1851
|
+
UI.main
|
1852
|
+
UI.quit
|
1853
|
+
```
|
1854
|
+
|
1855
|
+
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
1856
|
+
|
1857
|
+
```ruby
|
1858
|
+
require 'glimmer-dsl-libui'
|
1859
|
+
|
1860
|
+
include Glimmer
|
1861
|
+
|
1862
|
+
data = [
|
1863
|
+
%w[cat meow],
|
1864
|
+
%w[dog woof],
|
1865
|
+
%w[chicken cock-a-doodle-doo],
|
1866
|
+
%w[hourse neigh],
|
1867
|
+
%w[cow moo]
|
1868
|
+
]
|
1869
|
+
|
1870
|
+
window('Animal sounds', 300, 200) {
|
1871
|
+
horizontal_box {
|
1872
|
+
table {
|
1873
|
+
text_column('Animal')
|
1874
|
+
text_column('Description')
|
1875
|
+
|
1876
|
+
cell_rows data
|
1877
|
+
}
|
1878
|
+
}
|
1879
|
+
|
1880
|
+
on_closing do
|
1881
|
+
puts 'Bye Bye'
|
1882
|
+
end
|
1883
|
+
}.show
|
1884
|
+
```
|
1885
|
+
|
1886
|
+
### Editable Table
|
1887
|
+
|
1888
|
+
[examples/editable_table.rb](examples/editable_table.rb)
|
1889
|
+
|
1890
|
+
Run with this command from the root of the project if you cloned the project:
|
1891
|
+
|
1892
|
+
```
|
1893
|
+
ruby -r './lib/glimmer-dsl-libui' examples/editable_table.rb
|
1894
|
+
```
|
1895
|
+
|
1896
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
1897
|
+
|
1898
|
+
```
|
1899
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/editable_table'"
|
1900
|
+
```
|
1901
|
+
|
1902
|
+
Mac
|
1903
|
+
|
1904
|
+
![glimmer-dsl-libui-mac-editable-table.png](images/glimmer-dsl-libui-mac-editable-table.png)
|
1905
|
+
![glimmer-dsl-libui-mac-editable-table-editing.png](images/glimmer-dsl-libui-mac-editable-table-editing.png)
|
1906
|
+
![glimmer-dsl-libui-mac-editable-table-edited.png](images/glimmer-dsl-libui-mac-editable-table-edited.png)
|
1907
|
+
|
1908
|
+
Linux
|
1909
|
+
|
1910
|
+
![glimmer-dsl-libui-linux-editable-table.png](images/glimmer-dsl-libui-linux-editable-table.png)
|
1911
|
+
![glimmer-dsl-libui-linux-editable-table-editing.png](images/glimmer-dsl-libui-linux-editable-table-editing.png)
|
1912
|
+
![glimmer-dsl-libui-linux-editable-table-edited.png](images/glimmer-dsl-libui-linux-editable-table-edited.png)
|
1913
|
+
|
1914
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
1915
|
+
|
1916
|
+
```ruby
|
1917
|
+
require 'glimmer-dsl-libui'
|
1918
|
+
|
1919
|
+
include Glimmer
|
1920
|
+
|
1921
|
+
data = [
|
1922
|
+
%w[cat meow],
|
1923
|
+
%w[dog woof],
|
1924
|
+
%w[chicken cock-a-doodle-doo],
|
1925
|
+
%w[hourse neigh],
|
1926
|
+
%w[cow moo]
|
1927
|
+
]
|
1928
|
+
|
1929
|
+
window('Editable animal sounds', 300, 200) {
|
1930
|
+
horizontal_box {
|
1931
|
+
table {
|
1932
|
+
text_column('Animal')
|
1933
|
+
text_column('Description')
|
1934
|
+
|
1935
|
+
cell_rows data
|
1936
|
+
editable true
|
1937
|
+
}
|
1938
|
+
}
|
1939
|
+
|
1940
|
+
on_closing do
|
1941
|
+
puts 'Bye Bye'
|
1942
|
+
end
|
1943
|
+
}.show
|
1944
|
+
```
|
1945
|
+
|
1946
|
+
### Editable Column Table
|
1947
|
+
|
1948
|
+
[examples/editable_column_table.rb](examples/editable_column_table.rb)
|
1949
|
+
|
1950
|
+
Run with this command from the root of the project if you cloned the project:
|
1951
|
+
|
1952
|
+
```
|
1953
|
+
ruby -r './lib/glimmer-dsl-libui' examples/editable_column_table.rb
|
1954
|
+
```
|
1955
|
+
|
1956
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
1957
|
+
|
1958
|
+
```
|
1959
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/editable_column_table'"
|
1960
|
+
```
|
1961
|
+
|
1962
|
+
Mac
|
1963
|
+
|
1964
|
+
![glimmer-dsl-libui-mac-editable-column-table-editing.png](images/glimmer-dsl-libui-mac-editable-column-table-editing.png)
|
1965
|
+
![glimmer-dsl-libui-mac-editable-column-table-edited.png](images/glimmer-dsl-libui-mac-editable-column-table-edited.png)
|
1966
|
+
|
1967
|
+
Linux
|
1968
|
+
|
1969
|
+
![glimmer-dsl-libui-linux-editable-column-table-editing.png](images/glimmer-dsl-libui-linux-editable-column-table-editing.png)
|
1970
|
+
![glimmer-dsl-libui-linux-editable-column-table-edited.png](images/glimmer-dsl-libui-linux-editable-column-table-edited.png)
|
1971
|
+
|
1972
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
1973
|
+
|
1974
|
+
```ruby
|
1975
|
+
require 'glimmer-dsl-libui'
|
1976
|
+
|
1977
|
+
include Glimmer
|
1978
|
+
|
1979
|
+
data = [
|
1980
|
+
%w[cat calm meow],
|
1981
|
+
%w[dog loyal woof],
|
1982
|
+
%w[chicken bird cock-a-doodle-doo],
|
1983
|
+
%w[hourse fast neigh],
|
1984
|
+
%w[cow slow moo]
|
1985
|
+
]
|
1986
|
+
|
1987
|
+
window('Editable column animal sounds', 400, 200) {
|
1988
|
+
horizontal_box {
|
1989
|
+
table {
|
1990
|
+
text_column('Animal')
|
1991
|
+
text_column('Description')
|
1992
|
+
text_column('Sound (Editable)') {
|
1993
|
+
editable true
|
1994
|
+
}
|
1995
|
+
|
1996
|
+
cell_rows data
|
1997
|
+
}
|
1998
|
+
}
|
1999
|
+
|
2000
|
+
on_closing do
|
2001
|
+
puts 'Bye Bye'
|
2002
|
+
end
|
2003
|
+
}.show
|
2004
|
+
```
|
2005
|
+
|
2006
|
+
### Basic Table Image
|
2007
|
+
|
2008
|
+
This example has a prerequisite of installing `chunky_png` Ruby gem:
|
2009
|
+
|
2010
|
+
```
|
2011
|
+
gem install chunky_png -v1.4.0
|
2012
|
+
```
|
2013
|
+
|
2014
|
+
Also, note that behavior varies per platform (i.e. how `table` chooses to size images by default).
|
2015
|
+
|
2016
|
+
[examples/basic_table_image.rb](examples/basic_table_image.rb)
|
2017
|
+
|
2018
|
+
Run with this command from the root of the project if you cloned the project:
|
2019
|
+
|
2020
|
+
```
|
2021
|
+
ruby -r './lib/glimmer-dsl-libui' examples/basic_table_image.rb
|
2022
|
+
```
|
2023
|
+
|
2024
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
2025
|
+
|
2026
|
+
```
|
2027
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/basic_table_image'"
|
2028
|
+
```
|
2029
|
+
|
2030
|
+
Mac
|
2031
|
+
|
2032
|
+
![glimmer-dsl-libui-mac-basic-table-image.png](images/glimmer-dsl-libui-mac-basic-table-image.png)
|
2033
|
+
|
2034
|
+
Linux
|
2035
|
+
|
2036
|
+
![glimmer-dsl-libui-linux-basic-table-image.png](images/glimmer-dsl-libui-linux-basic-table-image.png)
|
2037
|
+
|
2038
|
+
[LibUI](https://github.com/kojix2/LibUI) Original Version:
|
2039
|
+
|
2040
|
+
```ruby
|
2041
|
+
# NOTE:
|
2042
|
+
# This example displays images that can be freely downloaded from the Studio Ghibli website.
|
2043
|
+
|
2044
|
+
require 'libui'
|
2045
|
+
require 'chunky_png'
|
2046
|
+
require 'open-uri'
|
2047
|
+
|
2048
|
+
UI = LibUI
|
2049
|
+
|
2050
|
+
UI.init
|
2051
|
+
|
2052
|
+
main_window = UI.new_window('The Red Turtle', 310, 350, 0)
|
2053
|
+
|
2054
|
+
hbox = UI.new_horizontal_box
|
2055
|
+
UI.window_set_child(main_window, hbox)
|
2056
|
+
|
2057
|
+
IMAGES = []
|
2058
|
+
|
2059
|
+
50.times do |i|
|
2060
|
+
url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
|
2061
|
+
puts "Processing Image: #{url}"
|
2062
|
+
f = URI.open(url)
|
2063
|
+
canvas = ChunkyPNG::Canvas.from_io(f)
|
2064
|
+
f.close
|
2065
|
+
data = canvas.to_rgba_stream
|
2066
|
+
width = canvas.width
|
2067
|
+
height = canvas.height
|
2068
|
+
image = UI.new_image(width, height)
|
2069
|
+
UI.image_append(image, data, width, height, width * 4)
|
2070
|
+
IMAGES << image
|
2071
|
+
rescue StandardError => e
|
2072
|
+
warn url, e.message
|
2073
|
+
end
|
2074
|
+
|
2075
|
+
# Protects BlockCaller objects from garbage collection.
|
2076
|
+
@blockcaller = []
|
2077
|
+
def rbcallback(*args, &block)
|
2078
|
+
args << [0] if args.size == 1 # Argument types are ommited
|
2079
|
+
blockcaller = Fiddle::Closure::BlockCaller.new(*args, &block)
|
2080
|
+
@blockcaller << blockcaller
|
2081
|
+
blockcaller
|
2082
|
+
end
|
2083
|
+
|
2084
|
+
model_handler = UI::FFI::TableModelHandler.malloc
|
2085
|
+
model_handler.NumColumns = rbcallback(4) { 1 }
|
2086
|
+
model_handler.ColumnType = rbcallback(4) { 1 } # Image
|
2087
|
+
model_handler.NumRows = rbcallback(4) { IMAGES.size }
|
2088
|
+
model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, _column|
|
2089
|
+
UI.new_table_value_image(IMAGES[row])
|
2090
|
+
end
|
2091
|
+
model_handler.SetCellValue = rbcallback(0, [0]) {}
|
2092
|
+
|
2093
|
+
model = UI.new_table_model(model_handler)
|
2094
|
+
|
2095
|
+
table_params = UI::FFI::TableParams.malloc
|
2096
|
+
table_params.Model = model
|
2097
|
+
table_params.RowBackgroundColorModelColumn = -1
|
2098
|
+
|
2099
|
+
table = UI.new_table(table_params)
|
2100
|
+
UI.table_append_image_column(table, 'www.ghibli.jp/works/red-turtle', 0)
|
2101
|
+
|
2102
|
+
UI.box_append(hbox, table, 1)
|
2103
|
+
UI.control_show(main_window)
|
2104
|
+
|
2105
|
+
UI.window_on_closing(main_window) do
|
2106
|
+
puts 'Bye Bye'
|
2107
|
+
UI.control_destroy(main_window)
|
2108
|
+
UI.free_table_model(model)
|
2109
|
+
IMAGES.each { |i| UI.free_image(i) }
|
2110
|
+
UI.quit
|
2111
|
+
0
|
2112
|
+
end
|
2113
|
+
|
2114
|
+
UI.main
|
2115
|
+
UI.quit
|
2116
|
+
```
|
2117
|
+
|
2118
|
+
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
2119
|
+
|
2120
|
+
```ruby
|
2121
|
+
# NOTE:
|
2122
|
+
# This example displays images that can be freely downloaded from the Studio Ghibli website.
|
2123
|
+
|
2124
|
+
require 'glimmer-dsl-libui'
|
2125
|
+
require 'chunky_png'
|
2126
|
+
require 'open-uri'
|
2127
|
+
|
2128
|
+
include Glimmer
|
2129
|
+
|
2130
|
+
IMAGE_ROWS = []
|
2131
|
+
|
2132
|
+
50.times do |i|
|
2133
|
+
url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
|
2134
|
+
puts "Processing Image: #{url}"
|
2135
|
+
f = URI.open(url)
|
2136
|
+
canvas = ChunkyPNG::Canvas.from_io(f)
|
2137
|
+
f.close
|
2138
|
+
data = canvas.to_rgba_stream
|
2139
|
+
width = canvas.width
|
2140
|
+
height = canvas.height
|
2141
|
+
img = image(width, height) {
|
2142
|
+
image_part(data, width, height, width * 4)
|
2143
|
+
}
|
2144
|
+
IMAGE_ROWS << [img] # array of one column cell
|
2145
|
+
rescue StandardError => e
|
2146
|
+
warn url, e.message
|
2147
|
+
end
|
2148
|
+
|
2149
|
+
window('The Red Turtle', 310, 350, false) {
|
2150
|
+
horizontal_box {
|
2151
|
+
table {
|
2152
|
+
image_column('www.ghibli.jp/works/red-turtle', 0)
|
2153
|
+
|
2154
|
+
cell_rows IMAGE_ROWS
|
2155
|
+
}
|
2156
|
+
}
|
2157
|
+
|
2158
|
+
on_closing do
|
2159
|
+
puts 'Bye Bye'
|
2160
|
+
end
|
2161
|
+
}.show
|
2162
|
+
```
|
2163
|
+
|
1752
2164
|
## Contributing to glimmer-dsl-libui
|
1753
2165
|
|
1754
2166
|
- Check out the latest master to make sure the feature hasn't been
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.20
|
@@ -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,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
|
data/examples/grid.rb
CHANGED
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
data/lib/glimmer/libui/box.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
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
|
+
attr_reader :appended
|
29
|
+
alias appended? appended
|
30
|
+
|
31
|
+
def initialize(keyword, parent, args, &block)
|
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
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def build_control
|
47
|
+
@appended = true
|
48
|
+
end
|
49
|
+
|
50
|
+
def next_column_index
|
51
|
+
@parent_proxy.columns.map(&:appended?).compact.count
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
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|
|
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
|
50
|
-
@@
|
51
|
-
@@
|
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
|
-
|
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
|
-
|
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.
|
227
|
+
ControlProxy.control_proxies.delete(self)
|
224
228
|
end
|
225
229
|
|
226
230
|
def enabled(value = nil)
|
@@ -0,0 +1,41 @@
|
|
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, next_column_index)
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
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,138 @@
|
|
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 table objects
|
27
|
+
#
|
28
|
+
# Follows the Proxy Design Pattern
|
29
|
+
class TableProxy < ControlProxy
|
30
|
+
attr_reader :model_handler, :model, :table_params, :columns
|
31
|
+
|
32
|
+
def initialize(keyword, parent, args, &block)
|
33
|
+
@keyword = keyword
|
34
|
+
@parent_proxy = parent
|
35
|
+
@args = args
|
36
|
+
@block = block
|
37
|
+
@enabled = true
|
38
|
+
@columns = []
|
39
|
+
@cell_rows = []
|
40
|
+
window_proxy.on_destroy do
|
41
|
+
# the following unless condition is an exceptional condition stumbled upon that fails freeing the table model
|
42
|
+
::LibUI.free_table_model(@model) unless @destroyed && parent_proxy.is_a?(Glimmer::LibUI::Box)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def post_add_content
|
47
|
+
build_control
|
48
|
+
super
|
49
|
+
end
|
50
|
+
|
51
|
+
def post_initialize_child(child)
|
52
|
+
@columns << child
|
53
|
+
end
|
54
|
+
|
55
|
+
def destroy
|
56
|
+
super
|
57
|
+
@destroyed = true
|
58
|
+
end
|
59
|
+
|
60
|
+
def cell_rows(rows = nil)
|
61
|
+
if rows.nil?
|
62
|
+
@cell_rows
|
63
|
+
else
|
64
|
+
rows = rows.map {|row| row.map {|cell| cell.respond_to?(:libui) ? cell.libui : cell }}
|
65
|
+
@cell_rows = rows
|
66
|
+
end
|
67
|
+
end
|
68
|
+
alias cell_rows= cell_rows
|
69
|
+
alias set_cell_rows cell_rows
|
70
|
+
|
71
|
+
def editable(value = nil)
|
72
|
+
if value.nil?
|
73
|
+
@editable
|
74
|
+
else
|
75
|
+
@editable = !!value
|
76
|
+
end
|
77
|
+
end
|
78
|
+
alias editable= editable
|
79
|
+
alias set_editable editable
|
80
|
+
alias editable? editable
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def build_control
|
85
|
+
@model_handler = ::LibUI::FFI::TableModelHandler.malloc
|
86
|
+
@model_handler.NumColumns = rbcallback(4) { @columns.count }
|
87
|
+
@model_handler.ColumnType = rbcallback(4) do
|
88
|
+
# Note: this assumes all columns are the same type
|
89
|
+
# TODO support different values per different columns
|
90
|
+
case @columns.first
|
91
|
+
when TextColumnProxy
|
92
|
+
0
|
93
|
+
when ImageColumnProxy
|
94
|
+
1
|
95
|
+
end
|
96
|
+
end
|
97
|
+
@model_handler.NumRows = rbcallback(4) { cell_rows.count }
|
98
|
+
@model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
|
99
|
+
case @columns[column]
|
100
|
+
when TextColumnProxy
|
101
|
+
::LibUI.new_table_value_string((@cell_rows[row] && @cell_rows[row][column]).to_s)
|
102
|
+
when ImageColumnProxy
|
103
|
+
::LibUI.new_table_value_image((@cell_rows[row] && @cell_rows[row][column]))
|
104
|
+
end
|
105
|
+
end
|
106
|
+
@model_handler.SetCellValue = rbcallback(0, [1, 1, 4, 4, 1]) do |_, _, row, column, val|
|
107
|
+
case @columns[column]
|
108
|
+
when TextColumnProxy
|
109
|
+
@cell_rows[row] ||= []
|
110
|
+
@cell_rows[row][column] = ::LibUI.table_value_string(val).to_s
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
@model = ::LibUI.new_table_model(@model_handler)
|
115
|
+
|
116
|
+
@table_params = ::LibUI::FFI::TableParams.malloc
|
117
|
+
@table_params.Model = @model
|
118
|
+
@table_params.RowBackgroundColorModelColumn = -1
|
119
|
+
|
120
|
+
@libui = ControlProxy.new_control(@keyword, [@table_params])
|
121
|
+
@libui.tap do
|
122
|
+
@columns.each {|column| column.send(:build_control) }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def rbcallback(*args, &block)
|
127
|
+
# TODO consider moving to a more general reusable location in the future (e.g. when used with `AreaProxy`)
|
128
|
+
# Protects BlockCaller objects from garbage collection.
|
129
|
+
@blockcaller ||= []
|
130
|
+
args << [0] if args.size == 1 # Argument types are ommited
|
131
|
+
blockcaller = Fiddle::Closure::BlockCaller.new(*args, &block)
|
132
|
+
@blockcaller << blockcaller
|
133
|
+
blockcaller
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,52 @@
|
|
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 text column objects
|
28
|
+
#
|
29
|
+
# Follows the Proxy Design Pattern
|
30
|
+
class TextColumnProxy < ControlProxy
|
31
|
+
include Column
|
32
|
+
|
33
|
+
def editable(value = nil)
|
34
|
+
if value.nil?
|
35
|
+
@editable
|
36
|
+
else
|
37
|
+
@editable = !!value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
alias editable= editable
|
41
|
+
alias set_editable editable
|
42
|
+
alias editable? editable
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def build_control
|
47
|
+
@parent_proxy.append_text_column(name, next_column_index, @parent_proxy.editable? || editable? ? -2 : -1)
|
48
|
+
super
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -40,6 +40,17 @@ module Glimmer
|
|
40
40
|
::LibUI.send("window_set_child", @libui, nil)
|
41
41
|
super
|
42
42
|
end
|
43
|
+
|
44
|
+
def destroy
|
45
|
+
super
|
46
|
+
ControlProxy.image_proxies.each { |image_proxy| ::LibUI.free_image(image_proxy.libui) }
|
47
|
+
@on_destroy_procs&.each { |on_destroy_proc| on_destroy_proc.call(self)}
|
48
|
+
end
|
49
|
+
|
50
|
+
def on_destroy(&block)
|
51
|
+
@on_destroy_procs ||= []
|
52
|
+
@on_destroy_procs << block
|
53
|
+
end
|
43
54
|
|
44
55
|
def show
|
45
56
|
super
|
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.
|
4
|
+
version: 0.0.20
|
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-
|
11
|
+
date: 2021-09-24 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 (
|
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:
|
@@ -182,11 +196,15 @@ files:
|
|
182
196
|
- bin/girb_runner.rb
|
183
197
|
- examples/basic_button.rb
|
184
198
|
- examples/basic_entry.rb
|
199
|
+
- examples/basic_table.rb
|
200
|
+
- examples/basic_table_image.rb
|
185
201
|
- examples/basic_window.rb
|
186
202
|
- examples/basic_window2.rb
|
187
203
|
- examples/color_button.rb
|
188
204
|
- examples/control_gallery.rb
|
189
205
|
- examples/date_time_picker.rb
|
206
|
+
- examples/editable_column_table.rb
|
207
|
+
- examples/editable_table.rb
|
190
208
|
- examples/font_button.rb
|
191
209
|
- examples/form.rb
|
192
210
|
- examples/grid.rb
|
@@ -209,6 +227,7 @@ files:
|
|
209
227
|
- lib/glimmer/libui/check_menu_item_proxy.rb
|
210
228
|
- lib/glimmer/libui/checkbox_proxy.rb
|
211
229
|
- lib/glimmer/libui/color_button_proxy.rb
|
230
|
+
- lib/glimmer/libui/column.rb
|
212
231
|
- lib/glimmer/libui/combobox_proxy.rb
|
213
232
|
- lib/glimmer/libui/control_proxy.rb
|
214
233
|
- lib/glimmer/libui/date_picker_proxy.rb
|
@@ -219,6 +238,8 @@ files:
|
|
219
238
|
- lib/glimmer/libui/grid_proxy.rb
|
220
239
|
- lib/glimmer/libui/group_proxy.rb
|
221
240
|
- lib/glimmer/libui/horizontal_box_proxy.rb
|
241
|
+
- lib/glimmer/libui/image_column_proxy.rb
|
242
|
+
- lib/glimmer/libui/image_part_proxy.rb
|
222
243
|
- lib/glimmer/libui/label_proxy.rb
|
223
244
|
- lib/glimmer/libui/menu_item_proxy.rb
|
224
245
|
- lib/glimmer/libui/menu_proxy.rb
|
@@ -229,6 +250,8 @@ files:
|
|
229
250
|
- lib/glimmer/libui/radio_buttons_proxy.rb
|
230
251
|
- lib/glimmer/libui/separator_menu_item_proxy.rb
|
231
252
|
- lib/glimmer/libui/tab_item_proxy.rb
|
253
|
+
- lib/glimmer/libui/table_proxy.rb
|
254
|
+
- lib/glimmer/libui/text_column_proxy.rb
|
232
255
|
- lib/glimmer/libui/time_picker_proxy.rb
|
233
256
|
- lib/glimmer/libui/vertical_box_proxy.rb
|
234
257
|
- lib/glimmer/libui/window_proxy.rb
|