glimmer-dsl-libui 0.0.2 → 0.0.6

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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/README.md +837 -27
  4. data/VERSION +1 -1
  5. data/examples/basic_entry.rb +1 -1
  6. data/examples/control_gallery.rb +184 -0
  7. data/examples/midi_player.rb +90 -0
  8. data/examples/simple_notepad.rb +15 -0
  9. data/glimmer-dsl-libui.gemspec +0 -0
  10. data/lib/glimmer/dsl/libui/control_expression.rb +1 -3
  11. data/lib/glimmer/dsl/libui/dsl.rb +1 -1
  12. data/lib/glimmer/dsl/libui/file_expression.rb +33 -0
  13. data/lib/glimmer/dsl/libui/open_file_expression.rb +33 -0
  14. data/lib/glimmer/dsl/libui/save_file_expression.rb +33 -0
  15. data/lib/glimmer/dsl/libui/tab_item_expression.rb +35 -0
  16. data/lib/glimmer/libui/about_menu_item_proxy.rb +37 -0
  17. data/lib/glimmer/libui/box.rb +4 -0
  18. data/lib/glimmer/libui/check_menu_item_proxy.rb +37 -0
  19. data/lib/glimmer/libui/combobox_proxy.rb +43 -0
  20. data/lib/glimmer/libui/control_proxy.rb +75 -22
  21. data/lib/glimmer/libui/editable_combobox_proxy.rb +43 -0
  22. data/lib/glimmer/libui/group_proxy.rb +35 -0
  23. data/lib/glimmer/libui/horizontal_box_proxy.rb +1 -1
  24. data/lib/glimmer/libui/menu_item_proxy.rb +41 -0
  25. data/lib/glimmer/libui/multiline_entry_proxy.rb +35 -0
  26. data/lib/glimmer/libui/non_wrapping_multiline_entry_proxy.rb +32 -0
  27. data/lib/glimmer/libui/preferences_menu_item_proxy.rb +37 -0
  28. data/lib/glimmer/libui/quit_menu_item_proxy.rb +62 -0
  29. data/lib/glimmer/libui/radio_buttons_proxy.rb +43 -0
  30. data/lib/glimmer/libui/separator_menu_item_proxy.rb +37 -0
  31. data/lib/glimmer/libui/tab_item_proxy.rb +66 -0
  32. data/lib/glimmer/libui/vertical_box_proxy.rb +1 -1
  33. data/lib/glimmer/libui/window_proxy.rb +3 -3
  34. data/lib/glimmer-dsl-libui.rb +2 -0
  35. metadata +25 -5
@@ -21,17 +21,19 @@
21
21
 
22
22
  module Glimmer
23
23
  module LibUI
24
- # Proxy for LibUI Control objects
24
+ # Proxy for LibUI control objects
25
25
  #
26
26
  # Follows the Proxy Design Pattern
27
27
  class ControlProxy
28
28
  class << self
29
29
  def control_exists?(keyword)
30
- ::LibUI.respond_to?("new_#{keyword}") || ::LibUI.respond_to?(keyword)
30
+ ::LibUI.respond_to?("new_#{keyword}") ||
31
+ ::LibUI.respond_to?(keyword) ||
32
+ Glimmer::LibUI.constants.include?("#{keyword.camelcase(:upper)}Proxy".to_sym)
31
33
  end
32
34
 
33
35
  def create(keyword, parent, args, &block)
34
- widget_proxy_class(keyword).new(keyword, parent, args, &block)
36
+ widget_proxy_class(keyword).new(keyword, parent, args, &block).tap {|c| all_controls << c}
35
37
  end
36
38
 
37
39
  def widget_proxy_class(keyword)
@@ -42,6 +44,12 @@ module Glimmer
42
44
  Glimmer::LibUI::ControlProxy
43
45
  end
44
46
  end
47
+
48
+ # autosave all controls in this array to avoid garbage collection
49
+ def all_controls
50
+ @@all_controls = [] unless defined?(@@all_controls)
51
+ @@all_controls
52
+ end
45
53
  end
46
54
 
47
55
  # libui returns the contained LibUI object
@@ -52,6 +60,7 @@ module Glimmer
52
60
  @parent_proxy = parent
53
61
  @args = args
54
62
  @block = block
63
+ @enabled = 1
55
64
  build_control
56
65
  if @parent_proxy.class.constants.include?(:APPEND_PROPERTIES)
