glimmer-dsl-libui 0.0.27 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,6 +21,7 @@
21
21
 
22
22
  require 'glimmer/libui/control_proxy'
23
23
  require 'glimmer/data_binding/observer'
24
+ require 'glimmer/fiddle_consumer'
24
25
 
25
26
  using ArrayIncludeMethods
26
27
 
@@ -30,6 +31,8 @@ module Glimmer
30
31
  #
31
32
  # Follows the Proxy Design Pattern
32
33
  class TableProxy < ControlProxy
34
+ include Glimmer::FiddleConsumer
35
+
33
36
  attr_reader :model_handler, :model, :table_params, :columns
34
37
 
35
38
  def initialize(keyword, parent, args, &block)
@@ -71,12 +74,16 @@ module Glimmer
71
74
  @last_cell_rows = @cell_rows.clone
72
75
  Glimmer::DataBinding::Observer.proc do
73
76
  if @cell_rows.size < @last_cell_rows.size && @last_cell_rows.include_all?(*@cell_rows)
74
- @last_cell_rows.array_diff_indexes(@cell_rows).reverse.each do |index|
75
- ::LibUI.table_model_row_deleted(model, index)
77
+ @last_cell_rows.array_diff_indexes(@cell_rows).reverse.each do |row|
78
+ ::LibUI.table_model_row_deleted(model, row)
76
79
  end
77
80
  elsif @cell_rows.size > @last_cell_rows.size && @cell_rows.include_all?(*@last_cell_rows)
78
- @cell_rows.array_diff_indexes(@last_cell_rows).each do |index|
79
- ::LibUI.table_model_row_inserted(model, index)
81
+ @cell_rows.array_diff_indexes(@last_cell_rows).each do |row|
82
+ ::LibUI.table_model_row_inserted(model, row)
83
+ end
84
+ else
85
+ @cell_rows.each_with_index do |new_row_data, row|
86
+ ::LibUI.table_model_row_changed(model, row) if new_row_data != @last_cell_rows[row]
80
87
  end
81
88
  end
82
89
  @last_cell_rows = @cell_rows.clone
@@ -108,8 +115,8 @@ module Glimmer
108
115
 
109
116
  def build_control
110
117
  @model_handler = ::LibUI::FFI::TableModelHandler.malloc
111
- @model_handler.NumColumns = rbcallback(4) { @columns.map {|c| c.is_a?(DualColumn) ? 2 : 1}.sum }
112
- @model_handler.ColumnType = rbcallback(4, [1, 1, 4]) do |_, _, column|
118
+ @model_handler.NumColumns = fiddle_closure_block_caller(4) { @columns.map {|c| c.is_a?(DualColumn) ? 2 : 1}.sum }
119
+ @model_handler.ColumnType = fiddle_closure_block_caller(4, [1, 1, 4]) do |_, _, column|
113
120
  case @columns[column]
114
121
  when TextColumnProxy, ButtonColumnProxy, NilClass
115
122
  0
@@ -119,8 +126,8 @@ module Glimmer
119
126
  2
120
127
  end
121
128
  end
122
- @model_handler.NumRows = rbcallback(4) { cell_rows.count }
123
- @model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
129
+ @model_handler.NumRows = fiddle_closure_block_caller(4) { cell_rows.count }
130
+ @model_handler.CellValue = fiddle_closure_block_caller(1, [1, 1, 4, 4]) do |_, _, row, column|
124
131
  the_cell_rows = expanded_cell_rows
125
132
  case @columns[column]
126
133
  when TextColumnProxy, ButtonColumnProxy, NilClass
@@ -133,7 +140,7 @@ module Glimmer
133
140
  ::LibUI.new_table_value_int((expanded_cell_rows[row] && (expanded_cell_rows[row][column].to_i)))
134
141
  end
135
142
  end
136
- @model_handler.SetCellValue = rbcallback(0, [1, 1, 4, 4, 1]) do |_, _, row, column, val|
143
+ @model_handler.SetCellValue = fiddle_closure_block_caller(0, [1, 1, 4, 4, 1]) do |_, _, row, column, val|
137
144
  case @columns[column]
