glimmer-dsl-libui 0.0.21 → 0.0.22

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: 3a7491ce7cea65fb7025868e9fb2db5c4e6187ba269a177879e4276e50fa3d9f
4
- data.tar.gz: 9b47cab46d79af36dd06b6914570f30662540b7b8c1e634dc326ed9af32ad041
3
+ metadata.gz: 974aa189dcfa34a3e96c581592d2acaa4fa1e14edeb784c3b80e47cf21b1f90d
4
+ data.tar.gz: 6bb99a56fe942706ec3a773cd90d0cfd88554fc03cb27465fb375538a56ac351
5
5
  SHA512:
6
- metadata.gz: 692870dd49de81f7d2840579f0de3b7bd414bda277db56a4c28597febd012446c6b8b098bf56e5afe8c9b17f68547bb24bceaba45e15c3e4fd3ca041e5c37d2a
7
- data.tar.gz: 289ede334bc53171a6a028dca1d03e794d0e81329621f2278365bfdcb2079fd200da21161d4aed6cf8486f382c4e0b04afadf3883ba0e07790878dbfd8fad334
6
+ metadata.gz: '08fcb654b14c8bf9bdca6e1d3b28477cd8d1d389447d4162dabe7f8f743cd9ee68e033012e01feadc5e9ac92daeca0feb74c794d0323ad4c083dde1f0fc90125'
7
+ data.tar.gz: e215a320873a70904062254fd63c32296b917c661592983d89bd6fa940413a5e554b6aa42c8e637409d777c3e739c6e80d1fef8072d1c72b4f275fc8985b775e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.22
4
+
5
+ - New examples/basic_table_button.rb
6
+ - Support table `button_column`
7
+ - Support table `button_column` `enabled` property
8
+ - Support `on_clicked` listener for `button_column`
9
+ - Support automatic table cell value reading management (table row deletion upon actual `cell_rows` deletion due to implicit data-binding)
10
+
3
11
  ## 0.0.21
4
12
 