57
66
  @parent_proxy.class::APPEND_PROPERTIES
@@ -70,28 +79,30 @@ module Glimmer
70
79
  end
71
80
 
72
81
  def can_handle_listener?(listener_name)
73
- ::LibUI.respond_to?("control_#{listener_name}") || ::LibUI.respond_to?("#{@keyword}_#{listener_name}")
82
+ ::LibUI.respond_to?("#{libui_api_keyword}_#{listener_name}") ||
83
+ ::LibUI.respond_to?("control_#{listener_name}")
74
84
  end
75
85
 
76
86
  def handle_listener(listener_name, &listener)
77
- if ::LibUI.respond_to?("control_#{listener_name}")
78
- ::LibUI.send("control_#{listener_name}", @libui, &listener)
79
- elsif ::LibUI.respond_to?("#{@keyword}_#{listener_name}")
80
- ::LibUI.send("#{@keyword}_#{listener_name}", @libui, &listener)
87
+ safe_listener = Proc.new { listener.call(self) }
88
+ if ::LibUI.respond_to?("#{libui_api_keyword}_#{listener_name}")
89
+ ::LibUI.send("#{libui_api_keyword}_#{listener_name}", @libui, &safe_listener)
90
+ elsif ::LibUI.respond_to?("control_#{listener_name}")
91
+ ::LibUI.send("control_#{listener_name}", @libui, &safe_listener)
81
92
  end
82
93
  end
83
94
 
84
95
  def respond_to?(method_name, *args, &block)
85
96
  respond_to_libui?(method_name, *args, &block) ||
86
97
  (append_properties.include?(method_name.to_s) || append_properties.include?(method_name.to_s.sub(/=$/, ''))) ||
87
- super
98
+ super(method_name, true)
88
99
  end
89
100
 
90
101
  def respond_to_libui?(method_name, *args, &block)
91
102
  ::LibUI.respond_to?("control_#{method_name}") ||
92
- ::LibUI.respond_to?("#{@keyword}_#{method_name}") ||
93
- ::LibUI.respond_to?("#{@keyword}_set_#{method_name}") ||
94
- ::LibUI.respond_to?("#{@keyword}_set_#{method_name.to_s.sub(/=$/, '')}")
103
+ ::LibUI.respond_to?("#{libui_api_keyword}_#{method_name}") ||
104
+ ::LibUI.respond_to?("#{libui_api_keyword}_set_#{method_name}") ||
105
+ ::LibUI.respond_to?("#{libui_api_keyword}_set_#{method_name.to_s.sub(/=$/, '')}")
95
106
  end
96
107
 
97
108
  def method_missing(method_name, *args, &block)
@@ -105,16 +116,18 @@ module Glimmer
105
116
  end
106
117
 
107
118
  def send_to_libui(method_name, *args, &block)
108
- if ::LibUI.respond_to?("control_#{method_name}")
119
+ if ::LibUI.respond_to?("#{libui_api_keyword}_#{method_name}") && args.empty?
120
+ ::LibUI.send("#{libui_api_keyword}_#{method_name}", @libui, *args)
121
+ elsif ::LibUI.respond_to?("#{libui_api_keyword}_set_#{method_name}") && !args.empty?
122
+ ::LibUI.send("#{libui_api_keyword}_set_#{method_name}", @libui, *args)
123
+ elsif ::LibUI.respond_to?("#{libui_api_keyword}_set_#{method_name.to_s.sub(/=$/, '')}") && !args.empty?
124
+ ::LibUI.send("#{libui_api_keyword}_set_#{method_name.to_s.sub(/=$/, '')}", @libui, *args)
125
+ elsif ::LibUI.respond_to?("#{libui_api_keyword}_#{method_name}") && method_name.start_with?('set_') && !args.empty?
126
+ ::LibUI.send("#{libui_api_keyword}_#{method_name}", @libui, *args)
127
+ elsif ::LibUI.respond_to?("#{libui_api_keyword}_#{method_name}") && !args.empty?
128
+ ::LibUI.send("#{libui_api_keyword}_#{method_name}", @libui, *args)
129
+ elsif ::LibUI.respond_to?("control_#{method_name}")
109
130
  ::LibUI.send("control_#{method_name}", @libui, *args)
