glimmer-dsl-libui 0.4.5 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -0
  3. data/README.md +388 -57
  4. data/VERSION +1 -1
  5. data/examples/button_counter.rb +2 -1
  6. data/examples/color_button.rb +18 -13
  7. data/examples/color_button2.rb +14 -0
  8. data/examples/date_time_picker.rb +19 -14
  9. data/examples/date_time_picker2.rb +20 -0
  10. data/examples/font_button.rb +17 -12
  11. data/examples/font_button2.rb +18 -0
  12. data/examples/histogram.rb +1 -6
  13. data/examples/meta_example.rb +17 -6
  14. data/examples/midi_player.rb +5 -6
  15. data/examples/midi_player2.rb +83 -0
  16. data/examples/midi_player3.rb +84 -0
  17. data/examples/snake.rb +19 -10
  18. data/examples/tetris.rb +15 -18
  19. data/glimmer-dsl-libui.gemspec +0 -0
  20. data/lib/glimmer/libui/control_proxy/checkbox_proxy.rb +4 -0
  21. data/lib/glimmer/libui/control_proxy/color_button_proxy.rb +4 -0
  22. data/lib/glimmer/libui/control_proxy/combobox_proxy.rb +17 -2
  23. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy.rb +4 -0
  24. data/lib/glimmer/libui/control_proxy/editable_combobox_proxy.rb +4 -0
  25. data/lib/glimmer/libui/control_proxy/entry_proxy.rb +1 -2
  26. data/lib/glimmer/libui/control_proxy/font_button_proxy.rb +8 -0
  27. data/lib/glimmer/libui/control_proxy/menu_item_proxy/check_menu_item_proxy.rb +4 -0
  28. data/lib/glimmer/libui/control_proxy/menu_item_proxy/radio_menu_item_proxy.rb +16 -4
  29. data/lib/glimmer/libui/control_proxy/multiline_entry_proxy.rb +1 -2
  30. data/lib/glimmer/libui/control_proxy/radio_buttons_proxy.rb +19 -0
  31. data/lib/glimmer/libui/control_proxy/slider_proxy.rb +37 -0
  32. data/lib/glimmer/libui/control_proxy/spinbox_proxy.rb +1 -2
  33. data/lib/glimmer/libui/control_proxy.rb +2 -2
  34. data/lib/glimmer/libui/data_bindable.rb +27 -2
  35. 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 data_bind(property, model_binding)
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
- # Data-binds model to update view.
27
- # Subclasses can override to do inverse data-binding by observing view control for property changes and updating model binding accordingly
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.5
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-29 00:00:00.000000000 Z
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