forked from thomthom/SKUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.rb
179 lines (151 loc) · 4.62 KB
/
example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
begin
original_verbose = $VERBOSE
$VERBOSE = nil
load 'SKUI/core.rb'
ensure
$VERBOSE = original_verbose
end
module SKUI::Examples
def self.show
options = {
:title => 'SKUI Control Examples',
:preferences_key => 'SKUI_Example',
:width => 400,
:height => 400,
:resizable => true
}
window = SKUI::Window.new( options )
# These events doesn't trigger correctly when Firebug Lite
# is active because it introduces frames that interfere with
# the focus notifications.
window.on( :focus ) { puts 'Window Focus' }
window.on( :blur ) { puts 'Window Blur' }
window.on( :resize ) { |window, width, height|
puts "Window Resize(#{width}, #{height})"
}
group = SKUI::Groupbox.new( 'Groupbox' )
group.position( 5, 5 )
group.right = 5
group.height = 100
group.foreground_color = Sketchup::Color.new( 192, 0, 0 )
window.add_control( group )
txt_input = SKUI::Textbox.new( 'SketchUp' )
txt_input.name = :txt_name
txt_input.position( 60, 20 )
txt_input.width = 190
txt_input.right = 10 # (!) Currently ignored by browser.
group.add_control( txt_input )
lbl_input = SKUI::Label.new( 'Name:', txt_input )
lbl_input.position( 10, 23 )
lbl_input.width = 50
group.add_control( lbl_input )
list = %w{ Hello World Lorem Ipsum Single'Quote Double'Quote }
lst_dropdown = SKUI::Listbox.new( list )
lst_dropdown.value = lst_dropdown.items.first
lst_dropdown.position( 10, -10 )
lst_dropdown.width = 170
lst_dropdown.on( :change ) { |control, value| # (?) Second argument needed?
puts "Dropbox value: #{control.value}"
}
group.add_control( lst_dropdown )
btn_hello = SKUI::Button.new( 'Hello' ) { |control|
name = control.window[:txt_name].value
puts "Hello #{name}"
UI.messagebox( "Hello #{name}" )
}
btn_hello.position( -10, -10 )
btn_hello.tooltip = 'Click me!'
group.add_control( btn_hello )
group2 = SKUI::Groupbox.new( 'Multiline Text and List' )
group2.position( 5, 110 )
group2.right = 5
group2.height = 130
window.add_control( group2 )
txt_area = SKUI::Textbox.new( 'Lorem Ipsum' )
txt_area.multiline = true
txt_area.position( 10, 20 )
txt_area.width = 130
txt_area.height = 90
group2.add_control( txt_area )
list = %w{ Hello World Lorem Ipsum Single'Quote Double'Quote }
lst_list = SKUI::Listbox.new( list )
lst_list.name = :lst_test
lst_list.size = 4
lst_list.multiple = true
lst_list.value = lst_list.items.first
lst_list.position( 145, 20 )
lst_list.width = 130
lst_list.height = 90
lst_list.on( :change ) { |control, value|
puts "Listbox value: #{control.value}"
}
group2.add_control( lst_list )
path = File.join( SKUI::PATH, '..', '..', 'examples' )
file = File.join( path, 'cookie.png' )
img_cookie = SKUI::Image.new( file )
img_cookie.position( 280, 20 )
img_cookie.width = 32
group2.add_control( img_cookie )
group3 = SKUI::Groupbox.new( 'Option Groups' )
group3.position( 5, 245 )
group3.right = 5
group3.height = 100
window.add_control( group3 )
r1 = SKUI::RadioButton.new( 'Foo' )
r1.position( 10, 20 )
r1.on( :change ) { |control|
puts "RadioButton.change - #{control}"
puts "> Siblings: #{control.siblings.inspect}"
puts "> Selected: #{control.checked_sibling.inspect}"
}
group3.add_control( r1 )
r2 = SKUI::RadioButton.new( 'Bar' )
r2.position( 10, 40 )
group3.add_control( r2 )
r3 = SKUI::RadioButton.new( 'Biz' )
r3.position( 10, 60 )
group3.add_control( r3 )
container = SKUI::Container.new
container.foreground_color = SKUI::SystemColor::HIGHLIGHT
container.background_color = Sketchup::Color.new( 192, 92, 64, 64 )
container.stretch( 100, 20, 10, 5 )
group3.add_control( container )
r4 = SKUI::RadioButton.new( 'Lorem', true )
r4.position( 10, 0 )
container.add_control( r4 )
r5 = SKUI::RadioButton.new( 'Ipsum' )
r5.position( 10, 20 )
container.add_control( r5 )
r6 = SKUI::RadioButton.new( 'Dolor' )
r6.position( 10, 40 )
container.add_control( r6 )
btn_test = SKUI::Button.new( 'Test' ) { |control|
puts 'Testing...'
}
btn_test.position( 5, -5 )
btn_test.font = SKUI::Font.new( 'Comic Sans MS', 14, true )
window.add_control( btn_test )
chk_hide = SKUI::Checkbox.new( 'Hide' )
chk_hide.left = btn_test.left + btn_test.width + 5
chk_hide.bottom = 8
chk_hide.on( :change ) { |control|
puts "Checkbox: #{control.checked?}"
btn_test.visible = !control.checked?
}
window.add_control( chk_hide )
lbl_url = SKUI::Label.new( 'SKUI on GitHub' )
lbl_url.position( -85, -10 )
lbl_url.url = 'https://github.com/thomthom/SKUI'
window.add_control( lbl_url )
btn_close = SKUI::Button.new( 'Close' ) { |control|
control.window.close
}
btn_close.position( -5, -5 )
window.add_control( btn_close )
window.default_button = btn_test
window.cancel_button = btn_close
window.show
window
end # def
end # module
window = SKUI::Examples.show