glimmer-dsl-libui 0.4.10 → 0.4.14

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -0
  3. data/README.md +1071 -219
  4. data/VERSION +1 -1
  5. data/examples/basic_image.rb +5 -3
  6. data/examples/basic_image2.rb +1 -3
  7. data/examples/basic_image3.rb +3 -3
  8. data/examples/basic_image4.rb +0 -3
  9. data/examples/basic_image5.rb +0 -2
  10. data/examples/basic_table_button.rb +54 -30
  11. data/examples/basic_table_button2.rb +34 -0
  12. data/examples/basic_table_color.rb +104 -26
  13. data/examples/basic_table_color2.rb +2 -14
  14. data/examples/basic_table_color3.rb +37 -0
  15. data/examples/basic_table_image.rb +1 -1
  16. data/examples/basic_table_image2.rb +2 -14
  17. data/examples/basic_table_image3.rb +44 -0
  18. data/examples/basic_table_image_text.rb +1 -2
  19. data/examples/basic_table_image_text2.rb +2 -13
  20. data/examples/basic_table_image_text3.rb +44 -0
  21. data/examples/cpu_percentage.rb +1 -1
  22. data/examples/editable_table.rb +1 -1
  23. data/examples/form_table.rb +21 -17
  24. data/examples/form_table2.rb +104 -85
  25. data/examples/form_table3.rb +113 -0
  26. data/examples/form_table4.rb +110 -0
  27. data/examples/form_table5.rb +94 -0
  28. data/examples/meta_example.rb +6 -4
  29. data/glimmer-dsl-libui.gemspec +0 -0
  30. data/lib/glimmer/dsl/libui/control_expression.rb +2 -1
  31. data/lib/glimmer/dsl/libui/shape_expression.rb +2 -2
  32. data/lib/glimmer/dsl/libui/string_expression.rb +2 -1
  33. data/lib/glimmer/libui/attributed_string.rb +3 -2
  34. data/lib/glimmer/libui/control_proxy/column/background_color_column_proxy.rb +4 -0
  35. data/lib/glimmer/libui/control_proxy/image_proxy.rb +90 -10
  36. data/lib/glimmer/libui/control_proxy/table_proxy.rb +95 -29
  37. data/lib/glimmer/libui/control_proxy.rb +4 -2
  38. data/lib/glimmer/libui/data_bindable.rb +8 -3
  39. data/lib/glimmer/libui/shape.rb +3 -2
  40. data/lib/glimmer/libui.rb +2 -2
  41. data/lib/glimmer-dsl-libui.rb +1 -0
  42. metadata +9 -2
@@ -30,8 +30,9 @@ module Glimmer
30
30
  class AttributedString
31
31
  include DataBindable
32
32
 
33
- attr_reader :keyword, :parent_proxy, :args
33
+ attr_reader :keyword, :parent_proxy, :args, :content_added
34
34
  attr_accessor :block
35
+ alias content_added? content_added
35
36
 
36
37
  def initialize(keyword, parent_proxy, args, &block)
37
38
  @keyword = keyword
@@ -205,7 +206,7 @@ module Glimmer
205
206
  end
206
207
 
207
208
  def content(&block)
208
- Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::StringExpression.new, @keyword, &block)
209
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::StringExpression.new, @keyword, {post_add_content: true}, &block)
209
210
  end
210
211
  end
211
212
  end
@@ -31,6 +31,10 @@ module Glimmer
31
31
  # Follows the Proxy Design Pattern
32
32
  class BackgroundColorColumnProxy < ControlProxy
33
33
  include Column
34
+
35
+ def name
36
+ 'Background Color'
37
+ end
34
38
  end
35
39
  end
36
40
  end
@@ -34,14 +34,31 @@ module Glimmer
34
34
  #
35
35
  # Follows the Proxy Design Pattern
36
36
  class ImageProxy < ControlProxy
37
+ class << self
38
+ # creates or returns existing instance for passed in arguments if parent is nil and block is nil
39
+ def create(keyword, parent, args, &block)
40
+ if parent.nil? && block.nil?
41
+ instances[args] ||= new(keyword, parent, args.dup, &block)
42
+ else
43
+ new(keyword, parent, args, &block)
44
+ end
45
+ end
46
+
47
+ def instances
48
+ @@instances = {} unless defined? @@instances
49
+ @@instances
50
+ end
51
+ end
52
+
37
53
  include Parent
38
54
  prepend Transformable
39
55
 
