glimmer-dsl-libui 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ab738eba1965fffc98860a23a44f2e1ed15c0c426ba4d21bcbb3fc4812ecde5
4
- data.tar.gz: 2d5c195882767b63d941d9b8bad8338bc5d5ce160e97f34a9f57f5631c833fac
3
+ metadata.gz: a9821169ec1b82253239d5169165c94c76e8b4efa407c27ccf4e73eae25cd68f
4
+ data.tar.gz: 47b312e49da5f6acf1011d1e45283d1b6d9cb2f8a03d37e218fba794e07990d9
5
5
  SHA512:
6
- metadata.gz: 23e1de3b8f30f90abb605a351e6cd9302dd778da2e711f7c72c4ad39b267090bab324bd056ca3855c343781c53757af320ca67c0d4aacac4c6351f7cf4a646e8
7
- data.tar.gz: 18f3d9b8d48bc15a342efeb38f6979e1b2516b5144a790876d931c28a2803da840f980d0d9b9cd4c96484817d4cf241d19b7b64c751229fa1ae6a236029545ac
6
+ metadata.gz: 326d75305142c5773a9dfd487fb595e7271c26a003ff1db10771a5e805e8c77eb567f6f56b54ac7ab721e2ed532f70ccdd9fa42437f6fd12c616f98d28c91f0e
7
+ data.tar.gz: a60432231078bf85d00e8882657eae577eeb99cf0b71a57f12c485c933577f8f4f7d98ec1cb6337f4ab4f1d02bf0c0061a618b9f998c16dc05641ad6efc8352f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.17
4
+
5
+ - Support examples/basic_table.rb
6
+ - Support non-editable `table` control
7
+ - Support table `text_column`
8
+ - Support table `cell_rows` property as an `Array` (rows) of `Array`s (row columns) of cell values
9
+
3
10
  ## 0.0.16
4
11
 