110
- elsif ::LibUI.respond_to?("#{@keyword}_#{method_name}") && args.empty?
111
- ::LibUI.send("#{@keyword}_#{method_name}", @libui, *args)
112
- elsif ::LibUI.respond_to?("#{@keyword}_set_#{method_name}") && !args.empty?
113
- ::LibUI.send("#{@keyword}_set_#{method_name}", @libui, *args)
114
- elsif ::LibUI.respond_to?("#{@keyword}_set_#{method_name.to_s.sub(/=$/, '')}") && !args.empty?
115
- ::LibUI.send("#{@keyword}_set_#{method_name.to_s.sub(/=$/, '')}", @libui, *args)
116
- elsif ::LibUI.respond_to?("#{@keyword}_#{method_name}") && method_name.start_with?('set_') && !args.empty?
117
- ::LibUI.send("#{@keyword}_#{method_name}", @libui, *args)
118
131
  end
119
132
  end
120
133
 
@@ -132,10 +145,50 @@ module Glimmer
132
145
  end
133
146
  end
134
147
 
148
+ def libui_api_keyword
149
+ @keyword
150
+ end
151
+
152
+ def enabled(value = nil)
153
+ if value.nil?
154
+ @enabled
155
+ elsif value != @enabled
156
+ if value == 1
157
+ send_to_libui('enable')
158
+ else
159
+ send_to_libui('disable')
160
+ end
161
+ end
162
+ end
163
+ alias enabled? enabled
164
+ alias set_enabled enabled
165
+ alias enabled= enabled
166
+
167
+ def visible(value = nil)
168
+ current_value = send_to_libui('visible')
169
+ if value.nil?
170
+ current_value
171
+ elsif value != current_value
172
+ if value == 1
173
+ send_to_libui('show')
174
+ else
175
+ send_to_libui('hide')
176
+ end
177
+ end
178
+ end
179
+ alias visible? visible
180
+ alias set_visible visible
181
+ alias visible= visible
182
+
183
+ def destroy
184
+ send_to_libui('destroy')
185
+ self.class.all_controls.delete(self)
186
+ end
187
+
135
188
  private
136
189
 
137
190
  def build_control
138
- @libui ||= if ::LibUI.respond_to?("new_#{keyword}")
191
+ @libui = if ::LibUI.respond_to?("new_#{keyword}")
139
192
  ::LibUI.send("new_#{@keyword}", *@args)
140
193
  elsif ::LibUI.respond_to?(keyword)
141
194
  @args[0] = @args.first.libui if @args.first.is_a?(ControlProxy)
@@ -0,0 +1,43 @@
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
+ # Proxy for LibUI editable combobox objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class EditableComboboxProxy < ControlProxy
30
+ def items(*values)
31
+ values = values.first if values.first.is_a?(Array)
32
+ if values.empty?
33
+ @values
34
+ else
35
+ @values = values
36
+ @values.each { |value| append value }
37
+ end
38
+ end
39
+ alias set_items items
40
+ alias items= items
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,35 @@
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
+ # Proxy for LibUI group objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class GroupProxy < ControlProxy
30
+ def post_initialize_child(child)
31
+ ::LibUI.group_set_child(@libui, child.libui)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -24,7 +24,7 @@ require 'glimmer/libui/box'
24
24
 
25
25
  module Glimmer
26
26
  module LibUI
27
- # Proxy for LibUI Window objects
27
+ # Proxy for LibUI horizontal box objects
28
28
  #
29
29
  # Follows the Proxy Design Pattern
30
30
  class HorizontalBoxProxy < ControlProxy