40
- attr_reader :data, :pixels, :shapes
56
+ attr_reader :data, :pixels, :shapes, :options
41
57
 
42
58
  def initialize(keyword, parent, args, &block)
43
59
  @keyword = keyword
44
60
  @parent_proxy = parent
61
+ @options = args.last.is_a?(Hash) ? args.pop : {}
45
62
  @args = args
46
63
  @block = block
47
64
  @enabled = true
@@ -76,11 +93,47 @@ module Glimmer
76
93
  alias file= file
77
94
  alias set_file file
78
95
 
96
+ def x(value = nil)
97
+ if value.nil?
98
+ @args.size > 3 ? @args[1] : (@options[:x] || 0)
99
+ else
100
+ if @args.size > 3
101
+ @args[1] = value
102
+ else
103
+ @options[:x] = value
104
+ end
105
+ if area_image? && @content_added
106
+ post_add_content
107
+ request_auto_redraw
108
+ end
109
+ end
110
+ end
111
+ alias x= x
112
+ alias set_x x
113
+
114
+ def y(value = nil)
115
+ if value.nil?
116
+ @args.size > 3 ? @args[2] : (@options[:y] || 0)
117
+ else
118
+ if @args.size > 3
119
+ @args[2] = value
120
+ else
121
+ @options[:y] = value
122
+ end
123
+ if area_image? && @content_added
124
+ post_add_content
125
+ request_auto_redraw
126
+ end
127
+ end
128
+ end
129
+ alias y= y
130
+ alias set_y y
131
+
79
132
  def width(value = nil)
80
133
  if value.nil?
81
- @args[1]
134
+ @args.size > 3 ? @args[3] : (@options[:width] || @args[1])
82
135
  else
83
- @args[1] = value
136
+ set_width_variable(value)
84
137
  if area_image? && @content_added
85
138
  post_add_content
86
139
  request_auto_redraw
@@ -92,9 +145,9 @@ module Glimmer
92
145
 
93
146
  def height(value = nil)
94
147
  if value.nil?
95
- @args[2]
148
+ @args.size > 3 ? @args[4] : (@options[:height] || @args[2])
96
149
  else
97
- @args[2] = value
150
+ set_height_variable(value)
98
151
  if area_image? && @content_added
99
152
  post_add_content
100
153
  request_auto_redraw
@@ -132,6 +185,26 @@ module Glimmer
132
185
 
133
186
  private
134
187
 
188
+ def set_width_variable(value)
189
+ if @args.size > 3
190
+ @args[3] = value
191
+ elsif @options[:width]
192
+ @options[:width] = value
193
+ else
194
+ @args[1] = value
195
+ end
196
+ end
197
+
198
+ def set_height_variable(value)
199
+ if @args.size > 3
200
+ @args[4] = value
201
+ elsif @options[:height]
202
+ @options[:height] = value
203
+ else
204
+ @args[2] = value
205
+ end
206
+ end
207
+
135
208
  def build_control
136
209
  unless area_image? # image object
137
210
  if file
@@ -164,10 +237,15 @@ module Glimmer
164
237
  canvas = ChunkyPNG::Canvas.from_io(f)
165
238
  f.close
166
239
  end
167
- canvas.resample_nearest_neighbor!(width, height) if width && height
240
+ original_width = canvas.width
241
+ original_height = canvas.height
242
+ require 'bigdecimal'
243
+ calculated_width = ((BigDecimal(height)/BigDecimal(original_height))*original_width).to_i if height && !width
244
+ calculated_height = ((BigDecimal(width)/BigDecimal(original_width))*original_height).to_i if width && !height
245
+ canvas.resample_nearest_neighbor!(calculated_width || width, calculated_height || height) if width || height
168
246
  @data = canvas.to_rgba_stream
169
- @args[1] = canvas.width
170
- @args[2] = canvas.height
247
+ set_width_variable(canvas.width) unless width
248
+ set_height_variable(canvas.height) unless height
171
249
  [@data, width, height]
172
250
  end
173
251
 
@@ -187,6 +265,8 @@ module Glimmer
187
265
  @shapes = []
188
266
  original_pixels = @pixels.dup
189
267
  indexed_original_pixels = Hash[original_pixels.each_with_index.to_a]
268
+ x_offset = x
269
+ y_offset = y
190
270
  @pixels.each do |pixel|
191
271
  index = indexed_original_pixels[pixel]
192
272
  @rectangle_start_x ||= pixel[:x]
@@ -195,9 +275,9 @@ module Glimmer
195
275
  @rectangle_width += 1
