glimmer-dsl-libui 0.4.5 → 0.4.9
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 +4 -4
- data/CHANGELOG.md +33 -0
- data/README.md +388 -57
- data/VERSION +1 -1
- data/examples/button_counter.rb +2 -1
- data/examples/color_button.rb +18 -13
- data/examples/color_button2.rb +14 -0
- data/examples/date_time_picker.rb +19 -14
- data/examples/date_time_picker2.rb +20 -0
- data/examples/font_button.rb +17 -12
- data/examples/font_button2.rb +18 -0
- data/examples/histogram.rb +1 -6
- data/examples/meta_example.rb +17 -6
- data/examples/midi_player.rb +5 -6
- data/examples/midi_player2.rb +83 -0
- data/examples/midi_player3.rb +84 -0
- data/examples/snake.rb +19 -10
- data/examples/tetris.rb +15 -18
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/libui/control_proxy/checkbox_proxy.rb +4 -0
- data/lib/glimmer/libui/control_proxy/color_button_proxy.rb +4 -0
- data/lib/glimmer/libui/control_proxy/combobox_proxy.rb +17 -2
- data/lib/glimmer/libui/control_proxy/date_time_picker_proxy.rb +4 -0
- data/lib/glimmer/libui/control_proxy/editable_combobox_proxy.rb +4 -0
- data/lib/glimmer/libui/control_proxy/entry_proxy.rb +1 -2
- data/lib/glimmer/libui/control_proxy/font_button_proxy.rb +8 -0
- data/lib/glimmer/libui/control_proxy/menu_item_proxy/check_menu_item_proxy.rb +4 -0
- data/lib/glimmer/libui/control_proxy/menu_item_proxy/radio_menu_item_proxy.rb +16 -4
- data/lib/glimmer/libui/control_proxy/multiline_entry_proxy.rb +1 -2
- data/lib/glimmer/libui/control_proxy/radio_buttons_proxy.rb +19 -0
- data/lib/glimmer/libui/control_proxy/slider_proxy.rb +37 -0
- data/lib/glimmer/libui/control_proxy/spinbox_proxy.rb +1 -2
- data/lib/glimmer/libui/control_proxy.rb +2 -2
- data/lib/glimmer/libui/data_bindable.rb +27 -2
- metadata +8 -2
@@ -39,6 +39,25 @@ module Glimmer
|
|
39
39
|
end
|
40
40
|
alias set_items items
|
41
41
|
alias items= items
|
42
|
+
|
43
|
+
def selected_item(value = nil)
|
44
|
+
if value.nil?
|
45
|
+
items[selected]
|
46
|
+
else
|
47
|
+
self.selected = items.index(value) || -1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
alias set_selected_item selected_item
|
51
|
+
alias selected_item= selected_item
|
52
|
+
|
53
|
+
def data_bind_write(property, model_binding)
|
54
|
+
case property
|
55
|
+
when 'selected'
|
56
|
+
handle_listener('on_selected') { model_binding.call(selected) }
|
57
|
+
when 'selected_item'
|
58
|
+
handle_listener('on_selected') { model_binding.call(selected_item) }
|
59
|
+
end
|
60
|
+
end
|
42
61
|
end
|
43
62
|
end
|
44
63
|
end
|
@@ -0,0 +1,37 @@
|
|
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
|
+
|
24
|
+
module Glimmer
|
25
|
+
module LibUI
|
26
|
+
class ControlProxy
|
27
|
+
# Proxy for LibUI slider objects
|
28
|
+
#
|
29
|
+
# Follows the Proxy Design Pattern
|
30
|
+
class SliderProxy < ControlProxy
|
31
|
+
def data_bind_write(property, model_binding)
|
32
|
+
handle_listener('on_changed') { model_binding.call(value) } if property == 'value'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -28,8 +28,7 @@ module Glimmer
|
|
28
28
|
#
|
29
29
|
# Follows the Proxy Design Pattern
|
30
30
|
class SpinboxProxy < ControlProxy
|
31
|
-
def
|
32
|
-
super
|
31
|
+
def data_bind_write(property, model_binding)
|
33
32
|
handle_listener('on_changed') { model_binding.call(value) } if property == 'value'
|
34
33
|
end
|
35
34
|
end
|
@@ -245,8 +245,8 @@ module Glimmer
|
|
245
245
|
args[0] = Glimmer::LibUI.boolean_to_integer(args.first) if BOOLEAN_PROPERTIES.include?(property) && (args.first.is_a?(TrueClass) || args.first.is_a?(FalseClass))
|
246
246
|
args[0] = '' if STRING_PROPERTIES.include?(property) && args.first == nil
|
247
247
|
if property.to_s == 'checked'
|
248
|
-
current_value = Glimmer::LibUI.integer_to_boolean(::LibUI.send("#{libui_api_keyword}_checked", @libui))
|
249
|
-
new_value = Glimmer::LibUI.integer_to_boolean(args[0])
|
248
|
+
current_value = Glimmer::LibUI.integer_to_boolean(::LibUI.send("#{libui_api_keyword}_checked", @libui), allow_nil: false)
|
249
|
+
new_value = Glimmer::LibUI.integer_to_boolean(args[0], allow_nil: false)
|
250
250
|
::LibUI.send("#{libui_api_keyword}_set_#{property}", @libui, *args) if new_value != current_value
|
251
251
|
else
|
252
252
|
::LibUI.send("#{libui_api_keyword}_set_#{property}", @libui, *args)
|
@@ -23,9 +23,25 @@ module Glimmer
|
|
23
23
|
module LibUI
|
24
24
|
# Parent controls and shapes who have children and add child post_initialize_child
|
25
25
|
module DataBindable
|
26
|
-
#
|
27
|
-
#
|
26
|
+
# Sets up read/write (bidirectional) data-binding
|
27
|
+
#
|
28
|
+
# classes are expected to implement `data_bind_write(property, model_binding)` to setup write data-binding
|
29
|
+
# by observing view property for changes and writing to model attribute via model binding accordingly
|
30
|
+
#
|
31
|
+
# classes can override data_bind_read to disable read data-binding in rare scenarios that might need it
|
32
|
+
#
|
33
|
+
# returns model attribute reading observer by default
|
28
34
|
def data_bind(property, model_binding)
|
35
|
+
data_bind_read(property, model_binding).tap do
|
36
|
+
data_bind_write(property, model_binding) unless model_binding.binding_options[:read_only]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Sets up read data-binding (reading from model to update view)
|
41
|
+
#
|
42
|
+
# Default implementation observes model attribute for changes via model binding
|
43
|
+
# and updates view property accordingly
|
44
|
+
def data_bind_read(property, model_binding)
|
29
45
|
model_attribute_observer = Glimmer::DataBinding::Observer.proc do
|
30
46
|
new_value = model_binding.evaluate_property
|
31
47
|
send("#{property}=", new_value) unless send(property) == new_value
|
@@ -34,6 +50,15 @@ module Glimmer
|
|
34
50
|
model_attribute_observer.call # initial update
|
35
51
|
model_attribute_observer
|
36
52
|
end
|
53
|
+
|
54
|
+
# Sets up write data-binding (writing to model from view)
|
55
|
+
#
|
56
|
+
# Has no implementation by default. Classes are expected
|
57
|
+
# to implement this method by observing view property
|
58
|
+
# for changes and writing them to model accordingly via model binding
|
59
|
+
def data_bind_write(property, model_binding)
|
60
|
+
# No Op by default
|
61
|
+
end
|
37
62
|
end
|
38
63
|
end
|
39
64
|
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.
|
4
|
+
version: 0.4.9
|
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-
|
11
|
+
date: 2021-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -247,11 +247,13 @@ files:
|
|
247
247
|
- examples/basic_window2.rb
|
248
248
|
- examples/button_counter.rb
|
249
249
|
- examples/color_button.rb
|
250
|
+
- examples/color_button2.rb
|
250
251
|
- examples/color_the_circles.rb
|
251
252
|
- examples/control_gallery.rb
|
252
253
|
- examples/custom_draw_text.rb
|
253
254
|
- examples/custom_draw_text2.rb
|
254
255
|
- examples/date_time_picker.rb
|
256
|
+
- examples/date_time_picker2.rb
|
255
257
|
- examples/dynamic_area.rb
|
256
258
|
- examples/dynamic_area2.rb
|
257
259
|
- examples/dynamic_area3.rb
|
@@ -259,6 +261,7 @@ files:
|
|
259
261
|
- examples/editable_column_table.rb
|
260
262
|
- examples/editable_table.rb
|
261
263
|
- examples/font_button.rb
|
264
|
+
- examples/font_button2.rb
|
262
265
|
- examples/form.rb
|
263
266
|
- examples/form2.rb
|
264
267
|
- examples/form_table.rb
|
@@ -275,6 +278,8 @@ files:
|
|
275
278
|
- examples/method_based_custom_keyword.rb
|
276
279
|
- examples/method_based_custom_keyword2.rb
|
277
280
|
- examples/midi_player.rb
|
281
|
+
- examples/midi_player2.rb
|
282
|
+
- examples/midi_player3.rb
|
278
283
|
- examples/simple_notepad.rb
|
279
284
|
- examples/snake.rb
|
280
285
|
- examples/snake/model/apple.rb
|
@@ -370,6 +375,7 @@ files:
|
|
370
375
|
- lib/glimmer/libui/control_proxy/open_type_tag_proxy.rb
|
371
376
|
- lib/glimmer/libui/control_proxy/path_proxy.rb
|
372
377
|
- lib/glimmer/libui/control_proxy/radio_buttons_proxy.rb
|
378
|
+
- lib/glimmer/libui/control_proxy/slider_proxy.rb
|
373
379
|
- lib/glimmer/libui/control_proxy/spinbox_proxy.rb
|
374
380
|
- lib/glimmer/libui/control_proxy/tab_item_proxy.rb
|
375
381
|
- lib/glimmer/libui/control_proxy/table_proxy.rb
|