@@ -0,0 +1,41 @@
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
+ # Proxy for LibUI menu item objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class MenuItemProxy < ControlProxy
30
+ def libui_api_keyword
31
+ 'menu_item'
32
+ end
33
+
34
+ private
35
+
36
+ def build_control
37
+ @libui = @parent_proxy.append_item(*@args)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,35 @@
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
+ # Proxy for LibUI multiline entry objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class MultilineEntryProxy < ControlProxy
30
+ def libui_api_keyword
31
+ 'multiline_entry'
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
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/multiline_entry_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI non wrapping multiline entry objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class NonWrappingMultilineEntryProxy < MultilineEntryProxy
30
+ end
31
+ end
32
+ 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/menu_item_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI preferences menu item object
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class PreferencesMenuItemProxy < MenuItemProxy
30
+ private
31
+
32
+ def build_control
33
+ @libui = @parent_proxy.append_preferences_item(*@args)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,62 @@
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/menu_item_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI quit menu item object
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class QuitMenuItemProxy < MenuItemProxy
30
+ def can_handle_listener?(listener_name)
31
+ listener_name == 'on_clicked' || super
32
+ end
33
+
34
+ def handle_listener(listener_name, &listener)
35
+ if listener_name == 'on_clicked'
36
+ @default_behavior_listener = Proc.new do
37
+ return_value = listener.call(self)
38
+ if return_value.is_a?(Numeric)
39
+ return_value
40
+ else
41
+ destroy
42
+ ::LibUI.quit
43
+ 0
44
+ end
45
+ end
46
+ ::LibUI.on_should_quit(&@default_behavior_listener)
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def build_control
53
+ @libui = @parent_proxy.append_quit_item(*@args)
54
+ handle_listener('on_clicked') do
55
+ destroy
56
+ ::LibUI.quit
57
+ 0
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,43 @@
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
+ # Proxy for LibUI radio buttons objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class RadioButtonsProxy < ControlProxy
30
+ def items(*values)
31
+ values = values.first if values.first.is_a?(Array)
32
+ if values.empty?
33
+ @values
34
+ else
35
+ @values = values
36
+ @values.each { |value| append value }
37
+ end
38
+ end
39
+ alias set_items items
40
+ alias items= items
41
+ end
42
+ end
43
+ 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/menu_item_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI separator menu item object
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class SeparatorMenuItemProxy < MenuItemProxy
30
+ private
31
+
32
+ def build_control
33
+ @libui = @parent_proxy.append_separator(*@args)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,66 @@
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
+ require 'glimmer/libui/horizontal_box_proxy'
24
+
25
+ module Glimmer
26
+ module LibUI
27
+ # Proxy for LibUI tab item objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class TabItemProxy < ControlProxy
31
+ attr_reader :index
32
+
33
+ def initialize(keyword, parent, args, &block)
34
+ @keyword = keyword
35
+ @parent_proxy = parent
36
+ @args = args
37
+ @block = block
38
+ @enabled = 1
39
+ @index = @parent_proxy.num_pages
40
+ @content = @block&.call
41
+ build_control
42
+ end
43
+
44
+ def name
45
+ @args.first
46
+ end
47
+
48
+ def margined(value = nil)
49
+ if value.nil?
50
+ @parent_proxy.margined(@index)
51
+ else
52
+ @parent_proxy.margined(@index, value)
53
+ end
54
+ end
55
+ alias set_margined margined
56
+ alias margined= margined
57
+
58
+ private
59
+
60
+ def build_control
61
+ @content = HorizontalBoxProxy.new('horizontal_box', @libui, []) if @content.nil?
62
+ @libui = @parent_proxy.append(name, @content.libui)
63
+ end
64
+ end
65
+ end
66
+ end
@@ -24,7 +24,7 @@ require 'glimmer/libui/box'
24
24
 
25
25
  module Glimmer
26
26
  module LibUI
27
- # Proxy for LibUI Window objects
27
+ # Proxy for LibUI vertical box objects
28
28
  #
29
29
  # Follows the Proxy Design Pattern
30
30
  class VerticalBoxProxy < ControlProxy
@@ -23,7 +23,7 @@ require 'glimmer/libui/control_proxy'
23
23
 
24
24
  module Glimmer
25
25
  module LibUI
26
- # Proxy for LibUI Window objects
26
+ # Proxy for LibUI window objects
27
27
  #
28
28
  # Follows the Proxy Design Pattern
29
29
  class WindowProxy < ControlProxy
@@ -36,13 +36,14 @@ module Glimmer
36
36
  unless @shown_at_least_once
37
37
  @shown_at_least_once = true
38
38
  ::LibUI.main
39
+ ::LibUI.quit
39
40
  end
40
41
  end
41
42
 
42
43
  def handle_listener(listener_name, &listener)
43
44
  if listener_name == 'on_closing'
44
45
  default_behavior_listener = Proc.new do
45
- return_value = listener.call
46
+ return_value = listener.call(self)
46
47
  if return_value.is_a?(Numeric)
47
48
  return_value
48
49
  else
@@ -58,7 +59,6 @@ module Glimmer
58
59
  private
59
60
 
60
61
  def build_control
61
- ::LibUI.init
62
62
  super.tap do
63
63
  handle_listener('on_closing') do
64
64
  destroy
@@ -38,3 +38,5 @@ Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
38
38
  result = false
39
39
  result ||= method == 'load_iseq'
40
40
  end
41
+
42
+ ::LibUI.init