196
276
  else
197
277
  if pixel[:x] > 0 && pixel[:color] == original_pixels[index - 1][:color]
198
- @shapes << {x: @rectangle_start_x, y: pixel[:y], width: @rectangle_width, height: 1, color: pixel[:color]}
278
+ @shapes << {x: x_offset + @rectangle_start_x, y: y_offset + pixel[:y], width: @rectangle_width, height: 1, color: pixel[:color]}
199
279
  else
200
- @shapes << {x: pixel[:x], y: pixel[:y], width: 1, height: 1, color: pixel[:color]}
280
+ @shapes << {x: x_offset + pixel[:x], y: y_offset + pixel[:y], width: 1, height: 1, color: pixel[:color]}
201
281
  end
202
282
  @rectangle_width = 1
203
283
  @rectangle_start_x = pixel[:x] == width - 1 ? 0 : pixel[:x] + 1
@@ -38,7 +38,7 @@ module Glimmer
38
38
 
39
39
  LISTENERS = ['on_changed', 'on_edited']
40
40
 
41
- attr_reader :model_handler, :model, :table_params, :columns
41
+ attr_reader :model_handler, :model, :table_params, :columns, :column_attributes
42
42
 
43
43
  def initialize(keyword, parent, args, &block)
44
44
  @keyword = keyword
@@ -75,6 +75,7 @@ module Glimmer
75
75
 
76
76
  def destroy
77
77
  super
78
+ @cell_rows_observer&.unobserve(self, :cell_rows, recursive: true)
78
79
  @destroyed = true
79
80
  end
80
81
 
@@ -82,10 +83,11 @@ module Glimmer
82
83
  if rows.nil?
83
84
  @cell_rows
84
85
  else
85
- @cell_rows = rows
86
- @cell_rows.tap do
87
- @last_cell_rows = array_deep_clone(@cell_rows)
88
- Glimmer::DataBinding::Observer.proc do |new_cell_rows|
86
+ if rows != @cell_rows
87
+ @cell_rows = rows
88
+ @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|
89
91
  if @cell_rows.size < @last_cell_rows.size && @last_cell_rows.include_all?(*@cell_rows)
90
92
  @last_cell_rows.array_diff_indexes(@cell_rows).reverse.each do |row|
91
93
  ::LibUI.table_model_row_deleted(model, row)
@@ -106,8 +108,11 @@ module Glimmer
106
108
  end
107
109
  @last_last_cell_rows = array_deep_clone(@last_cell_rows)
108
110
  @last_cell_rows = array_deep_clone(@cell_rows)
109
- end.observe(self, :cell_rows, recursive: true)
111
+ end.tap do |cell_rows_observer|
112
+ cell_rows_observer.observe(self, :cell_rows, recursive: true)
113
+ end
110
114
  end
115
+ @cell_rows
111
116
  end
112
117
  end
113
118
  alias cell_rows= cell_rows
@@ -119,6 +124,7 @@ module Glimmer
119
124
 
120
125
  def expand(cell_rows)
121
126
  cell_rows.to_a.map do |row|
127
+ row = @column_attributes.map {|attribute| row.send(attribute) } if @column_attributes&.any? && !row.is_a?(Array)
122
128
  row.flatten(1)
123
129
  end
124
130
  end
@@ -134,6 +140,46 @@ module Glimmer
134
140
  alias set_editable editable
135
141
  alias editable? editable
136
142
 
