glimmer-dsl-libui 0.4.9 → 0.4.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -0
- data/README.md +1330 -487
- data/VERSION +1 -1
- data/examples/basic_table_button.rb +54 -30
- data/examples/basic_table_button2.rb +34 -0
- data/examples/basic_table_color.rb +104 -26
- data/examples/basic_table_color2.rb +2 -14
- data/examples/basic_table_color3.rb +37 -0
- data/examples/basic_table_image.rb +1 -1
- data/examples/basic_table_image2.rb +2 -14
- data/examples/basic_table_image3.rb +44 -0
- data/examples/basic_table_image_text.rb +1 -2
- data/examples/basic_table_image_text2.rb +2 -13
- data/examples/basic_table_image_text3.rb +44 -0
- data/examples/cpu_percentage.rb +36 -0
- data/examples/editable_table.rb +1 -1
- data/examples/form_table.rb +21 -17
- data/examples/form_table2.rb +104 -85
- data/examples/form_table3.rb +113 -0
- data/examples/form_table4.rb +110 -0
- data/examples/form_table5.rb +94 -0
- data/examples/meta_example.rb +6 -4
- data/examples/snake2.rb +97 -0
- data/examples/tic_tac_toe.rb +1 -0
- data/examples/tic_tac_toe2.rb +84 -0
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/dsl/libui/control_expression.rb +2 -1
- data/lib/glimmer/dsl/libui/shape_expression.rb +2 -2
- data/lib/glimmer/dsl/libui/string_expression.rb +2 -1
- data/lib/glimmer/libui/attributed_string.rb +3 -2
- data/lib/glimmer/libui/control_proxy/column/background_color_column_proxy.rb +4 -0
- data/lib/glimmer/libui/control_proxy/image_proxy.rb +16 -0
- data/lib/glimmer/libui/control_proxy/table_proxy.rb +95 -29
- data/lib/glimmer/libui/control_proxy.rb +4 -2
- data/lib/glimmer/libui/data_bindable.rb +8 -3
- data/lib/glimmer/libui/shape.rb +3 -2
- data/lib/glimmer/libui.rb +2 -2
- data/lib/glimmer-dsl-libui.rb +1 -0
- metadata +12 -2
@@ -0,0 +1,84 @@
|
|
1
|
+
|
2
|
+
require 'glimmer-dsl-libui'
|
3
|
+
|
4
|
+
require_relative "tic_tac_toe/board"
|
5
|
+
|
6
|
+
class TicTacToe
|
7
|
+
include Glimmer
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@tic_tac_toe_board = Board.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def launch
|
14
|
+
create_gui
|
15
|
+
register_observers
|
16
|
+
@main_window.show
|
17
|
+
end
|
18
|
+
|
19
|
+
def register_observers
|
20
|
+
observe(@tic_tac_toe_board, :game_status) do |game_status|
|
21
|
+
display_win_message if game_status == Board::WIN
|
22
|
+
display_draw_message if game_status == Board::DRAW
|
23
|
+
end
|
24
|
+
|
25
|
+
3.times.map do |row|
|
26
|
+
3.times.map do |column|
|
27
|
+
observe(@tic_tac_toe_board[row + 1, column + 1], :sign) do |sign| # board model is 1-based
|
28
|
+
@cells[row][column].string = sign
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_gui
|
35
|
+
@main_window = window('Tic-Tac-Toe', 180, 180) {
|
36
|
+
resizable false
|
37
|
+
|
38
|
+
@cells = []
|
39
|
+
vertical_box {
|
40
|
+
padded false
|
41
|
+
|
42
|
+
3.times.map do |row|
|
43
|
+
@cells << []
|
44
|
+
horizontal_box {
|
45
|
+
padded false
|
46
|
+
|
47
|
+
3.times.map do |column|
|
48
|
+
area {
|
49
|
+
square(0, 0, 60) {
|
50
|
+
stroke :black, thickness: 2
|
51
|
+
}
|
52
|
+
text(23, 19) {
|
53
|
+
@cells[row] << string('') {
|
54
|
+
font family: 'Arial', size: OS.mac? ? 20 : 16
|
55
|
+
}
|
56
|
+
}
|
57
|
+
on_mouse_up do
|
58
|
+
@tic_tac_toe_board.mark(row + 1, column + 1) # board model is 1-based
|
59
|
+
end
|
60
|
+
}
|
61
|
+
end
|
62
|
+
}
|
63
|
+
end
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def display_win_message
|
69
|
+
display_game_over_message("Player #{@tic_tac_toe_board.winning_sign} has won!")
|
70
|
+
end
|
71
|
+
|
72
|
+
def display_draw_message
|
73
|
+
display_game_over_message("Draw!")
|
74
|
+
end
|
75
|
+
|
76
|
+
def display_game_over_message(message_text)
|
77
|
+
Glimmer::LibUI.queue_main do
|
78
|
+
msg_box('Game Over', message_text)
|
79
|
+
@tic_tac_toe_board.reset!
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
TicTacToe.new.launch
|
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
@@ -39,8 +39,9 @@ module Glimmer
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def add_content(parent, keyword, *args, &block)
|
42
|
+
options = args.last.is_a?(Hash) ? args.last : {post_add_content: true}
|
42
43
|
super
|
43
|
-
parent&.post_add_content
|
44
|
+
parent&.post_add_content if options[:post_add_content]
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
@@ -47,10 +47,10 @@ module Glimmer
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def add_content(parent, keyword, *args, &block)
|
50
|
+
options = args.last.is_a?(Hash) ? args.last : {post_add_content: true}
|
50
51
|
super
|
51
|
-
parent
|
52
|
+
parent&.post_add_content if options[:post_add_content]
|
52
53
|
end
|
53
|
-
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -46,7 +46,8 @@ module Glimmer
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def add_content(parent, keyword, *args, &block)
|
49
|
-
|
49
|
+
options = args.last.is_a?(Hash) ? args.last : {post_add_content: true}
|
50
|
+
parent&.post_add_content(block) if options[:post_add_content]
|
50
51
|
end
|
51
52
|
end
|
52
53
|
end
|
@@ -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
|
@@ -34,6 +34,22 @@ 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
|
|
@@ -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
|
86
|
-
|
87
|
-
@
|
88
|
-
|
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.
|
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
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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]
|
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]
|
201
|
-
|
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]
|
206
|
-
|
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]
|
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]
|
217
|
-
|
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
|
-
|
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
|
data/lib/glimmer/libui/shape.rb
CHANGED
@@ -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)
|
data/lib/glimmer-dsl-libui.rb
CHANGED
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.
|
4
|
+
version: 0.4.13
|
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-
|
11
|
+
date: 2021-12-03 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
|
@@ -250,6 +254,7 @@ files:
|
|
250
254
|
- examples/color_button2.rb
|
251
255
|
- examples/color_the_circles.rb
|
252
256
|
- examples/control_gallery.rb
|
257
|
+
- examples/cpu_percentage.rb
|
253
258
|
- examples/custom_draw_text.rb
|
254
259
|
- examples/custom_draw_text2.rb
|
255
260
|
- examples/date_time_picker.rb
|
@@ -266,6 +271,9 @@ files:
|
|
266
271
|
- examples/form2.rb
|
267
272
|
- examples/form_table.rb
|
268
273
|
- examples/form_table2.rb
|
274
|
+
- examples/form_table3.rb
|
275
|
+
- examples/form_table4.rb
|
276
|
+
- examples/form_table5.rb
|
269
277
|
- examples/grid.rb
|
270
278
|
- examples/histogram.rb
|
271
279
|
- examples/histogram2.rb
|
@@ -288,6 +296,7 @@ files:
|
|
288
296
|
- examples/snake/model/vertebra.rb
|
289
297
|
- examples/snake/presenter/cell.rb
|
290
298
|
- examples/snake/presenter/grid.rb
|
299
|
+
- examples/snake2.rb
|
291
300
|
- examples/tetris.rb
|
292
301
|
- examples/tetris/model/block.rb
|
293
302
|
- examples/tetris/model/game.rb
|
@@ -296,6 +305,7 @@ files:
|
|
296
305
|
- examples/tic_tac_toe.rb
|
297
306
|
- examples/tic_tac_toe/board.rb
|
298
307
|
- examples/tic_tac_toe/cell.rb
|
308
|
+
- examples/tic_tac_toe2.rb
|
299
309
|
- examples/timer.rb
|
300
310
|
- examples/timer2.rb
|
301
311
|
- glimmer-dsl-libui.gemspec
|