138
145
  when TextColumnProxy
139
146
  column = @columns[column].index
@@ -163,16 +170,6 @@ module Glimmer
163
170
  end
164
171
  end
165
172
 
166
- def rbcallback(*args, &block)
167
- # TODO consider moving to a more general reusable location in the future (e.g. when used with `AreaProxy`)
168
- # Protects BlockCaller objects from garbage collection.
169
- @blockcaller ||= []
170
- args << [0] if args.size == 1 # Argument types are ommited
171
- blockcaller = Fiddle::Closure::BlockCaller.new(*args, &block)
172
- @blockcaller << blockcaller
173
- blockcaller
174
- end
175
-
176
173
  def next_column_index
177
174
  @next_column_index ||= -1
178
175
  @next_column_index += 1
@@ -48,8 +48,14 @@ module Glimmer
48
48
  end
49
49
 
50
50
  def on_destroy(&block)
51
+ # TODO look into a way to generalize this logic for multiple listeners
51
52
  @on_destroy_procs ||= []
52
- @on_destroy_procs << block
53
+ if block.nil?
54
+ @on_destroy_procs
55
+ else
56
+ @on_destroy_procs << block
57
+ block
58
+ end
53
59
  end
54
60
 
55
61
  def show
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.27
4
+ version: 0.1.2
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-27 00:00:00.000000000 Z
11
+ date: 2021-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.5
19
+ version: 2.2.0
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.5
26
+ version: 2.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: os
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -194,6 +194,8 @@ files:
194
194
  - VERSION
195
195
  - bin/girb
196
196
  - bin/girb_runner.rb
197
+ - examples/basic_area.rb
198
+ - examples/basic_area2.rb
197
199
  - examples/basic_button.rb
198
200
  - examples/basic_entry.rb
199
201
  - examples/basic_table.rb
@@ -208,6 +210,8 @@ files:
208
210
  - examples/color_button.rb
209
211
  - examples/control_gallery.rb
210
212
  - examples/date_time_picker.rb
213
+ - examples/dynamic_area.rb
214
+ - examples/dynamic_area2.rb
211
215
  - examples/editable_column_table.rb
212
216
  - examples/editable_table.rb
213
217
  - examples/font_button.rb
@@ -227,7 +231,9 @@ files:
227
231
  - lib/glimmer/dsl/libui/property_expression.rb
228
232
  - lib/glimmer/dsl/libui/save_file_expression.rb
229
233
  - lib/glimmer/dsl/libui/tab_item_expression.rb
234
+ - lib/glimmer/fiddle_consumer.rb
230
235
  - lib/glimmer/libui/about_menu_item_proxy.rb
236
+ - lib/glimmer/libui/area_proxy.rb
231
237
  - lib/glimmer/libui/box.rb
232
238
  - lib/glimmer/libui/button_column_proxy.rb
233
239
  - lib/glimmer/libui/button_proxy.rb
@@ -259,10 +265,12 @@ files:
259
265
  - lib/glimmer/libui/menu_proxy.rb
260
266
  - lib/glimmer/libui/multiline_entry_proxy.rb
261
267
  - lib/glimmer/libui/non_wrapping_multiline_entry_proxy.rb
268
+ - lib/glimmer/libui/path_proxy.rb
262
269
  - lib/glimmer/libui/preferences_menu_item_proxy.rb
263
270
  - lib/glimmer/libui/progress_bar_column_proxy.rb
264
271
  - lib/glimmer/libui/quit_menu_item_proxy.rb
265
272
  - lib/glimmer/libui/radio_buttons_proxy.rb
273
+ - lib/glimmer/libui/rectangle_proxy.rb
266
274
  - lib/glimmer/libui/separator_menu_item_proxy.rb
267
275
  - lib/glimmer/libui/tab_item_proxy.rb
268
276
  - lib/glimmer/libui/table_proxy.rb