143
+ def data_bind_read(property, model_binding)
144
+ if model_binding.binding_options[:column_attributes].is_a?(Array)
145
+ @column_attributes = model_binding.binding_options[:column_attributes]
146
+ else
147
+ column_attribute_mapping = model_binding.binding_options[:column_attributes].is_a?(Hash) ? model_binding.binding_options[:column_attributes] : {}
148
+ @column_attributes = columns.select {|column| column.is_a?(Column)}.map(&:name).map {|column_name| column_attribute_mapping[column_name] || column_name.underscore}
149
+ end
150
+ model_attribute_observer = model_attribute_observer_registration = nil
151
+ model_attribute_observer = Glimmer::DataBinding::Observer.proc do
152
+ new_value = model_binding.evaluate_property
153
+ new_value = new_value.to_a if new_value.is_a?(Enumerator)
154
+ if model_binding.binding_options[:column_attributes] || (!new_value.empty? && !new_value.first.is_a?(Array))
155
+ @model_attribute_array_observer_registration&.deregister
156
+ @model_attribute_array_observer_registration = model_attribute_observer.observe(new_value, @column_attributes)
157
+ model_attribute_observer.add_dependent(model_attribute_observer_registration => @model_attribute_array_observer_registration)
158
+ end
159
+ # TODO look if multiple notifications are happening as a result of observing array and observing model binding
160
+ send("#{property}=", new_value) unless @last_cell_rows == new_value
161
+ end
162
+ model_attribute_observer_registration = model_attribute_observer.observe(model_binding)
163
+ model_attribute_observer.call # initial update
164
+ data_binding_model_attribute_observer_registrations << model_attribute_observer_registration
165
+ model_attribute_observer
166
+ end
167
+
168
+ def data_bind_write(property, model_binding)
169
+ # TODO ensure writing is happening to models if rows are not arrays
170
+ handle_listener('on_edited') { model_binding.call(cell_rows) } if property == 'cell_rows'
171
+ end
172
+
173
+ def array_deep_clone(array_or_object)
174
+ if array_or_object.is_a?(Array)
175
+ array_or_object.map do |element|
176
+ array_deep_clone(element)
177
+ end
178
+ else
179
+ array_or_object.clone
180
+ end
181
+ end
182
+
137
183
  private
138
184
 
139
185
  def build_control
@@ -162,11 +208,13 @@ module Glimmer
162
208
  when Column::TextColumnProxy, Column::ButtonColumnProxy, Column::TextColorColumnProxy, :text
163
209
  ::LibUI.new_table_value_string((expanded_cell_rows[row] && expanded_cell_rows[row][column]).to_s)
164
210
  when Column::ImageColumnProxy, Column::ImageTextColumnProxy, Column::ImageTextColorColumnProxy
165
- if OS.windows? && row == cell_rows.count
166
- ::LibUI.new_table_value_image((expanded_cell_rows[row - 1] && (expanded_cell_rows[row - 1][column].respond_to?(:libui) ? expanded_cell_rows[row - 1][column].libui : expanded_cell_rows[row - 1][column])))
167
- else
168
- ::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])))
169
- end
211
+ # TODO refactor to eliminate redundancy and share similar code
212
+ row = row - 1 if OS.windows? && row == cell_rows.count
213
+ img = expanded_cell_rows[row][column]
214
+ img = ControlProxy::ImageProxy.create('image', nil, img) if img.is_a?(Array)
215
+ img = ControlProxy::ImageProxy.create('image', nil, [img]) if img.is_a?(String)
216
+ img = img.respond_to?(:libui) ? img.libui : img
217
+ ::LibUI.new_table_value_image(img)
170
218
  when Column::CheckboxColumnProxy, Column::CheckboxTextColumnProxy, Column::CheckboxTextColorColumnProxy
171
219
  ::LibUI.new_table_value_int(((expanded_cell_rows[row] && (expanded_cell_rows[row][column] == 1 || expanded_cell_rows[row][column].to_s.strip.downcase == 'true' ? 1 : 0))) || 0)
172
220
  when Column::ProgressBarColumnProxy
@@ -193,28 +241,56 @@ module Glimmer
193
241
  when Column::TextColumnProxy
194
242
  column = @columns[column].index
195
243
  @cell_rows[row] ||= []
196
- @cell_rows[row][column] = ::LibUI.table_value_string(val).to_s
244
+ if @cell_rows[row].is_a?(Array)
245
+ @cell_rows[row][column] = ::LibUI.table_value_string(val).to_s
246
+ else
247
+ attribute = @column_attributes[column]
248
+ @cell_rows[row].send("#{attribute}=", ::LibUI.table_value_string(val).to_s)
249
+ end
197
250
  when Column::TextColorColumnProxy
198
251
  column = @columns[column].index
199
252
  @cell_rows[row] ||= []
200
- @cell_rows[row][column] ||= []
201
- @cell_rows[row][column][0] = ::LibUI.table_value_string(val).to_s
253
+ if @cell_rows[row].is_a?(Array)
254
+ @cell_rows[row][column] ||= []
255
+ @cell_rows[row][column][0] = ::LibUI.table_value_string(val).to_s
256
+ else
257
+ attribute = @column_attributes[column]
258
+ @cell_rows[row].send("#{attribute}=", []) unless @cell_rows[row].send(attribute)
259
+ @cell_rows[row].send(attribute)[0] = ::LibUI.table_value_string(val).to_s
260
+ end
202
261
  when :text
203
262
  column = @columns[column - 1].index
204
263
  @cell_rows[row] ||= []