5
13
  - New examples/editable_column_table_image_text.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.21
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.22
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.21](#-glimmer-dsl-for-libui-0021)
46
+ - [Glimmer DSL for LibUI 0.0.22](#-glimmer-dsl-for-libui-0022)
47
47
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
48
48
  - [Usage](#usage)
49
49
  - [API](#api)
@@ -74,6 +74,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
74
74
  - [Editable Column Table](#editable-column-table)
75
75
  - [Basic Table Image](#basic-table-image)
76
76
  - [Basic Table Image Text](#basic-table-image-text)
77
+ - [Basic Table Button](#basic-table-button)
77
78
  - [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
78
79
  - [Help](#help)
79
80
  - [Issues](#issues)
@@ -161,7 +162,7 @@ gem install glimmer-dsl-libui
161
162
  Or install via Bundler `Gemfile`:
162
163
 
163
164
  ```ruby
164
- gem 'glimmer-dsl-libui', '~> 0.0.21'
165
+ gem 'glimmer-dsl-libui', '~> 0.0.22'
165
166
  ```
166
167
 
167
168
  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.
@@ -2245,6 +2246,64 @@ window('The Red Turtle', 900, 350) {
2245
2246
  }.show
2246
2247
  ```
2247
2248
 
2249
+ ### Basic Table Button
2250
+
2251
+ [examples/basic_table_button.rb](examples/basic_table_button.rb)
2252
+
2253
+ Run with this command from the root of the project if you cloned the project:
2254
+
2255
+ ```
2256
+ ruby -r './lib/glimmer-dsl-libui' examples/basic_table_button.rb
2257
+ ```
2258
+
2259
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
2260
+
2261
+ ```
2262
+ ruby -r glimmer-dsl-libui -e "require 'examples/basic_table_button'"
2263
+ ```
2264
+
2265
+ Mac
2266
+
2267
+ ![glimmer-dsl-libui-mac-basic-table-button.png](images/glimmer-dsl-libui-mac-basic-table-button.png)
2268
+ ![glimmer-dsl-libui-mac-basic-table-button-deleted.png](images/glimmer-dsl-libui-mac-basic-table-button-deleted.png)
2269
+
2270
+ Linux
2271
+
2272
+ ![glimmer-dsl-libui-linux-basic-table-button.png](images/glimmer-dsl-libui-linux-basic-table-button.png)
2273
+ ![glimmer-dsl-libui-linux-basic-table-button-deleted.png](images/glimmer-dsl-libui-linux-basic-table-button-deleted.png)
2274
+
2275
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
2276
+
2277
+ ```ruby
2278
+ require 'glimmer-dsl-libui'
2279
+
2280
+ include Glimmer
2281
+
2282
+ data = [
2283
+ %w[cat meow delete],
2284
+ %w[dog woof delete],
2285
+ %w[chicken cock-a-doodle-doo delete],
2286
+ %w[hourse neigh delete],
2287
+ %w[cow moo delete]
2288
+ ]
2289
+
2290
+ window('Animal sounds', 300, 200) {
2291
+ horizontal_box {
2292
+ table {
2293
+ text_column('Animal')
2294
+ text_column('Description')
2295
+ button_column('Action') {
2296
+ on_clicked do |row|
2297
+ data.delete_at(row) # automatically deletes actual table row due to implicit data-binding
2298
+ end
2299
+ }
2300
+
2301
+ cell_rows data # implicit data-binding
2302
+ }
2303
+ }
2304
+ }.show
2305
+ ```
2306
+
2248
2307
  ## Contributing to glimmer-dsl-libui
2249
2308
 
2250
2309
  - Check out the latest master to make sure the feature hasn't been
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.21
1
+ 0.0.22
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'glimmer-dsl-libui'
4
+
5
+ include Glimmer
6
+
7
+ data = [
8
+ %w[cat meow delete],
9
+ %w[dog woof delete],
10
+ %w[chicken cock-a-doodle-doo delete],
11
+ %w[hourse neigh delete],
12
+ %w[cow moo delete]
13
+ ]
14
+
15
+ window('Animal sounds', 300, 200) {
16
+ horizontal_box {
17
+ table {
18
+ text_column('Animal')
19
+ text_column('Description')
20
+ button_column('Action') {
21
+ on_clicked do |row|
22
+ data.delete_at(row) # automatically deletes actual table row due to implicit data-binding
23
+ end
24
+ }
25
+
26
+ cell_rows data # implicit data-binding
27
+ }
28
+ }
29
+
30
+ on_closing do
31
+ puts 'Bye Bye'
32
+ end
33
+ }.show
Binary file
@@ -35,10 +35,6 @@ module Glimmer
35
35
  module Libui
36
36
  Engine.add_dynamic_expressions(
37
37
  Libui,
38
- # list_selection_data_binding
39
- # data_binding
40
- # block_attribute
41
- # attribute
42
38
  %w[
43
39
  listener
44
40
  property
@@ -0,0 +1,67 @@
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
+ require 'glimmer/libui/enableable_column'
25
+
26
+ module Glimmer
27
+ module LibUI
28
+ # Proxy for LibUI button column objects
29
+ #
30
+ # Follows the Proxy Design Pattern
31
+ class ButtonColumnProxy < ControlProxy
32
+ include Column
33
+ include EnableableColumn
34
+
35
+ def on_clicked(&block)
36
+ # TODO consider generalizing into custom listeners and moving to ControlProxy
37
+ @on_clicked_procs ||= []
38
+ @on_clicked_procs << block
39
+ end
40
+
41
+ def can_handle_listener?(listener_name)
42
+ listener_name == 'on_clicked' || super
43
+ end
44
+
45
+ def handle_listener(listener_name, &listener)
46
+ case listener_name
47
+ when 'on_clicked'
48
+ on_clicked(&listener)
49
+ else
50
+ super
51
+ end
52
+ end
53
+
54
+ def notify_listeners(listener_name, *args)
55
+ @on_clicked_procs&.each do |on_clicked_proc|
56
+ on_clicked_proc.call(*args)
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def build_control
63
+ @parent_proxy.append_button_column(name, column_index, enabled_value)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -19,8 +19,6 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- require 'glimmer/libui/control_proxy'
23
-
24
22
  module Glimmer
25
23
  module LibUI
26
24
  # Common logic for all column proxy objects
@@ -19,8 +19,6 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- require 'glimmer/libui/control_proxy'
23
-
24
22
  module Glimmer
25
23
  module LibUI
26
24
  # A dual column is one that represents two values (e.g. image and text or checkbox and text)
@@ -19,13 +19,12 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- require 'glimmer/libui/control_proxy'
23
-
24
22
  module Glimmer
25
23
  module LibUI
26
24
  module EditableColumn
27
25
  def editable(value = nil)
28
26
  if value.nil?
27
+ @editable = false if @editable.nil?
29
28
  @editable
30
29
  else
31
30
  @editable = !!value
@@ -0,0 +1,44 @@
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
+ module Glimmer
23
+ module LibUI
24
+ module EnableableColumn
25
+ def enabled(value = nil)
26
+ if value.nil?
27
+ @enabled = true if @enabled.nil?
28
+ @enabled
29
+ else
30
+ @enabled = !!value
31
+ end
32
+ end
33
+ alias enabled= enabled
34
+ alias set_enabled enabled
35
+ alias enabled? enabled
36
+
37
+ private
38
+
39
+ def enabled_value
40
+ enabled? ? -2 : -1
41
+ end
42
+ end
43
+ end
44
+ end
@@ -21,6 +21,8 @@
21
21
 
22
22
  require 'glimmer/libui/control_proxy'
23
23
  require 'glimmer/libui/column'
24
+ require 'glimmer/libui/dual_column'
25
+ require 'glimmer/libui/editable_column'
24
26
 
25
27
  module Glimmer
26
28
  module LibUI
@@ -20,6 +20,9 @@
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  require 'glimmer/libui/control_proxy'
23
+ require 'glimmer/data_binding/observer'
24
+
25
+ using ArrayIncludeMethods
23
26
 
24
27
  module Glimmer
25
28
  module LibUI
@@ -63,18 +66,19 @@ module Glimmer
63
66
  if rows.nil?
64
67
  @cell_rows
65
68
  else
66
- rows = rows.map do |row|
67
- row.map do |cell|
68
- if cell.respond_to?(:libui)
69
- cell.libui
70
- elsif cell.is_a?(Array)
71
- cell.map { |inner_cell| inner_cell.respond_to?(:libui) ? inner_cell.libui : inner_cell }
72
- else
73
- cell
69
+ @cell_rows = rows
70
+ @cell_rows.tap do
71
+ @last_cell_rows = @cell_rows.clone
72
+ Glimmer::DataBinding::Observer.proc do
73
+ if (@cell_rows.size == @last_cell_rows.size - 1) && @last_cell_rows & @cell_rows == @cell_rows
74
+ _, row = @last_cell_rows.each_with_index.find do |row_data, row|
75
+ !@cell_rows.include?(row_data)
76
+ end
77
+ ::LibUI.table_model_row_deleted(model, row)
74
78
  end
75
- end
79
+ @last_cell_rows = @cell_rows.clone
80
+ end.observe(self, :cell_rows)
76
81
  end
77
- @cell_rows = rows
78
82
  end
79
83
  end
80
84
  alias cell_rows= cell_rows
@@ -104,7 +108,7 @@ module Glimmer
104
108
  @model_handler.NumColumns = rbcallback(4) { @columns.map {|c| c.is_a?(DualColumn) ? 2 : 1}.sum }
105
109
  @model_handler.ColumnType = rbcallback(4, [1, 1, 4]) do |_, _, column|
106
110
  case @columns[column]
107
- when TextColumnProxy, NilClass
111
+ when TextColumnProxy, ButtonColumnProxy, NilClass
108
112
  0
109
113
  when ImageColumnProxy, ImageTextColumnProxy
110
114
  1
@@ -114,18 +118,16 @@ module Glimmer
114
118
  # 2
115
119
  # when ProgressBarColumnProxy
116
120
  # 2
117
- # when ButtonColumnProxy
118
- # 0
119
121
  end
120
122
  end
121
123
  @model_handler.NumRows = rbcallback(4) { cell_rows.count }
122
124
  @model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
123
125
  the_cell_rows = expanded_cell_rows
124
126
  case @columns[column]
125
- when TextColumnProxy, NilClass
127
+ when TextColumnProxy, ButtonColumnProxy, NilClass
126
128
  ::LibUI.new_table_value_string((expanded_cell_rows[row] && expanded_cell_rows[row][column]).to_s)
127
129
  when ImageColumnProxy, ImageTextColumnProxy
128
- ::LibUI.new_table_value_image((expanded_cell_rows[row] && expanded_cell_rows[row][column]))
130
+ ::LibUI.new_table_value_image((expanded_cell_rows[row] && (expanded_cell_rows[row][column].respond_to?(:libui) ? expanded_cell_rows[row][column].libui : expanded_cell_rows[row][column])))
129
131
  end
130
132
  end
131
133
  @model_handler.SetCellValue = rbcallback(0, [1, 1, 4, 4, 1]) do |_, _, row, column, val|
@@ -135,9 +137,10 @@ module Glimmer
135
137
  @cell_rows[row] ||= []
136
138
  @cell_rows[row][column] = ::LibUI.table_value_string(val).to_s
137
139
  when NilClass
138
- # TODO ensure this works for editable table
139
140
  column = @columns[column - 1].index
140
141
  @cell_rows[row][column][1] = ::LibUI.table_value_string(val).to_s
142
+ when ButtonColumnProxy
143
+ @columns[column].notify_listeners(:on_clicked, row)
141
144
  end
142
145
  end
143
146
 
@@ -21,6 +21,7 @@
21
21
 
22
22
  require 'glimmer/libui/control_proxy'
23
23
  require 'glimmer/libui/column'
24
+ require 'glimmer/libui/editable_column'
24
25
 
25
26
  module Glimmer
26
27
  module LibUI
@@ -61,20 +61,29 @@ module Glimmer
61
61
  end
62
62
  end
63
63
 
64
+ def can_handle_listener?(listener_name)
65
+ listener_name == 'on_destroy' || super
66
+ end
67
+
64
68
  def handle_listener(listener_name, &listener)
65
- if listener_name == 'on_closing'
66
- default_behavior_listener = Proc.new do
67
- return_value = listener.call(self)
68
- if return_value.is_a?(Numeric)
69
- return_value
70
- else
71
- destroy
72
- ::LibUI.quit
73
- 0
69
+ case listener_name
70
+ when 'on_destroy'
71
+ on_destroy(&listener)
72
+ else
73
+ if listener_name == 'on_closing'
74
+ default_behavior_listener = Proc.new do
75
+ return_value = listener.call(self)
76
+ if return_value.is_a?(Numeric)
77
+ return_value
78
+ else
79
+ destroy
80
+ ::LibUI.quit
81
+ 0
82
+ end
74
83
  end
75
84
  end
85
+ super(listener_name, &default_behavior_listener)
76
86
  end
77
- super(listener_name, &default_behavior_listener)
78
87
  end
79
88
 
80
89
  private
@@ -27,6 +27,7 @@ require 'glimmer'
27
27
  # require 'puts_debuggerer' if ENV['pd'].to_s.downcase == 'true'
28
28
  # require 'super_module'
29
29
  require 'os'
30
+ require 'array_include_methods'
30
31
  require 'libui'
31
32
 
32
33
  # Internal requires
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.21
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.2
19
+ version: 2.1.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.2
26
+ version: 2.1.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: os
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -197,6 +197,7 @@ files:
197
197
  - examples/basic_button.rb
198
198
  - examples/basic_entry.rb
199
199
  - examples/basic_table.rb
200
+ - examples/basic_table_button.rb
200
201
  - examples/basic_table_image.rb
201
202
  - examples/basic_table_image_text.rb
202
203
  - examples/basic_window.rb
@@ -224,6 +225,7 @@ files:
224
225
  - lib/glimmer/dsl/libui/tab_item_expression.rb
225
226
  - lib/glimmer/libui/about_menu_item_proxy.rb
226
227
  - lib/glimmer/libui/box.rb
228
+ - lib/glimmer/libui/button_column_proxy.rb
227
229
  - lib/glimmer/libui/button_proxy.rb
228
230
  - lib/glimmer/libui/check_menu_item_proxy.rb
229
231
  - lib/glimmer/libui/checkbox_proxy.rb
@@ -236,6 +238,7 @@ files:
236
238
  - lib/glimmer/libui/dual_column.rb
237
239
  - lib/glimmer/libui/editable_column.rb
238
240
  - lib/glimmer/libui/editable_combobox_proxy.rb
241
+ - lib/glimmer/libui/enableable_column.rb
239
242
  - lib/glimmer/libui/font_button_proxy.rb
240
243
  - lib/glimmer/libui/form_proxy.rb
241
244
  - lib/glimmer/libui/grid_proxy.rb