glimmer-dsl-libui 0.4.17 → 0.4.18

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: 7fc87cc5cdac4adda4a307a3b38ec3255efdacd9a97a667c6840788be005ab80
4
- data.tar.gz: 2d57256b28fb43d584949d9316ceaf70ca67999b918ebfca5898aef99f78add4
3
+ metadata.gz: 2d56a2500e640c9f34f29daddc718a1adee47564da205fc7aff171047f90581f
4
+ data.tar.gz: 0067be097b14cf452323ce2faf79c244f99b525b24bd400b248119d8e2b24be4
5
5
  SHA512:
6
- metadata.gz: 3490923e9e595407a17350f337f1a8128a59bba1d7b0b2ce2dde12c1425324b6ca8a7688a307290a79baece9eeda8f54bedb3c2e6eb59dbfc65d9702136b6271
7
- data.tar.gz: f935b3d85c167e5697973e77a419ad2d929e3071a5013fba2dd3b04035b5da5d1e5623df10ceefb6535fed428b2f127f42373fb42b54853f61f0834031addb7f
6
+ metadata.gz: 5c954f84c3565d6c4dd2fe5262b5d34749ee5d5efc94f9cbb351d1924b442474089bbf731f8d418cae332f44ff215d0a21a54ceded566667b6e558109e28ea82
7
+ data.tar.gz: e0fcf189174a77fe48f80cbae8af6d0028092c4b19e1c653243845d194bd923e42fa5ae29f2a43cbe684106dfbc107eb6193af63d0e16e79fa5b40d8b383a47e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.4.18
4
+
5
+ - Support setting `table` `cell_rows` after the `table` definition completed (e.g. `@table.cell_rows = data` after `table {}` curly braces closed already)
6
+ - Support adding to `table` `cell_rows` piecemeal after the `table` definition completed (e.g. `data.each { |row| @table.cell_rows << row }` after `table {}` curly braces closed already)
7
+ - Support notifying observers of control property changes when calling the `set_attribute` version of attribute writers, not just `attribute=`
8
+ - Hide background field in examples/custom_draw_text.rb on Windows since it is not supported there
9
+ - Fix issue with `quit_menu_item` click resulting in a stack overflow on Windows
10
+
3
11
  ## 0.4.17
4
12
 
5
13
  - Remove Windows workaround of always adding an extra row at the bottom of `table` as it is no longer necessary after adding a better workaround (on Windows, add & remove row just after constructing `table` to get rid of double-delete glitch)
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.4.17
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.4.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
  [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@@ -506,7 +506,7 @@ gem install glimmer-dsl-libui
506
506
  Or install via Bundler `Gemfile`:
507
507
 
508
508
  ```ruby
509
- gem 'glimmer-dsl-libui', '~> 0.4.17'
509
+ gem 'glimmer-dsl-libui', '~> 0.4.18'
510
510
  ```
511
511
 
512
512
  Test that installation worked by running the [Meta-Example](#examples):
@@ -6039,7 +6039,7 @@ Glimmer::LibUI.timer(1) do
6039
6039
  cpu_percentage_value = nil
6040
6040
  if OS.windows?
6041
6041
  cpu_percentage_raw_value = `wmic cpu get loadpercentage`
6042
- cpu_percentage_value = cpu_percentage_raw_value.split("\n")[2].to_i
6042
+ cpu_percentage_value = cpu_percentage_raw_value.split("\n").map(&:strip).find {|l| l.match(/^\d+$/)}.to_i
6043
6043
  elsif OS.mac?
6044
6044
  cpu_percentage_value = `ps -A -o %cpu | awk '{s+=$1} END {print s}'`.to_i
6045
6045
  elsif OS.linux?
@@ -6110,6 +6110,7 @@ class CustomDrawText
6110
6110
  @string.font = fb.font
6111
6111
  end
6112
6112
  }
6113
+
6113
6114
  color_button { |cb|
6114
6115
  label 'Color'
6115
6116
 
@@ -6117,13 +6118,17 @@ class CustomDrawText
6117
6118
  @string.color = cb.color
6118
6119
  end
6119
6120
  }
6120
- color_button { |cb|
6121
- label 'Background'
6122
-
6123
- on_changed do
6124
- @string.background = cb.color
6125
- end
6126
- }
6121
+
6122
+ unless OS.windows?
6123
+ color_button { |cb|
6124
+ label 'Background'
6125
+
6126
+ on_changed do
6127
+ @string.background = cb.color
6128
+ end
6129
+ }
6130
+ end
6131
+
6127
6132
  combobox { |c|
6128
6133
  label 'Underline'
6129
6134
  items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
@@ -6133,12 +6138,36 @@ class CustomDrawText
6133
6138
  @string.underline = c.selected_item.underscore
6134
6139
  end
6135
6140
  }
6141
+
6142
+ combobox { |c|
6143
+ label 'Underline Built-In Color'
6144
+ items Glimmer::LibUI.enum_symbols(:underline_color).map(&:to_s).map(&:capitalize)
6145
+ selected 'Custom'
6146
+
6147
+ on_selected do
6148
+ @underline_custom_color_button.enabled = c.selected_item == 'Custom'
6149
+ if c.selected_item == 'Custom'
6150
+ @string.underline_color = @underline_custom_color_button.color
6151
+ else
6152
+ @string.underline_color = c.selected_item.underscore
6153
+ @underline_custom_color_button.color = :black
6154
+ end
6155
+ end
6156
+ }
6157
+
6158
+ @underline_custom_color_button = color_button {
6159
+ label 'Underline Custom Color'
6160
+
6161
+ on_changed do
6162
+ @string.underline_color = @underline_custom_color_button.color
6163
+ end
6164
+ }
6136
6165
  }