205
- @cell_rows[row][column] ||= []
206
- @cell_rows[row][column][1] = ::LibUI.table_value_string(val).to_s
264
+ if @cell_rows[row].is_a?(Array)
265
+ @cell_rows[row][column] ||= []
266
+ @cell_rows[row][column][1] = ::LibUI.table_value_string(val).to_s
267
+ else
268
+ attribute = @column_attributes[column]
269
+ @cell_rows[row].send("#{attribute}=", []) unless @cell_rows[row].send(attribute)
270
+ @cell_rows[row].send(attribute)[1] = ::LibUI.table_value_string(val).to_s
271
+ end
207
272
  when Column::ButtonColumnProxy
208
273
  @columns[column].notify_listeners(:on_clicked, row)
209
274
  when Column::CheckboxColumnProxy
210
275
  column = @columns[column].index
211
276
  @cell_rows[row] ||= []
212
- @cell_rows[row][column] = ::LibUI.table_value_int(val).to_i == 1
277
+ if @cell_rows[row].is_a?(Array)
278
+ @cell_rows[row][column] = ::LibUI.table_value_int(val).to_i == 1
279
+ else
280
+ attribute = @column_attributes[column]
281
+ @cell_rows[row].send("#{attribute}=", ::LibUI.table_value_int(val).to_i == 1)
282
+ end
213
283
  when Column::CheckboxTextColumnProxy
214
284
  column = @columns[column].index
215
285
  @cell_rows[row] ||= []
216
- @cell_rows[row][column] ||= []
217
- @cell_rows[row][column][0] = ::LibUI.table_value_int(val).to_i == 1
286
+ if @cell_rows[row].is_a?(Array)
287
+ @cell_rows[row][column] ||= []
288
+ @cell_rows[row][column][0] = ::LibUI.table_value_int(val).to_i == 1
289
+ else
290
+ attribute = @column_attributes[column]
291
+ @cell_rows[row].send("#{attribute}=", []) unless @cell_rows[row].send(attribute)
292
+ @cell_rows[row].send(attribute)[0] = ::LibUI.table_value_int(val).to_i == 1
293
+ end
218
294
  end
219
295
  on_edited.each {|listener| listener.call(row, @cell_rows[row])}
220
296
  end
@@ -238,16 +314,6 @@ module Glimmer
238
314
  @next_column_index ||= -1
239
315
  @next_column_index += 1
240
316
  end
241
-
242
- def array_deep_clone(array_or_object)
243
- if array_or_object.is_a?(Array)
244
- array_or_object.map do |element|
245
- array_deep_clone(element)
246
- end
247
- else
248
- array_or_object.clone
249
- end
250
- end
251
317
  end
252
318
  end
253
319
  end
@@ -126,7 +126,8 @@ module Glimmer
126
126
  ]
127
127
 
128
128
  # libui returns the contained LibUI object
129
- attr_reader :parent_proxy, :libui, :args, :keyword, :block
129
+ attr_reader :parent_proxy, :libui, :args, :keyword, :block, :content_added
130
+ alias content_added? content_added
130
131
 
131
132
  def initialize(keyword, parent, args, &block)
132
133
  @keyword = keyword
@@ -288,6 +289,7 @@ module Glimmer
288
289
  end
289
290
 
290
291
  def destroy
292
+ data_binding_model_attribute_observer_registrations.each(&:deregister)
291
293
  if parent_proxy.nil?
292
294
  default_destroy
293
295
  else
@@ -337,7 +339,7 @@ module Glimmer
337
339
  alias visible= visible
338
340
 
339
341
  def content(&block)
340
- Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::ControlExpression.new, @keyword, &block)
342
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::ControlExpression.new, @keyword, {post_add_content: @content_added}, &block)
341
343
  end
342
344
 
343
345
  private
@@ -30,7 +30,7 @@ module Glimmer
30
30
  #
31
31
  # classes can override data_bind_read to disable read data-binding in rare scenarios that might need it
32
32
  #
33
- # returns model attribute reading observer by default
33
+ # returns model attribute reading observer registration by default
34
34
  def data_bind(property, model_binding)
35
35
  data_bind_read(property, model_binding).tap do
36
36
  data_bind_write(property, model_binding) unless model_binding.binding_options[:read_only]
@@ -46,9 +46,10 @@ 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
- model_attribute_observer.observe(model_binding)
49
+ observer_registration = model_attribute_observer.observe(model_binding)
50
50
  model_attribute_observer.call # initial update
