glimmer-dsl-libui 0.0.7 → 0.0.11
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 +28 -0
- data/README.md +324 -68
- data/VERSION +1 -1
- data/examples/basic_button.rb +1 -1
- data/examples/basic_entry.rb +3 -3
- data/examples/basic_window.rb +1 -1
- data/examples/basic_window2.rb +14 -0
- data/examples/color_button.rb +14 -0
- data/examples/control_gallery.rb +20 -20
- data/examples/font_button.rb +18 -0
- data/examples/meta_example.rb +57 -0
- data/examples/midi_player.rb +2 -2
- data/examples/simple_notepad.rb +1 -1
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/libui/box.rb +15 -3
- data/lib/glimmer/libui/color_button_proxy.rb +64 -0
- data/lib/glimmer/libui/control_proxy.rb +86 -25
- data/lib/glimmer/libui/date_picker_proxy.rb +32 -0
- data/lib/glimmer/libui/date_time_picker_proxy.rb +35 -0
- data/lib/glimmer/libui/font_button_proxy.rb +68 -0
- data/lib/glimmer/libui/group_proxy.rb +6 -1
- data/lib/glimmer/libui/tab_item_proxy.rb +1 -0
- data/lib/glimmer/libui/time_picker_proxy.rb +32 -0
- data/lib/glimmer/libui/window_proxy.rb +23 -2
- data/lib/glimmer-dsl-libui.rb +1 -0
- metadata +34 -5
data/examples/basic_entry.rb
CHANGED
@@ -4,10 +4,10 @@ require 'glimmer-dsl-libui'
|
|
4
4
|
|
5
5
|
include Glimmer
|
6
6
|
|
7
|
-
window('Basic Entry', 300, 50
|
7
|
+
window('Basic Entry', 300, 50) { |w|
|
8
8
|
horizontal_box {
|
9
9
|
e = entry {
|
10
|
-
# stretchy
|
10
|
+
# stretchy true # Smart default option for appending to horizontal_box
|
11
11
|
|
12
12
|
on_changed do
|
13
13
|
puts e.text
|
@@ -16,7 +16,7 @@ window('Basic Entry', 300, 50, 1) { |w|
|
|
16
16
|
}
|
17
17
|
|
18
18
|
button('Button') {
|
19
|
-
stretchy
|
19
|
+
stretchy false
|
20
20
|
|
21
21
|
on_clicked do
|
22
22
|
text = e.text
|
data/examples/basic_window.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
|
5
|
+
include Glimmer
|
6
|
+
|
7
|
+
window { # first 3 args can be set via properties with 4th arg has_menubar=true by default
|
8
|
+
title 'hello world'
|
9
|
+
content_size 300, 200
|
10
|
+
|
11
|
+
on_closing do
|
12
|
+
puts 'Bye Bye'
|
13
|
+
end
|
14
|
+
}.show
|
data/examples/control_gallery.rb
CHANGED
@@ -32,7 +32,7 @@ menu('Edit') {
|
|
32
32
|
check_menu_item('Checkable Item_')
|
33
33
|
separator_menu_item
|
34
34
|
menu_item('Disabled Item_') {
|
35
|
-
enabled
|
35
|
+
enabled false
|
36
36
|
}
|
37
37
|
}
|
38
38
|
|
@@ -42,8 +42,8 @@ menu('Help') {
|
|
42
42
|
about_menu_item # Can optionally contain an on_clicked listener
|
43
43
|
}
|
44
44
|
|
45
|
-
MAIN_WINDOW = window('Control Gallery', 600, 500
|
46
|
-
margined
|
45
|
+
MAIN_WINDOW = window('Control Gallery', 600, 500) {
|
46
|
+
margined true
|
47
47
|
|
48
48
|
on_closing do
|
49
49
|
puts 'Bye Bye'
|
@@ -54,7 +54,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
|
|
54
54
|
group('Basic Controls') {
|
55
55
|
vertical_box {
|
56
56
|
button('Button') {
|
57
|
-
stretchy
|
57
|
+
stretchy false
|
58
58
|
|
59
59
|
on_clicked do
|
60
60
|
msg_box(MAIN_WINDOW, 'Information', 'You clicked the button')
|
@@ -62,38 +62,38 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
|
|
62
62
|
}
|
63
63
|
|
64
64
|
checkbox('Checkbox') {
|
65
|
-
stretchy
|
65
|
+
stretchy false
|
66
66
|
|
67
67
|
on_toggled do |c|
|
68
|
-
checked = c.checked
|
68
|
+
checked = c.checked?
|
69
69
|
MAIN_WINDOW.title = "Checkbox is #{checked}"
|
70
70
|
c.text = "I am the checkbox (#{checked})"
|
71
71
|
end
|
72
72
|
}
|
73
73
|
|
74
|
-
label('Label') { stretchy
|
74
|
+
label('Label') { stretchy false }
|
75
75
|
|
76
|
-
horizontal_separator { stretchy
|
76
|
+
horizontal_separator { stretchy false }
|
77
77
|
|
78
|
-
date_picker { stretchy
|
78
|
+
date_picker { stretchy false }
|
79
79
|
|
80
|
-
time_picker { stretchy
|
80
|
+
time_picker { stretchy false }
|
81
81
|
|
82
|
-
date_time_picker { stretchy
|
82
|
+
date_time_picker { stretchy false }
|
83
83
|
|
84
|
-
font_button { stretchy
|
84
|
+
font_button { stretchy false }
|
85
85
|
|
86
|
-
color_button { stretchy
|
86
|
+
color_button { stretchy false }
|
87
87
|
}
|
88
88
|
}
|
89
89
|
|
90
90
|
vertical_box {
|
91
91
|
group('Numbers') {
|
92
|
-
stretchy
|
92
|
+
stretchy false
|
93
93
|
|
94
94
|
vertical_box {
|
95
95
|
spinbox(0, 100) {
|
96
|
-
stretchy
|
96
|
+
stretchy false
|
97
97
|
value 42
|
98
98
|
|
99
99
|
on_changed do |s|
|
@@ -102,7 +102,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
|
|
102
102
|
}
|
103
103
|
|
104
104
|
slider(0, 100) {
|
105
|
-
stretchy
|
105
|
+
stretchy false
|
106
106
|
|
107
107
|
on_changed do |s|
|
108
108
|
v = s.value
|
@@ -111,16 +111,16 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
|
|
111
111
|
end
|
112
112
|
}
|
113
113
|
|
114
|
-
@progress_bar = progress_bar { stretchy
|
114
|
+
@progress_bar = progress_bar { stretchy false }
|
115
115
|
}
|
116
116
|
}
|
117
117
|
|
118
118
|
group('Lists') {
|
119
|
-
stretchy
|
119
|
+
stretchy false
|
120
120
|
|
121
121
|
vertical_box {
|
122
122
|
combobox {
|
123
|
-
stretchy
|
123
|
+
stretchy false
|
124
124
|
items 'combobox Item 1', 'combobox Item 2', 'combobox Item 3' # also accepts a single array argument
|
125
125
|
|
126
126
|
on_selected do |c|
|
@@ -129,7 +129,7 @@ MAIN_WINDOW = window('Control Gallery', 600, 500, 1) {
|
|
129
129
|
}
|
130
130
|
|
131
131
|
editable_combobox {
|
132
|
-
stretchy
|
132
|
+
stretchy false
|
133
133
|
items 'Editable Item 1', 'Editable Item 2', 'Editable Item 3' # also accepts a single array argument
|
134
134
|
}
|
135
135
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
|
5
|
+
include Glimmer
|
6
|
+
|
7
|
+
window('hello world', 300, 200) {
|
8
|
+
font_button { |fb|
|
9
|
+
on_changed do
|
10
|
+
font_descriptor = fb.font
|
11
|
+
p font_descriptor
|
12
|
+
end
|
13
|
+
}
|
14
|
+
|
15
|
+
on_closing do
|
16
|
+
puts 'Bye Bye'
|
17
|
+
end
|
18
|
+
}.show
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
require 'facets'
|
5
|
+
|
6
|
+
class MetaExample
|
7
|
+
include Glimmer
|
8
|
+
|
9
|
+
def examples
|
10
|
+
if @examples.nil?
|
11
|
+
example_files = Dir.glob(File.join(File.expand_path('.', __dir__), '**', '*.rb'))
|
12
|
+
example_file_names = example_files.map { |f| File.basename(f, '.rb') }
|
13
|
+
example_file_names = example_file_names.reject { |f| f == 'meta_example' }
|
14
|
+
@examples = example_file_names.map { |f| f.underscore.titlecase }
|
15
|
+
end
|
16
|
+
@examples
|
17
|
+
end
|
18
|
+
|
19
|
+
def file_path_for(example)
|
20
|
+
File.join(File.expand_path('.', __dir__), "#{example.underscore}.rb")
|
21
|
+
end
|
22
|
+
|
23
|
+
def launch
|
24
|
+
window('Meta-Example', 700, 500) { |w|
|
25
|
+
margined true
|
26
|
+
|
27
|
+
horizontal_box {
|
28
|
+
vertical_box {
|
29
|
+
@rbs = radio_buttons {
|
30
|
+
stretchy false
|
31
|
+
items examples
|
32
|
+
selected 0
|
33
|
+
|
34
|
+
on_selected do
|
35
|
+
@nwme.text = File.read(file_path_for(@examples[@rbs.selected]))
|
36
|
+
end
|
37
|
+
}
|
38
|
+
button('Launch') {
|
39
|
+
stretchy false
|
40
|
+
|
41
|
+
on_clicked do
|
42
|
+
system "ruby -r puts_debuggerer -r #{File.expand_path('../lib/glimmer-dsl-libui', __dir__)} #{file_path_for(@examples[@rbs.selected])}"
|
43
|
+
end
|
44
|
+
}
|
45
|
+
}
|
46
|
+
vertical_box {
|
47
|
+
@nwme = non_wrapping_multiline_entry {
|
48
|
+
read_only true
|
49
|
+
text File.read(file_path_for(@examples[@rbs.selected]))
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}.show
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
MetaExample.new.launch
|
data/examples/midi_player.rb
CHANGED
@@ -56,10 +56,10 @@ class TinyMidiPlayer
|
|
56
56
|
end
|
57
57
|
}
|
58
58
|
}
|
59
|
-
@main_window = window('Tiny Midi Player', 200, 50
|
59
|
+
@main_window = window('Tiny Midi Player', 200, 50) {
|
60
60
|
horizontal_box {
|
61
61
|
vertical_box {
|
62
|
-
stretchy
|
62
|
+
stretchy false
|
63
63
|
|
64
64
|
button('▶') {
|
65
65
|
on_clicked do
|
data/examples/simple_notepad.rb
CHANGED
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
data/lib/glimmer/libui/box.rb
CHANGED
@@ -19,25 +19,37 @@
|
|
19
19
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
|
+
require 'glimmer/libui/control_proxy'
|
23
|
+
|
22
24
|
module Glimmer
|
23
25
|
module LibUI
|
24
26
|
module Box
|
25
27
|
APPEND_PROPERTIES = %w[stretchy]
|
26
28
|
|
27
29
|
def post_initialize_child(child)
|
28
|
-
child.stretchy =
|
29
|
-
::LibUI.box_append(@libui, child.libui, child.stretchy)
|
30
|
+
child.stretchy = true if child.stretchy.nil?
|
31
|
+
::LibUI.box_append(@libui, child.libui, ControlProxy.boolean_to_integer(child.stretchy))
|
32
|
+
children << child
|
30
33
|
end
|
31
34
|
|
32
35
|
def libui_api_keyword
|
33
36
|
'box'
|
34
37
|
end
|
35
38
|
|
39
|
+
def children
|
40
|
+
@children ||= []
|
41
|
+
end
|
42
|
+
|
43
|
+
def destroy_child(child)
|
44
|
+
::LibUI.send("box_delete", @libui, children.index(child))
|
45
|
+
ControlProxy.all_control_proxies.delete(child)
|
46
|
+
end
|
47
|
+
|
36
48
|
private
|
37
49
|
|
38
50
|
def build_control
|
39
51
|
super.tap do
|
40
|
-
self.padded =
|
52
|
+
self.padded = true
|
41
53
|
end
|
42
54
|
end
|
43
55
|
end
|
@@ -0,0 +1,64 @@
|
|
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 color button objects
|
27
|
+
#
|
28
|
+
# Follows the Proxy Design Pattern
|
29
|
+
class ColorButtonProxy < ControlProxy
|
30
|
+
def color
|
31
|
+
@red ||= Fiddle::Pointer.malloc(8) # double
|
32
|
+
@green ||= Fiddle::Pointer.malloc(8) # double
|
33
|
+
@blue ||= Fiddle::Pointer.malloc(8) # double
|
34
|
+
@alpha ||= Fiddle::Pointer.malloc(8) # double
|
35
|
+
::LibUI.color_button_color(@libui, @red, @green, @blue, @alpha)
|
36
|
+
[@red[0, 8].unpack1('d') * 255.0, @green[0, 8].unpack1('d') * 255.0, @blue[0, 8].unpack1('d') * 255.0, @alpha[0, 8].unpack1('d')]
|
37
|
+
end
|
38
|
+
|
39
|
+
def red
|
40
|
+
color[0]
|
41
|
+
end
|
42
|
+
|
43
|
+
def green
|
44
|
+
color[1]
|
45
|
+
end
|
46
|
+
|
47
|
+
def blue
|
48
|
+
color[2]
|
49
|
+
end
|
50
|
+
|
51
|
+
def alpha
|
52
|
+
color[3]
|
53
|
+
end
|
54
|
+
|
55
|
+
def destroy
|
56
|
+
Fiddle.free @red unless @red.nil?
|
57
|
+
Fiddle.free @green unless @green.nil?
|
58
|
+
Fiddle.free @blue unless @blue.nil?
|
59
|
+
Fiddle.free @alpha unless @alpha.nil?
|
60
|
+
super
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -52,10 +52,37 @@ module Glimmer
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def main_window_proxy
|
55
|
-
all_control_proxies.find {|c| c.is_a?(WindowProxy)}
|
55
|
+
all_control_proxies.find {|c| c.is_a?(Glimmer::LibUI::WindowProxy)}
|
56
|
+
end
|
57
|
+
|
58
|
+
def integer_to_boolean(int)
|
59
|
+
int.nil? ? nil : int == 1
|
60
|
+
end
|
61
|
+
|
62
|
+
def boolean_to_integer(bool)
|
63
|
+
bool.nil? ? nil : (bool ? 1 : 0)
|
64
|
+
end
|
65
|
+
|
66
|
+
def menu_proxies
|
67
|
+
all_control_proxies.select {|c| c.keyword == 'menu' }
|
56
68
|
end
|
57
69
|
end
|
58
70
|
|
71
|
+
BOOLEAN_PROPERTIES = %w[
|
72
|
+
padded
|
73
|
+
checked
|
74
|
+
enabled toplevel visible
|
75
|
+
read_only
|
76
|
+
margined
|
77
|
+
borderless fullscreen
|
78
|
+
stretchy
|
79
|
+
]
|
80
|
+
|
81
|
+
STRING_PROPERTIES = %w[
|
82
|
+
text
|
83
|
+
title
|
84
|
+
]
|
85
|
+
|
59
86
|
# libui returns the contained LibUI object
|
60
87
|
attr_reader :parent_proxy, :libui, :args, :keyword
|
61
88
|
|
@@ -64,11 +91,8 @@ module Glimmer
|
|
64
91
|
@parent_proxy = parent
|
65
92
|
@args = args
|
66
93
|
@block = block
|
67
|
-
@enabled =
|
94
|
+
@enabled = true
|
68
95
|
build_control
|
69
|
-
if @parent_proxy.class.constants.include?(:APPEND_PROPERTIES)
|
70
|
-
@parent_proxy.class::APPEND_PROPERTIES
|
71
|
-
end
|
72
96
|
post_add_content if @block.nil?
|
73
97
|
end
|
74
98
|
|
@@ -106,21 +130,28 @@ module Glimmer
|
|
106
130
|
|
107
131
|
def respond_to?(method_name, *args, &block)
|
108
132
|
respond_to_libui?(method_name, *args, &block) ||
|
109
|
-
(
|
133
|
+
(
|
134
|
+
append_properties.include?(method_name.to_s) ||
|
135
|
+
(append_properties.include?(method_name.to_s.sub(/\?$/, '')) && BOOLEAN_PROPERTIES.include?(method_name.to_s.sub(/\?$/, ''))) ||
|
136
|
+
append_properties.include?(method_name.to_s.sub(/=$/, ''))
|
137
|
+
) ||
|
110
138
|
super(method_name, true)
|
111
139
|
end
|
112
140
|
|
113
141
|
def respond_to_libui?(method_name, *args, &block)
|
114
142
|
::LibUI.respond_to?("control_#{method_name}") ||
|
143
|
+
(::LibUI.respond_to?("control_#{method_name.to_s.sub(/\?$/, '')}") && BOOLEAN_PROPERTIES.include?(method_name.to_s.sub(/\?$/, '')) ) ||
|
144
|
+
::LibUI.respond_to?("control_set_#{method_name.to_s.sub(/=$/, '')}") ||
|
115
145
|
::LibUI.respond_to?("#{libui_api_keyword}_#{method_name}") ||
|
116
|
-
::LibUI.respond_to?("#{libui_api_keyword}
|
146
|
+
(::LibUI.respond_to?("#{libui_api_keyword}_#{method_name.to_s.sub(/\?$/, '')}") && BOOLEAN_PROPERTIES.include?(method_name.to_s.sub(/\?$/, '')) ) ||
|
117
147
|
::LibUI.respond_to?("#{libui_api_keyword}_set_#{method_name.to_s.sub(/=$/, '')}")
|
118
148
|
end
|
119
149
|
|
120
150
|
def method_missing(method_name, *args, &block)
|
121
151
|
if respond_to_libui?(method_name, *args, &block)
|
122
152
|
send_to_libui(method_name, *args, &block)
|
123
|
-
elsif
|
153
|
+
elsif append_properties.include?(method_name.to_s) ||
|
154
|
+
append_properties.include?(method_name.to_s.sub(/(=|\?)$/, ''))
|
124
155
|
append_property(method_name, *args)
|
125
156
|
else
|
126
157
|
super
|
@@ -128,17 +159,25 @@ module Glimmer
|
|
128
159
|
end
|
129
160
|
|
130
161
|
def send_to_libui(method_name, *args, &block)
|
131
|
-
if ::LibUI.respond_to?("#{libui_api_keyword}_#{method_name}") && args.empty?
|
132
|
-
|
133
|
-
|
134
|
-
|
162
|
+
if ::LibUI.respond_to?("#{libui_api_keyword}_#{method_name.to_s.sub(/\?$/, '')}") && args.empty?
|
163
|
+
property = method_name.to_s.sub(/\?$/, '')
|
164
|
+
value = ::LibUI.send("#{libui_api_keyword}_#{property}", @libui, *args)
|
165
|
+
handle_string_property(property, handle_boolean_property(property, value))
|
135
166
|
elsif ::LibUI.respond_to?("#{libui_api_keyword}_set_#{method_name.to_s.sub(/=$/, '')}") && !args.empty?
|
136
|
-
|
137
|
-
|
138
|
-
::LibUI.send("#{libui_api_keyword}
|
167
|
+
property = method_name.to_s.sub(/=$/, '')
|
168
|
+
args[0] = ControlProxy.boolean_to_integer(args.first) if BOOLEAN_PROPERTIES.include?(property) && (args.first.is_a?(TrueClass) || args.first.is_a?(FalseClass))
|
169
|
+
::LibUI.send("#{libui_api_keyword}_set_#{property}", @libui, *args)
|
139
170
|
elsif ::LibUI.respond_to?("#{libui_api_keyword}_#{method_name}") && !args.empty?
|
140
171
|
::LibUI.send("#{libui_api_keyword}_#{method_name}", @libui, *args)
|
141
|
-
elsif ::LibUI.respond_to?("control_#{method_name}")
|
172
|
+
elsif ::LibUI.respond_to?("control_#{method_name.to_s.sub(/\?$/, '')}") && args.empty?
|
173
|
+
property = method_name.to_s.sub(/\?$/, '')
|
174
|
+
value = ::LibUI.send("control_#{property}", @libui, *args)
|
175
|
+
handle_string_property(property, handle_boolean_property(property, value))
|
176
|
+
elsif ::LibUI.respond_to?("control_set_#{method_name.to_s.sub(/=$/, '')}")
|
177
|
+
property = method_name.to_s.sub(/=$/, '')
|
178
|
+
args[0] = ControlProxy.boolean_to_integer(args.first) if BOOLEAN_PROPERTIES.include?(property) && (args.first.is_a?(TrueClass) || args.first.is_a?(FalseClass))
|
179
|
+
::LibUI.send("control_set_#{method_name.to_s.sub(/=$/, '')}", @libui, *args)
|
180
|
+
elsif ::LibUI.respond_to?("control_#{method_name}") && !args.empty?
|
142
181
|
::LibUI.send("control_#{method_name}", @libui, *args)
|
143
182
|
end
|
144
183
|
end
|
@@ -148,11 +187,13 @@ module Glimmer
|
|
148
187
|
end
|
149
188
|
|
150
189
|
def append_property(property, value = nil)
|
151
|
-
property = property.to_s.sub(
|
190
|
+
property = property.to_s.sub(/(=|\?)$/, '')
|
152
191
|
@append_property_hash ||= {}
|
153
192
|
if value.nil?
|
154
|
-
@append_property_hash[property]
|
193
|
+
value = @append_property_hash[property]
|
194
|
+
handle_string_property(property, handle_boolean_property(property, value))
|
155
195
|
else
|
196
|
+
value = ControlProxy.boolean_to_integer(value) if BOOLEAN_PROPERTIES.include?(property) && (value.is_a?(TrueClass) || value.is_a?(FalseClass))
|
156
197
|
@append_property_hash[property] = value
|
157
198
|
end
|
158
199
|
end
|
@@ -161,11 +202,28 @@ module Glimmer
|
|
161
202
|
@keyword
|
162
203
|
end
|
163
204
|
|
205
|
+
def destroy
|
206
|
+
if parent_proxy.nil?
|
207
|
+
default_destroy
|
208
|
+
else
|
209
|
+
parent_proxy.destroy_child(self)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def destroy_child(child)
|
214
|
+
child.default_destroy
|
215
|
+
end
|
216
|
+
|
217
|
+
def default_destroy
|
218
|
+
send_to_libui('destroy')
|
219
|
+
ControlProxy.all_control_proxies.delete(self)
|
220
|
+
end
|
221
|
+
|
164
222
|
def enabled(value = nil)
|
165
223
|
if value.nil?
|
166
224
|
@enabled
|
167
225
|
elsif value != @enabled
|
168
|
-
if value == 1
|
226
|
+
if value == 1 || value
|
169
227
|
send_to_libui('enable')
|
170
228
|
else
|
171
229
|
send_to_libui('disable')
|
@@ -181,7 +239,7 @@ module Glimmer
|
|
181
239
|
if value.nil?
|
182
240
|
current_value
|
183
241
|
elsif value != current_value
|
184
|
-
if value == 1
|
242
|
+
if value == 1 || value
|
185
243
|
send_to_libui('show')
|
186
244
|
else
|
187
245
|
send_to_libui('hide')
|
@@ -192,11 +250,6 @@ module Glimmer
|
|
192
250
|
alias set_visible visible
|
193
251
|
alias visible= visible
|
194
252
|
|
195
|
-
def destroy
|
196
|
-
send_to_libui('destroy')
|
197
|
-
self.class.all_control_proxies.delete(self)
|
198
|
-
end
|
199
|
-
|
200
253
|
private
|
201
254
|
|
202
255
|
def build_control
|
@@ -207,6 +260,14 @@ module Glimmer
|
|
207
260
|
::LibUI.send(@keyword, *@args)
|
208
261
|
end
|
209
262
|
end
|
263
|
+
|
264
|
+
def handle_boolean_property(property, value)
|
265
|
+
BOOLEAN_PROPERTIES.include?(property) ? ControlProxy.integer_to_boolean(value) : value
|
266
|
+
end
|
267
|
+
|
268
|
+
def handle_string_property(property, value)
|
269
|
+
STRING_PROPERTIES.include?(property) ? value.to_s : value
|
270
|
+
end
|
210
271
|
end
|
211
272
|
end
|
212
273
|
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/date_time_picker_proxy'
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module LibUI
|
26
|
+
# Proxy for LibUI date picker objects
|
27
|
+
#
|
28
|
+
# Follows the Proxy Design Pattern
|
29
|
+
class DatePickerProxy < DateTimePickerProxy
|
30
|
+
end
|
31
|
+
end
|
32
|
+
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 date time picker objects
|
27
|
+
#
|
28
|
+
# Follows the Proxy Design Pattern
|
29
|
+
class DateTimePickerProxy < ControlProxy
|
30
|
+
def libui_api_keyword
|
31
|
+
'date_time_picker'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|