5
12
  - 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.16
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for LibUI 0.0.17
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.16](#-glimmer-dsl-for-libui-0016)
46
+ - [Glimmer DSL for LibUI 0.0.17](#-glimmer-dsl-for-libui-0017)
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.16'
160
+ gem 'glimmer-dsl-libui', '~> 0.0.17'
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.
@@ -241,9 +242,11 @@ Control(Args) | Properties | Listeners
241
242
  `spinbox(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
242
243
  `tab` | `margined` (Boolean), `num_pages` (`Integer`) | None
243
244
  `tab_item(name as String)` | `index` [read-only] (`Integer`), `margined` (Boolean), `name` [read-only] (`String`) | None
245
+ `table` | `cell_rows` (`Array` (rows) of `Arrays` (row columns) of cell values (e.g. `String` values)) | None
246
+ `text_column(name as String)` | None | None
244
247
  `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
248
  `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`
249
+ `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
250
 
248
251
  ### Common Control Properties
249
252
  - `enabled` (Boolean)
@@ -303,6 +306,7 @@ Control(Args) | Properties | Listeners
303
306
  - When destroying a control nested under a `window` or `group`, it is automatically unset as their child to allow successful destruction
304
307
  - 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
308
  - Smart defaults for `grid` child attributes are `left` (`0`), `top` (`0`), `xspan` (`1`), `yspan` (`1`), `hexpand` (`false`), `halign` (`0`), `vexpand` (`false`), and `valign` (`0`)
309
+ - The `table` control automatically constructs required `TableModelHandler`, `TableModel`, and `TableParams`, calculating all their arguments from `cell_rows` property (e.g. `NumRows`)
306
310
 
307
311
  ### API Gotchas
308
312
 
@@ -1629,8 +1633,8 @@ window('Grid') {
1629
1633
  tab {
1630
1634
  tab_item('Spanning') {
1631
1635
  grid {
1632
- 4.times { |left_value|
1633
- 4.times { |top_value|
1636
+ 4.times { |top_value|
1637
+ 4.times { |left_value|
1634
1638
  label("(#{left_value}, #{top_value}) xspan1\nyspan1") {
1635
1639
  left left_value
1636
1640
  top top_value
@@ -1749,6 +1753,126 @@ window('Form') { |w|
1749
1753
  }.show
1750
1754
  ```
1751
1755
 
1756
+ ### Basic Table
1757
+
1758
+ [examples/basic_table.rb](examples/basic_table.rb)
1759
+
1760
+ Run with this command from the root of the project if you cloned the project:
1761
+
1762
+ ```
1763
+ ruby -r './lib/glimmer-dsl-libui' examples/basic_table.rb
1764
+ ```
1765
+
1766
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1767
+
1768
+ ```
1769
+ ruby -r glimmer-dsl-libui -e "require 'examples/basic_table'"
1770
+ ```
1771
+
1772
+ Mac
1773
+
1774
+ ![glimmer-dsl-libui-mac-basic-table.png](images/glimmer-dsl-libui-mac-basic-table.png)
1775
+
1776
+ Linux
1777
+
1778
+ ![glimmer-dsl-libui-linux-basic-table.png](images/glimmer-dsl-libui-linux-basic-table.png)
1779
+
1780
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
1781
+
1782
+ ```ruby
1783
+ require 'libui'
1784
+
1785
+ UI = LibUI
1786
+
1787
+ UI.init
1788
+
1789
+ main_window = UI.new_window('Animal sounds', 300, 200, 1)
1790
+
1791
+ hbox = UI.new_horizontal_box
1792
+ UI.window_set_child(main_window, hbox)
1793
+
1794
+ data = [
1795
+ %w[cat meow],
1796
+ %w[dog woof],
1797
+ %w[checken cock-a-doodle-doo],
1798
+ %w[hourse neigh],
1799
+ %w[cow moo]
1800
+ ]
1801
+
1802
+ # Protects BlockCaller objects from garbage collection.
1803
+ @blockcaller = []
1804
+ def rbcallback(*args, &block)
1805
+ args << [0] if args.size == 1 # Argument types are ommited
1806
+ blockcaller = Fiddle::Closure::BlockCaller.new(*args, &block)
1807
+ @blockcaller << blockcaller
1808
+ blockcaller
1809
+ end
1810
+
1811
+ model_handler = UI::FFI::TableModelHandler.malloc
1812
+ model_handler.NumColumns = rbcallback(4) { 2 }
1813
+ model_handler.ColumnType = rbcallback(4) { 0 }
1814
+ model_handler.NumRows = rbcallback(4) { 5 }
1815
+ model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
1816
+ UI.new_table_value_string(data[row][column])
1817
+ end
1818
+ model_handler.SetCellValue = rbcallback(0, [0]) {}
1819
+
1820
+ model = UI.new_table_model(model_handler)
1821
+
1822
+ table_params = UI::FFI::TableParams.malloc
1823
+ table_params.Model = model
1824
+ table_params.RowBackgroundColorModelColumn = -1
1825
+
1826
+ table = UI.new_table(table_params)
1827
+ UI.table_append_text_column(table, 'Animal', 0, -1)
1828
+ UI.table_append_text_column(table, 'Description', 1, -1)
1829
+
1830
+ UI.box_append(hbox, table, 1)
1831
+ UI.control_show(main_window)
1832
+
1833
+ UI.window_on_closing(main_window) do
1834
+ puts 'Bye Bye'
1835
+ UI.control_destroy(main_window)
1836
+ UI.free_table_model(model)
1837
+ UI.quit
1838
+ 0
1839
+ end
1840
+
1841
+ UI.main
1842
+ UI.quit
1843
+ ```
1844
+
1845
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1846
+
1847
+ ```ruby
1848
+ require 'glimmer-dsl-libui'
1849
+
1850
+ include Glimmer
1851
+
1852
+ data = [
1853
+ %w[cat meow],
1854
+ %w[dog woof],
1855
+ %w[chicken cock-a-doodle-doo],
1856
+ %w[hourse neigh],
1857
+ %w[cow moo]
1858
+ ]
1859
+
1860
+ window('Animal sounds', 300, 200) {
1861
+ horizontal_box {
1862
+ table {
1863
+ text_column('Animal')
1864
+ text_column('Description')
1865
+
1866
+ cell_rows data
1867
+ }
1868
+ }
1869
+
1870
+ on_closing do
1871
+ puts 'Bye Bye'
1872
+ end
1873
+ }.show
1874
+ ```
1875
+
1752
1876
  ## Contributing to glimmer-dsl-libui
1753
1877
 
1754
1878
  - Check out the latest master to make sure the feature hasn't been
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.16
1
+ 0.0.17
@@ -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
data/examples/grid.rb CHANGED
@@ -8,8 +8,8 @@ window('Grid') {
8
8
  tab {
9
9
  tab_item('Spanning') {
10
10
  grid {
11
- 4.times { |left_value|
12
- 4.times { |top_value|
11
+ 4.times { |top_value|
12
+ 4.times { |left_value|
13
13
  label("(#{left_value}, #{top_value}) xspan1\nyspan1") {
14
14
  left left_value
15
15
  top top_value
Binary file
@@ -0,0 +1,105 @@
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
+ @cell_rows = rows
65
+ end
66
+ end
67
+ alias cell_rows= cell_rows
68
+ alias set_cell_rows cell_rows
69
+
70
+ private
71
+
72
+ def build_control
73
+ @model_handler = ::LibUI::FFI::TableModelHandler.malloc
74
+ @model_handler.NumColumns = rbcallback(4) { @columns.count }
75
+ @model_handler.ColumnType = rbcallback(4) { 0 } # TODO derive from @columns when supporting multiple column types in the future
76
+ @model_handler.NumRows = rbcallback(4) { cell_rows.count }
77
+ @model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
78
+ ::LibUI.new_table_value_string((@cell_rows[row] && @cell_rows[row][column]).to_s)
79
+ end
80
+
81
+ @model = ::LibUI.new_table_model(@model_handler)
82
+
83
+ @table_params = ::LibUI::FFI::TableParams.malloc
84
+ @table_params.Model = @model
85
+ @table_params.RowBackgroundColorModelColumn = -1
86
+
87
+ @libui = ControlProxy.new_control(@keyword, [@table_params])
88
+ @libui.tap do
89
+ @columns.each {|column| column.send(:build_control) }
90
+ end
91
+ end
92
+
93
+ def rbcallback(*args, &block)
94
+ # TODO consider moving to a more general reusable location in the future (e.g. when used with `AreaProxy`)
95
+ # Protects BlockCaller objects from garbage collection.
96
+ @blockcaller ||= []
97
+ args << [0] if args.size == 1 # Argument types are ommited
98
+ blockcaller = Fiddle::Closure::BlockCaller.new(*args, &block)
99
+ @blockcaller << blockcaller
100
+ blockcaller
101
+ end
102
+
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,51 @@
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 text column objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class TextColumnProxy < ControlProxy
30
+ def initialize(keyword, parent, args, &block)
31
+ # TODO eventually move this to a supermodule ColumnProxy
32
+ @keyword = keyword
33
+ @parent_proxy = parent
34
+ @args = args
35
+ @block = block
36
+ @enabled = true
37
+ post_add_content if @block.nil?
38
+ end
39
+
40
+ def name
41
+ @args.first
42
+ end
43
+
44
+ private
45
+
46
+ def build_control
47
+ @libui = @parent_proxy.append_text_column(name, @parent_proxy.columns.map(&:libui).compact.count, -1) # -1 for non-editable for now until editing is supported
48
+ end
49
+ end
50
+ end
51
+ end
@@ -40,6 +40,16 @@ module Glimmer
40
40
  ::LibUI.send("window_set_child", @libui, nil)
41
41
  super
42
42
  end
43
+
44
+ def destroy
45
+ super
46
+ @on_destroy_procs&.each { |on_destroy_proc| on_destroy_proc.call(self)}
47
+ end
48
+
49
+ def on_destroy(&block)
50
+ @on_destroy_procs ||= []
51
+ @on_destroy_procs << block
52
+ end
43
53
 
44
54
  def show
45
55
  super
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
@@ -182,6 +182,7 @@ files:
182
182
  - bin/girb_runner.rb
183
183
  - examples/basic_button.rb
184
184
  - examples/basic_entry.rb
185
+ - examples/basic_table.rb
185
186
  - examples/basic_window.rb
186
187
  - examples/basic_window2.rb
187
188
  - examples/color_button.rb
@@ -229,6 +230,8 @@ files:
229
230
  - lib/glimmer/libui/radio_buttons_proxy.rb
230
231
  - lib/glimmer/libui/separator_menu_item_proxy.rb
231
232
  - lib/glimmer/libui/tab_item_proxy.rb
233
+ - lib/glimmer/libui/table_proxy.rb
234
+ - lib/glimmer/libui/text_column_proxy.rb
232
235
  - lib/glimmer/libui/time_picker_proxy.rb
233
236
  - lib/glimmer/libui/vertical_box_proxy.rb
234
237
  - lib/glimmer/libui/window_proxy.rb