51
- model_attribute_observer
51
+ data_binding_model_attribute_observer_registrations << observer_registration
52
+ observer_registration
52
53
  end
53
54
 
54
55
  # Sets up write data-binding (writing to model from view)
@@ -59,6 +60,10 @@ module Glimmer
59
60
  def data_bind_write(property, model_binding)
60
61
  # No Op by default
61
62
  end
63
+
64
+ def data_binding_model_attribute_observer_registrations
65
+ @data_binding_model_attribute_observer_registrations ||= []
66
+ end
62
67
  end
63
68
  end
64
69
  end
@@ -67,7 +67,8 @@ module Glimmer
67
67
  include Parent
68
68
  include DataBindable
69
69
 
70
- attr_reader :parent, :args, :keyword, :block
70
+ attr_reader :parent, :args, :keyword, :block, :content_added
71
+ alias content_added? content_added
71
72
 
72
73
  def initialize(keyword, parent, args, &block)
73
74
  @keyword = keyword
@@ -97,7 +98,7 @@ module Glimmer
97
98
  end
98
99
 
99
100
  def content(&block)
100
- Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::ShapeExpression.new, @keyword, &block)
101
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::ShapeExpression.new, @keyword, {post_add_content: @content_added}, &block)
101
102
  request_auto_redraw
102
103
  end
103
104
 
data/lib/glimmer/libui.rb CHANGED
@@ -63,7 +63,7 @@ module Glimmer
63
63
  value[:b] = value.delete(:blue) if value[:blue]
64
64
  value[:a] = value.delete(:alpha) if value[:alpha]
65
65
  value
66
- elsif value.is_a?(String) && !value.start_with?('0x') && !value.downcase.match(/^((([1-9a-f]){6})|(([1-9a-f]){3}))$/)
66
+ elsif value.is_a?(String) && !value.start_with?('0x') && !value.start_with?('#') && !value.downcase.match(/^((([1-9a-f]){6})|(([1-9a-f]){3}))$/)
67
67
  color = Color::RGB.extract_colors(value).first
68
68
  color.nil? ? {} : {
69
69
  r: color.red,
@@ -79,11 +79,11 @@ module Glimmer
79
79
 
80
80
  def hex_to_rgb(value)
81
81
  if value.is_a?(String)
82
+ value = "0x#{value[1..-1]}" if value.start_with?('#')
82
83
  if !value.start_with?('0x')
83
84
  value = value.chars.map {|char| [char, char]}.flatten.join if value.length == 3
84
85
  value = "0x#{value}"
85
86
  end
86
- value = "0x#{value[1..-1]}" if value.start_with?('#')
87
87
  value = value.to_i(16)
88
88
  end
89
89
  if value.is_a?(Integer)
@@ -30,6 +30,7 @@ require 'color'
30
30
  require 'os'
31
31
  require 'array_include_methods'
32
32
  require 'facets/hash/stringify_keys'
33
+ require 'facets/string/underscore'
33
34
  require 'libui'
34
35
 
35
36
  # Internal requires
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.10
4
+ version: 0.4.14
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-01 00:00:00.000000000 Z
11
+ date: 2021-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -232,14 +232,18 @@ files:
232
232
  - examples/basic_scrolling_area.rb
233
233
  - examples/basic_table.rb
234
234
  - examples/basic_table_button.rb
235
+ - examples/basic_table_button2.rb
235
236
  - examples/basic_table_checkbox.rb
236
237
  - examples/basic_table_checkbox_text.rb
237
238
  - examples/basic_table_color.rb
238
239
  - examples/basic_table_color2.rb
240
+ - examples/basic_table_color3.rb
239
241
  - examples/basic_table_image.rb
240
242
  - examples/basic_table_image2.rb
243
+ - examples/basic_table_image3.rb
241
244
  - examples/basic_table_image_text.rb
242
245
  - examples/basic_table_image_text2.rb
246
+ - examples/basic_table_image_text3.rb
243
247
  - examples/basic_table_progress_bar.rb
244
248
  - examples/basic_transform.rb
245
249
  - examples/basic_transform2.rb
@@ -267,6 +271,9 @@ files:
267
271
  - examples/form2.rb
268
272
  - examples/form_table.rb
269
273
  - examples/form_table2.rb
274
+ - examples/form_table3.rb
275
+ - examples/form_table4.rb
276
+ - examples/form_table5.rb
270
277
  - examples/grid.rb
271
278
  - examples/histogram.rb
272
279
  - examples/histogram2.rb