6137
6166
 
6138
6167
  area {
6139
- text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
6168
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width] - 2*x)
6140
6169
  # align :left # default alignment
6141
-
6170
+
6142
6171
  @string = string {
6143
6172
  ' At last Ygramul sensed that something was coming toward ' \
6144
6173
  'her. With the speed of lightning, she turned about, confronting ' \
@@ -6183,62 +6212,94 @@ require 'glimmer-dsl-libui'
6183
6212
  # The English version, translated by Ralph Manheim, was published in 1983.
6184
6213
  class CustomDrawText
6185
6214
  include Glimmer
6186
-
6215
+
6187
6216
  def launch
6188
6217
  window('Michael Ende (1929-1995) The Neverending Story', 600, 500) {
6189
6218
  margined true
6190
-
6219
+
6191
6220
  vertical_box {
6192
6221
  form {
6193
6222
  stretchy false
6194
-
6223
+
6195
6224
  font_button { |fb|
6196
6225
  label 'Font'
6197
-
6226
+
6198
6227
  on_changed do
6199
6228
  @font = fb.font
6200
6229
  @area.queue_redraw_all
6201
6230
  end
6202
6231
  }
6232
+
6203
6233
  color_button { |cb|
6204
6234
  label 'Color'
6205
-
6235
+
6206
6236
  on_changed do
6207
6237
  @color = cb.color
6208
6238
  @area.queue_redraw_all
6209
6239
  end
6210
6240
  }
6211
- color_button { |cb|
6212
- label 'Background'
6213
-
6214
- on_changed do
6215
- @background = cb.color
6216
- @area.queue_redraw_all
6217
- end
6218
- }
6241
+
6242
+ unless OS.windows?
6243
+ color_button { |cb|
6244
+ label 'Background'
6245
+
6246
+ on_changed do
6247
+ @background = cb.color
6248
+ @area.queue_redraw_all
6249
+ end
6250
+ }
6251
+ end
6252
+
6219
6253
  combobox { |c|
6220
6254
  label 'Underline'
6221
6255
  items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
6222
6256
  selected 'None'
6223
-
6257
+
6224
6258
  on_selected do
6225
6259
  @underline = c.selected_item.underscore
6226
6260
  @area.queue_redraw_all
6227
6261
  end
6228
6262
  }
6263
+
6264
+ combobox { |c|
6265
+ label 'Underline Built-In Color'
6266
+ items Glimmer::LibUI.enum_symbols(:underline_color).map(&:to_s).map(&:capitalize)
6267
+ selected 'Custom'
6268
+
6269
+ on_selected do
6270
+ @underline_custom_color_button.enabled = c.selected_item == 'Custom'
6271
+ if c.selected_item == 'Custom'
6272
+ @underline_color = @underline_custom_color_button.color
6273
+ else
6274
+ @underline_color = c.selected_item.underscore
6275
+ @underline_custom_color_button.color = :black
6276
+ end
6277
+ @area.queue_redraw_all
6278
+ end
6279
+ }
6280
+
6281
+ @underline_custom_color_button = color_button {
6282
+ label 'Underline Custom Color'
6283
+
6284
+ on_changed do
6285
+ @underline_color = @underline_custom_color_button.color
6286
+ @area.queue_redraw_all
6287
+ end
6288
+ }
6229
6289
  }
6230
-
6290
+
6231
6291
  @area = area {
6232
6292
  on_draw do |area_draw_params|
6233
- text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
6293
+ text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width] - 2*x)
6234
6294
  # align :left # default alignment
6235
-
6295
+
6236
6296
  string {
6237
6297
  font @font
6238
6298
  color @color
6239
6299
  background @background
6240
6300
  underline @underline
6241
-
6301
+ underline_color @underline_color
6302
+
6242
6303
  ' At last Ygramul sensed that something was coming toward ' \
6243
6304
  'her. With the speed of lightning, she turned about, confronting ' \
6244
6305
  'Atreyu with an enormous steel-blue face. Her single eye had a ' \
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.17
1
+ 0.4.18
@@ -17,7 +17,7 @@ window('Animal sounds', 300, 200) {
17
17
  table {
18
18
  text_column('Animal')
19
19
  text_column('Description')
20
-
20
+
21
21
  cell_rows data
22
22
  }
23
23
  }
@@ -21,6 +21,7 @@ class CustomDrawText
21
21
  @string.font = fb.font
22
22
  end
23
23
  }
24
+
24
25
  color_button { |cb|
25
26
  label 'Color'
26
27
 
@@ -28,13 +29,17 @@ class CustomDrawText
28
29
  @string.color = cb.color
29
30
  end
30
31
  }
31
- color_button { |cb|
32
- label 'Background'
33
-
34
- on_changed do
35
- @string.background = cb.color
36
- end
37
- }
32
+
33
+ unless OS.windows?
34
+ color_button { |cb|
35
+ label 'Background'
36
+
37
+ on_changed do
38
+ @string.background = cb.color
39
+ end
40
+ }
41
+ end
42
+
38
43
  combobox { |c|
39
44
  label 'Underline'
40
45
  items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
@@ -44,6 +49,7 @@ class CustomDrawText
44
49
  @string.underline = c.selected_item.underscore
45
50
  end
46
51
  }
52
+
47
53
  combobox { |c|
48
54
  label 'Underline Built-In Color'
49
55
  items Glimmer::LibUI.enum_symbols(:underline_color).map(&:to_s).map(&:capitalize)
@@ -59,6 +65,7 @@ class CustomDrawText
59
65
  end
60
66
  end
61
67
  }
68
+
62
69
  @underline_custom_color_button = color_button {
63
70
  label 'Underline Custom Color'
64
71
 
@@ -22,6 +22,7 @@ class CustomDrawText
22
22
  @area.queue_redraw_all
23
23
  end
24
24
  }
25
+
25
26
  color_button { |cb|
26
27
  label 'Color'
27
28
 
@@ -30,14 +31,18 @@ class CustomDrawText
30
31
  @area.queue_redraw_all
31
32
  end
32
33
  }
33
- color_button { |cb|
34
- label 'Background'
35
-
36
- on_changed do
37
- @background = cb.color
38
- @area.queue_redraw_all
39
- end
40
- }
34
+
35
+ unless OS.windows?
36
+ color_button { |cb|
37
+ label 'Background'
38
+
39
+ on_changed do
40
+ @background = cb.color
41
+ @area.queue_redraw_all
42
+ end
43
+ }
44
+ end
45
+
41
46
  combobox { |c|
42
47
  label 'Underline'
43
48
  items Glimmer::LibUI.enum_symbols(:underline).map(&:to_s).map {|word| word.split('_').map(&:capitalize).join(' ')}
@@ -48,6 +53,7 @@ class CustomDrawText
48
53
  @area.queue_redraw_all
49
54
  end
50
55
  }
56
+
51
57
  combobox { |c|
52
58
  label 'Underline Built-In Color'
53
59
  items Glimmer::LibUI.enum_symbols(:underline_color).map(&:to_s).map(&:capitalize)
@@ -64,6 +70,7 @@ class CustomDrawText
64
70
  @area.queue_redraw_all
65
71
  end
66
72
  }
73
+
67
74
  @underline_custom_color_button = color_button {
68
75
  label 'Underline Custom Color'
69
76
 
Binary file
@@ -41,6 +41,7 @@ module Glimmer
41
41
  shine_data_binding
42
42
  property
43
43
  string
44
+ operation
44
45
  control
45
46
  shape
46
47
  ]
@@ -0,0 +1,47 @@
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/dsl/expression'
23
+ require 'glimmer/libui/control_proxy'
24
+ require 'glimmer/libui/shape'
25
+ require 'glimmer/libui/attributed_string'
26
+
27
+ module Glimmer
28
+ module DSL
29
+ module Libui
30
+ class OperationExpression < Expression
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ (
33
+ parent.is_a?(Glimmer::LibUI::ControlProxy) or
34
+ parent.is_a?(Glimmer::LibUI::Shape) or
35
+ parent.is_a?(Glimmer::LibUI::AttributedString)
36
+ ) and
37
+ block.nil? and
38
+ parent.respond_to?(keyword, *args)
39
+ end
40
+
41
+ def interpret(parent, keyword, *args, &block)
42
+ parent.send(keyword, *args)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -35,11 +35,11 @@ module Glimmer
35
35
  parent.is_a?(Glimmer::LibUI::AttributedString)
36
36
  ) and
37
37
  block.nil? and
38
- parent.respond_to?(keyword, *args)
38
+ parent.respond_to?("#{keyword}=", *args)
39
39
  end
40
40
 
41
41
  def interpret(parent, keyword, *args, &block)
42
- parent.send(keyword, *args)
42
+ parent.send("#{keyword}=", *args)
43
43
  end
44
44
  end
45
45
  end
@@ -46,7 +46,6 @@ module Glimmer
46
46
  if return_value.is_a?(Numeric)
47
47
  return_value
48
48
  else
49
- destroy
50
49
  ControlProxy.main_window_proxy&.destroy
51
50
  ::LibUI.quit
52
51
  0
@@ -70,7 +70,8 @@ module Glimmer
70
70
  else
71
71
  new_color = Glimmer::LibUI.interpret_color(args)
72
72
  if new_color != @fill
73
- @fill_observer&.unobserve(@fill) if @fill
73
+ # TODO consider replacing unobserve with observer_registration.deregister
74
+ @fill_observer&.unobserve(@fill, attribute_writer_type: [:attribute=, :set_attribute]) if @fill
74
75
  @fill = new_color
75
76
  request_auto_redraw
76
77
  end
@@ -79,7 +80,7 @@ module Glimmer
79
80
  @fill_observer ||= Glimmer::DataBinding::Observer.proc do
80
81
  request_auto_redraw
81
82
  end
82
- @fill_observer.observe(@fill)
83
+ @fill_observer.observe(@fill, attribute_writer_type: [:attribute=, :set_attribute])
83
84
  end
84
85
  end
85
86
  alias fill= fill
@@ -98,7 +99,8 @@ module Glimmer
98
99
  else
99
100
  new_color = Glimmer::LibUI.interpret_color(args)
100
101
  if new_color != @stroke
101
- @stroke_observer&.unobserve(@stroke) if @stroke
102
+ # TODO consider replacing unobserve with observer_registration.deregister
103
+ @stroke_observer&.unobserve(@stroke, attribute_writer_type: [:attribute=, :set_attribute]) if @stroke
102
104
  @stroke = Glimmer::LibUI.interpret_color(args)
103
105
  request_auto_redraw
104
106
  end
@@ -107,7 +109,7 @@ module Glimmer
107
109
  @stroke_observer ||= Glimmer::DataBinding::Observer.proc do
108
110
  request_auto_redraw
109
111
  end
110
- @stroke_observer.observe(@stroke)
112
+ @stroke_observer.observe(@stroke, attribute_writer_type: [:attribute=, :set_attribute])
111
113
  end
112
114
  end
113
115
  alias stroke= stroke
@@ -48,6 +48,8 @@ module Glimmer
48
48
  @enabled = true
49
49
  @columns = []
50
50
  @cell_rows = []
51
+ @last_cell_rows = []
52
+ register_cell_rows_observer
51
53
  window_proxy.on_destroy do
52
54
  # the following unless condition is an exceptional condition stumbled upon that fails freeing the table model
53
55
  ::LibUI.free_table_model(@model) unless @destroyed && parent_proxy.is_a?(Box)
@@ -75,7 +77,8 @@ module Glimmer
75
77
 
76
78
  def destroy
77
79
  super
78
- @cell_rows_observer&.unobserve(self, :cell_rows, recursive: true)
80
+ # TODO consider replacing unobserve with observer_registration.deregister
81
+ @cell_rows_observer&.unobserve(self, :cell_rows, recursive: true, ignore_frozen: true, attribute_writer_type: [:attribute=, :set_attribute])
79
82
  @destroyed = true
80
83
  end
81
84
 
@@ -86,31 +89,6 @@ module Glimmer
86
89
  if rows != @cell_rows
87
90
  @cell_rows = rows
88
91
  @cell_rows = @cell_rows.to_a if @cell_rows.is_a?(Enumerator)
89
- @last_cell_rows ||= array_deep_clone(@cell_rows)
90
- @cell_rows_observer ||= Glimmer::DataBinding::Observer.proc do |new_cell_rows|
91
- if @cell_rows.size < @last_cell_rows.size && @last_cell_rows.include_all?(*@cell_rows)
92
- @last_cell_rows.array_diff_indexes(@cell_rows).reverse.each do |row|
93
- ::LibUI.table_model_row_deleted(model, row) if model && row
94
- notify_custom_listeners('on_changed', row, :deleted, @last_cell_rows[row])
95
- end
96
- elsif @cell_rows.size > @last_cell_rows.size && @cell_rows.include_all?(*@last_cell_rows)
97
- @cell_rows.array_diff_indexes(@last_cell_rows).each do |row|
98
- ::LibUI.table_model_row_inserted(model, row) if model && row
99
- notify_custom_listeners('on_changed', row, :inserted, @cell_rows[row])
100
- end
101
- else
102
- @cell_rows.each_with_index do |new_row_data, row|
103
- if new_row_data != @last_cell_rows[row]
104
- ::LibUI.table_model_row_changed(model, row) if model && row
105
- notify_custom_listeners('on_changed', row, :changed, @cell_rows[row])
106
- end
107
- end
108
- end
109
- @last_last_cell_rows = array_deep_clone(@last_cell_rows)
110
- @last_cell_rows = array_deep_clone(@cell_rows)
111
- end.tap do |cell_rows_observer|
112
- cell_rows_observer.observe(self, :cell_rows, recursive: true, ignore_frozen: true)
113
- end
114
92
  end
115
93
  @cell_rows
116
94
  end
@@ -153,13 +131,13 @@ module Glimmer
153
131
  new_value = new_value.to_a if new_value.is_a?(Enumerator)
154
132
  if model_binding.binding_options[:column_attributes] || (!new_value.empty? && !new_value.first.is_a?(Array))
155
133
  @model_attribute_array_observer_registration&.deregister
156
- @model_attribute_array_observer_registration = model_attribute_observer.observe(new_value, @column_attributes, ignore_frozen: true)
134
+ @model_attribute_array_observer_registration = model_attribute_observer.observe(new_value, @column_attributes, ignore_frozen: true, attribute_writer_type: [:attribute=, :set_attribute])
157
135
  model_attribute_observer.add_dependent(model_attribute_observer_registration => @model_attribute_array_observer_registration)
158
136
  end
159
137
  # TODO look if multiple notifications are happening as a result of observing array and observing model binding
160
138
  send("#{property}=", new_value) unless @last_cell_rows == new_value
161
139
  end
162
- model_attribute_observer_registration = model_attribute_observer.observe(model_binding)
140
+ model_attribute_observer_registration = model_attribute_observer.observe(model_binding, attribute_writer_type: [:attribute=, :set_attribute])
163
141
  model_attribute_observer.call # initial update
164
142
  data_binding_model_attribute_observer_registrations << model_attribute_observer_registration
165
143
  model_attribute_observer
@@ -313,11 +291,7 @@ module Glimmer
313
291
 
314
292
  if !@applied_windows_fix && OS.windows?
315
293
  @applied_windows_fix = true
316
- new_row = @columns&.select {|column| column.is_a?(Column)}&.map {|column| column.class.default_value}
317
- if new_row
318
- @cell_rows << new_row
319
- @cell_rows.pop
320
- end
294
+ apply_windows_fix
321
295
  end
322
296
  end
323
297
 
@@ -325,6 +299,46 @@ module Glimmer
325
299
  @next_column_index ||= -1
326
300
  @next_column_index += 1
327
301
  end
302
+
303
+ def register_cell_rows_observer
304
+ @cell_rows_observer = Glimmer::DataBinding::Observer.proc do |new_cell_rows|
305
+ if @cell_rows.size < @last_cell_rows.size && @last_cell_rows.include_all?(*@cell_rows)
306
+ @last_cell_rows.array_diff_indexes(@cell_rows).reverse.each do |row|
307
+ ::LibUI.table_model_row_deleted(model, row) if model && row
308
+ notify_custom_listeners('on_changed', row, :deleted, @last_cell_rows[row])
309
+ end
310
+ elsif @cell_rows.size > @last_cell_rows.size && @cell_rows.include_all?(*@last_cell_rows)
311
+ @cell_rows.array_diff_indexes(@last_cell_rows).each do |row|
312
+ ::LibUI.table_model_row_inserted(model, row) if model && row
313
+ notify_custom_listeners('on_changed', row, :inserted, @cell_rows[row])
314
+ end
315
+ else
316
+ @cell_rows.each_with_index do |new_row_data, row|
317
+ if new_row_data != @last_cell_rows[row]
318
+ ::LibUI.table_model_row_changed(model, row) if model && row
319
+ notify_custom_listeners('on_changed', row, :changed, @cell_rows[row])
320
+ end
321
+ end
322
+ end
323
+ @last_last_cell_rows = array_deep_clone(@last_cell_rows)
324
+ @last_cell_rows = array_deep_clone(@cell_rows)
325
+ if !@applied_windows_fix_on_first_cell_rows_update && OS.windows?
326
+ @applied_windows_fix_on_first_cell_rows_update = true
327
+ apply_windows_fix
328
+ end
329
+ end
330
+ @cell_rows_observer_registration = @cell_rows_observer.observe(self, :cell_rows, recursive: true, ignore_frozen: true, attribute_writer_type: [:attribute=, :set_attribute])
331
+ end
332
+
333
+ def apply_windows_fix
334
+ Glimmer::LibUI.queue_main do
335
+ new_row = @columns&.select {|column| column.is_a?(Column)}&.map {|column| column.class.default_value}
336
+ if new_row
337
+ @cell_rows << new_row
338
+ @cell_rows.pop
339
+ end
340
+ end
341
+ end
328
342
  end
329
343
  end
330
344
  end
@@ -46,7 +46,7 @@ module Glimmer
46
46
  new_value = model_binding.evaluate_property
47
47
  send("#{property}=", new_value) unless send(property) == new_value
48
48
  end
49
- observer_registration = model_attribute_observer.observe(model_binding)
49
+ observer_registration = model_attribute_observer.observe(model_binding, attribute_writer_type: [:attribute=, :set_attribute])
50
50
  model_attribute_observer.call # initial update
51
51
  data_binding_model_attribute_observer_registrations << observer_registration
52
52
  observer_registration
@@ -50,5 +50,5 @@ end
50
50
  # begin
51
51
  # PutsDebuggerer.printer = lambda { |m| puts m; $stdout.flush}
52
52
  # rescue
53
- ## No Op if puts_debuggerer is not loaded
53
+ ##### No Op if puts_debuggerer is not loaded
54
54
  # end
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.4.17
4
+ version: 0.4.18
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-12-07 00:00:00.000000000 Z
11
+ date: 2021-12-09 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.5.3
19
+ version: 2.5.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.5.3
26
+ version: 2.5.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: os
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -334,6 +334,7 @@ files:
334
334
  - lib/glimmer/dsl/libui/listener_expression.rb
335
335
  - lib/glimmer/dsl/libui/observe_expression.rb
336
336
  - lib/glimmer/dsl/libui/open_file_expression.rb
337
+ - lib/glimmer/dsl/libui/operation_expression.rb
337
338
  - lib/glimmer/dsl/libui/property_expression.rb
338
339
  - lib/glimmer/dsl/libui/save_file_expression.rb
339
340
  - lib/glimmer/dsl/libui/shape_expression.rb