glimmer-dsl-swt 4.20.0.0 → 4.20.0.5
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 +26 -0
- data/README.md +18 -14
- data/VERSION +1 -1
- data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +11 -7
- data/docs/reference/GLIMMER_SAMPLES.md +170 -17
- data/docs/reference/GLIMMER_STYLE_GUIDE.md +4 -3
- data/glimmer-dsl-swt.gemspec +0 -0
- data/lib/glimmer/dsl/swt/widget_expression.rb +2 -0
- data/lib/glimmer/dsl/swt/widget_listener_expression.rb +3 -3
- data/lib/glimmer/rake_task/scaffold.rb +0 -2
- data/lib/glimmer/swt/combo_proxy.rb +48 -0
- data/lib/glimmer/swt/display_proxy.rb +11 -8
- data/lib/glimmer/swt/tool_bar_proxy.rb +51 -0
- data/lib/glimmer/swt/widget_proxy.rb +7 -1
- data/lib/glimmer/ui/custom_shell.rb +3 -3
- data/lib/glimmer/ui/custom_widget.rb +5 -2
- data/samples/elaborate/calculator.rb +116 -0
- data/samples/elaborate/calculator/model/command.rb +105 -0
- data/samples/elaborate/calculator/model/command/all_clear.rb +17 -0
- data/samples/elaborate/calculator/model/command/command_history.rb +0 -0
- data/samples/elaborate/calculator/model/command/equals.rb +18 -0
- data/samples/elaborate/calculator/model/command/number.rb +20 -0
- data/samples/elaborate/calculator/model/command/operation.rb +27 -0
- data/samples/elaborate/calculator/model/command/operation/add.rb +15 -0
- data/samples/elaborate/calculator/model/command/operation/divide.rb +15 -0
- data/samples/elaborate/calculator/model/command/operation/multiply.rb +15 -0
- data/samples/elaborate/calculator/model/command/operation/subtract.rb +15 -0
- data/samples/elaborate/calculator/model/command/point.rb +20 -0
- data/samples/elaborate/calculator/model/presenter.rb +30 -0
- data/samples/elaborate/login.rb +15 -13
- data/samples/elaborate/tetris.rb +4 -4
- data/samples/elaborate/tetris/model/game.rb +0 -3
- data/samples/elaborate/timer.rb +233 -0
- data/samples/elaborate/timer/alarm1.wav +0 -0
- data/samples/elaborate/timer/sounds/alarm1.wav +0 -0
- data/samples/elaborate/user_profile.rb +4 -2
- data/samples/elaborate/weather.rb +164 -0
- data/samples/hello/hello_composite.rb +71 -0
- data/samples/hello/hello_cool_bar.rb +147 -0
- data/samples/hello/hello_layout.rb +243 -0
- data/samples/hello/hello_shell.rb +205 -0
- data/samples/hello/hello_text.rb +120 -0
- data/samples/hello/hello_tool_bar.rb +143 -0
- metadata +28 -3
Binary file
|
Binary file
|
@@ -23,7 +23,9 @@ require 'glimmer-dsl-swt'
|
|
23
23
|
|
24
24
|
include Glimmer
|
25
25
|
|
26
|
-
|
26
|
+
# A version of this was featured in a dzone article as an intro to Glimmer syntax:
|
27
|
+
# https://dzone.com/articles/an-introduction-glimmer
|
28
|
+
shell { |shell_proxy|
|
27
29
|
text "User Profile"
|
28
30
|
|
29
31
|
composite {
|
@@ -72,7 +74,7 @@ shell {
|
|
72
74
|
button {
|
73
75
|
text "close"
|
74
76
|
layout_data :left, :center, true, true
|
75
|
-
on_widget_selected {
|
77
|
+
on_widget_selected { shell_proxy.close }
|
76
78
|
}
|
77
79
|
}
|
78
80
|
}.open
|
@@ -0,0 +1,164 @@
|
|
1
|
+
# Copyright (c) 2007-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-dsl-swt'
|
23
|
+
require 'net/http'
|
24
|
+
require 'json'
|
25
|
+
require 'facets/string/titlecase'
|
26
|
+
|
27
|
+
class Weather
|
28
|
+
include Glimmer::UI::CustomShell
|
29
|
+
|
30
|
+
DEFAULT_FONT_HEIGHT = 30
|
31
|
+
DEFAULT_FOREGROUND = :white
|
32
|
+
|
33
|
+
attr_accessor :city, :temp, :temp_min, :temp_max, :feels_like, :humidity
|
34
|
+
|
35
|
+
before_body {
|
36
|
+
@weather_mutex = Mutex.new
|
37
|
+
self.city = 'Montreal, QC, CA'
|
38
|
+
fetch_weather!
|
39
|
+
}
|
40
|
+
|
41
|
+
after_body {
|
42
|
+
Thread.new do
|
43
|
+
loop do
|
44
|
+
sleep(10)
|
45
|
+
break if body_root.disposed?
|
46
|
+
fetch_weather!
|
47
|
+
end
|
48
|
+
end
|
49
|
+
}
|
50
|
+
|
51
|
+
body {
|
52
|
+
shell(:no_resize) {
|
53
|
+
grid_layout
|
54
|
+
|
55
|
+
text 'Glimmer Weather'
|
56
|
+
minimum_size 400, 300
|
57
|
+
background rgb(135, 176, 235)
|
58
|
+
|
59
|
+
text {
|
60
|
+
layout_data(:center, :center, true, true)
|
61
|
+
|
62
|
+
text <=> [self, :city]
|
63
|
+
|
64
|
+
on_key_pressed {|event|
|
65
|
+
if event.keyCode == swt(:cr) # carriage return
|
66
|
+
Thread.new do
|
67
|
+
fetch_weather!
|
68
|
+
end
|
69
|
+
end
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
tab_folder {
|
74
|
+
layout_data(:center, :center, true, true)
|
75
|
+
|
76
|
+
['℃', '℉'].each do |temp_unit|
|
77
|
+
tab_item {
|
78
|
+
grid_layout 2, false
|
79
|
+
|
80
|
+
text temp_unit
|
81
|
+
background :transparent
|
82
|
+
|
83
|
+
rectangle(0, 0, [:default, -2], [:default, -2], 15, 15) {
|
84
|
+
foreground DEFAULT_FOREGROUND
|
85
|
+
}
|
86
|
+
|
87
|
+
%w[temp temp_min temp_max feels_like].each do |field_name|
|
88
|
+
temp_field(field_name, temp_unit)
|
89
|
+
end
|
90
|
+
|
91
|
+
humidity_field
|
92
|
+
}
|
93
|
+
end
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
def temp_field(field_name, temp_unit)
|
99
|
+
name_label(field_name)
|
100
|
+
label {
|
101
|
+
layout_data(:fill, :center, true, false)
|
102
|
+
text <= [self, field_name, on_read: ->(t) { "#{kelvin_to_temp_unit(t, temp_unit).to_f.round}°" }]
|
103
|
+
font height: DEFAULT_FONT_HEIGHT
|
104
|
+
foreground DEFAULT_FOREGROUND
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
def humidity_field
|
109
|
+
name_label('humidity')
|
110
|
+
label {
|
111
|
+
layout_data(:fill, :center, true, false)
|
112
|
+
text <= [self, 'humidity', on_read: ->(h) { "#{h.to_f.round}%" }]
|
113
|
+
font height: DEFAULT_FONT_HEIGHT
|
114
|
+
foreground DEFAULT_FOREGROUND
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
def name_label(field_name)
|
119
|
+
label {
|
120
|
+
layout_data :fill, :center, false, false
|
121
|
+
text field_name.titlecase
|
122
|
+
font height: DEFAULT_FONT_HEIGHT
|
123
|
+
foreground DEFAULT_FOREGROUND
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
def fetch_weather!
|
128
|
+
@weather_mutex.synchronize do
|
129
|
+
self.weather_data = JSON.parse(Net::HTTP.get('api.openweathermap.org', "/data/2.5/weather?q=#{city}&appid=1d16d70a9aec3570b5cbd27e6b421330"))
|
130
|
+
end
|
131
|
+
rescue
|
132
|
+
# No Op
|
133
|
+
end
|
134
|
+
|
135
|
+
def weather_data=(data)
|
136
|
+
@weather_data = data
|
137
|
+
main_data = data['main']
|
138
|
+
# temps come back in Kelvin
|
139
|
+
self.temp = main_data['temp']
|
140
|
+
self.temp_min = main_data['temp_min']
|
141
|
+
self.temp_max = main_data['temp_max']
|
142
|
+
self.feels_like = main_data['feels_like']
|
143
|
+
self.humidity = main_data['humidity']
|
144
|
+
end
|
145
|
+
|
146
|
+
def kelvin_to_temp_unit(kelvin, temp_unit)
|
147
|
+
temp_unit == '℃' ? kelvin_to_celsius(kelvin) : kelvin_to_fahrenheit(kelvin)
|
148
|
+
end
|
149
|
+
|
150
|
+
def kelvin_to_celsius(kelvin)
|
151
|
+
kelvin - 273.15
|
152
|
+
end
|
153
|
+
|
154
|
+
def celsius_to_fahrenheit(celsius)
|
155
|
+
(celsius * 9 / 5 ) + 32
|
156
|
+
end
|
157
|
+
|
158
|
+
def kelvin_to_fahrenheit(kelvin)
|
159
|
+
celsius_to_fahrenheit(kelvin_to_celsius(kelvin))
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
Weather.launch
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Copyright (c) 2007-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-dsl-swt'
|
23
|
+
|
24
|
+
class HelloComposite
|
25
|
+
include Glimmer::UI::CustomShell
|
26
|
+
|
27
|
+
body {
|
28
|
+
shell {
|
29
|
+
# shell (which is a composite) has fill_layout(:horizontal) by default with no margins
|
30
|
+
# we override below
|
31
|
+
fill_layout(:vertical)
|
32
|
+
text 'Hello, Composite!'
|
33
|
+
|
34
|
+
composite { # composite simply contains widgets for visual organization via a layout
|
35
|
+
# it has grid_layout(1, false) as its default layout
|
36
|
+
label {
|
37
|
+
text "Field is above its text widget"
|
38
|
+
}
|
39
|
+
text {
|
40
|
+
layout_data :fill, :center, true, false # fill horizontally, align center vertically, grab remaining horizontal space, but not vertical
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
composite { # composite simply contains widgets for visual organization via a layout
|
45
|
+
grid_layout 2, true
|
46
|
+
|
47
|
+
label {
|
48
|
+
text "Field has equal width to its text widget's"
|
49
|
+
}
|
50
|
+
text {
|
51
|
+
layout_data :fill, :center, true, false # fill horizontally, align center vertically, grab remaining horizontal space, but not vertical
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
composite { # composite simply contains widgets for visual organization via a layout
|
56
|
+
grid_layout 2, false
|
57
|
+
|
58
|
+
label {
|
59
|
+
text "Field has inequal width"
|
60
|
+
}
|
61
|
+
|
62
|
+
text {
|
63
|
+
layout_data :fill, :center, true, false # fill horizontally, align center vertically, grab remaining horizontal space, but not vertical
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
HelloComposite.launch
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# Copyright (c) 2007-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-dsl-swt'
|
23
|
+
|
24
|
+
class HelloCoolBar
|
25
|
+
include Glimmer::UI::CustomShell
|
26
|
+
|
27
|
+
attr_accessor :operation, :font_size
|
28
|
+
|
29
|
+
def font_size_options
|
30
|
+
(10..30).to_a.map(&:to_s)
|
31
|
+
end
|
32
|
+
|
33
|
+
before_body {
|
34
|
+
self.font_size = '30'
|
35
|
+
}
|
36
|
+
|
37
|
+
body {
|
38
|
+
shell {
|
39
|
+
fill_layout(:vertical) {
|
40
|
+
margin_width 0
|
41
|
+
margin_height 0
|
42
|
+
}
|
43
|
+
|
44
|
+
text 'Hello, Cool Bar!'
|
45
|
+
|
46
|
+
cool_bar { # optionally takes a :flat style and/or :vertical style if you need vertical layout
|
47
|
+
tool_bar {
|
48
|
+
tool_item {
|
49
|
+
image cut_image # alternatively you can pass an image file path
|
50
|
+
|
51
|
+
on_widget_selected do
|
52
|
+
self.operation = 'Cut'
|
53
|
+
end
|
54
|
+
}
|
55
|
+
tool_item {
|
56
|
+
image copy_image # alternatively you can pass an image file path
|
57
|
+
|
58
|
+
on_widget_selected do
|
59
|
+
self.operation = 'Copy'
|
60
|
+
end
|
61
|
+
}
|
62
|
+
tool_item {
|
63
|
+
image paste_image # alternatively you can pass an image file path
|
64
|
+
|
65
|
+
on_widget_selected do
|
66
|
+
self.operation = 'Paste'
|
67
|
+
end
|
68
|
+
}
|
69
|
+
}
|
70
|
+
tool_bar {
|
71
|
+
tool_item {
|
72
|
+
text 'Font Size'
|
73
|
+
}
|
74
|
+
# a combo can be nested in a tool_bar (it auto-generates a tool_item for itself behind the scenes)
|
75
|
+
combo {
|
76
|
+
selection bind(self, :font_size)
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
label {
|
83
|
+
font <= [self, :font_size, on_read: ->(size) { {height: size.to_i} }]
|
84
|
+
text <= [self, :operation]
|
85
|
+
text <= [self, :font_size]
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
def cut_image
|
91
|
+
# building image on the fly with Canvas Shape DSL
|
92
|
+
image(25, 25) {
|
93
|
+
rectangle(0, 0, 25, 25) {
|
94
|
+
background_pattern 0, 0, 0, 25, :white, :gray
|
95
|
+
line(20, 2, 9, 15) {
|
96
|
+
line_width 2
|
97
|
+
}
|
98
|
+
line(5, 2, 16, 15) {
|
99
|
+
line_width 2
|
100
|
+
}
|
101
|
+
oval(2, 15, 8, 8) {
|
102
|
+
line_width 2
|
103
|
+
}
|
104
|
+
oval(16, 15, 8, 8) {
|
105
|
+
line_width 2
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
def copy_image
|
112
|
+
# building image on the fly with Canvas Shape DSL
|
113
|
+
image(25, 25) {
|
114
|
+
rectangle(0, 0, 25, 25) {
|
115
|
+
background_pattern 0, 0, 0, 25, :white, :gray
|
116
|
+
rectangle([:default, 2], [:default, -2], 14, 14, 5, 5) {
|
117
|
+
line_width 2
|
118
|
+
}
|
119
|
+
rectangle([:default, -2], [:default, 2], 14, 14, 5, 5) {
|
120
|
+
line_width 2
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
def paste_image
|
127
|
+
image(25, 25) {
|
128
|
+
rectangle(0, 0, 25, 25) {
|
129
|
+
background_pattern 0, 0, 0, 25, :white, :gray
|
130
|
+
rectangle(:default, [:default, 1], 15, 20, 5, 5) {
|
131
|
+
line_width 2
|
132
|
+
}
|
133
|
+
line(7, 8, 18, 8) {
|
134
|
+
line_width 2
|
135
|
+
}
|
136
|
+
line(7, 13, 18, 13) {
|
137
|
+
line_width 2
|
138
|
+
}
|
139
|
+
line(7, 18, 18, 18) {
|
140
|
+
line_width 2
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
HelloCoolBar.launch
|
@@ -0,0 +1,243 @@
|
|
1
|
+
# Copyright (c) 2007-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-dsl-swt'
|
23
|
+
|
24
|
+
class HelloLayout
|
25
|
+
include Glimmer::UI::CustomShell
|
26
|
+
|
27
|
+
body {
|
28
|
+
shell {
|
29
|
+
# shell (which is a composite) has fill_layout(:horizontal) by default with no margins
|
30
|
+
text 'Hello, Layout!'
|
31
|
+
tab_folder {
|
32
|
+
|
33
|
+
# every tab item has its own composite, which can set a layout
|
34
|
+
tab_item {
|
35
|
+
text 'Fill Layout (horizontal)'
|
36
|
+
|
37
|
+
fill_layout(:horizontal) {
|
38
|
+
margin_width 30
|
39
|
+
margin_height 40
|
40
|
+
spacing 5
|
41
|
+
}
|
42
|
+
|
43
|
+
10.times { |n|
|
44
|
+
label {
|
45
|
+
text "<label #{n+1}>"
|
46
|
+
}
|
47
|
+
|
48
|
+
}
|
49
|
+
|
50
|
+
}
|
51
|
+
|
52
|
+
tab_item {
|
53
|
+
text 'Fill Layout (vertical)'
|
54
|
+
|
55
|
+
fill_layout {
|
56
|
+
type :vertical # alternative way of specifying orientation
|
57
|
+
margin_width 40
|
58
|
+
margin_height 30
|
59
|
+
spacing 10
|
60
|
+
}
|
61
|
+
|
62
|
+
10.times { |n|
|
63
|
+
label(:center) {
|
64
|
+
text "<label #{n+1}>"
|
65
|
+
}
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
tab_item {
|
72
|
+
text 'Row Layout (horizontal)'
|
73
|
+
|
74
|
+
row_layout(:horizontal) {
|
75
|
+
# row layout has margin attributes for top, left, right, and bottom
|
76
|
+
# in addition to width and height (and sets margin_width and margin_height to 5 by default)
|
77
|
+
margin_top 40
|
78
|
+
margin_left 30
|
79
|
+
spacing 5
|
80
|
+
wrap false
|
81
|
+
center true
|
82
|
+
justify true
|
83
|
+
}
|
84
|
+
|
85
|
+
10.times { |n|
|
86
|
+
label {
|
87
|
+
text "<label #{n+1}>"
|
88
|
+
}
|
89
|
+
|
90
|
+
}
|
91
|
+
|
92
|
+
}
|
93
|
+
|
94
|
+
tab_item {
|
95
|
+
text 'Row Layout (wrap on shrink)'
|
96
|
+
|
97
|
+
row_layout { # :horizontal is the default type
|
98
|
+
margin_height 40
|
99
|
+
margin_width 30
|
100
|
+
spacing 35
|
101
|
+
# wrap true # is the default
|
102
|
+
}
|
103
|
+
|
104
|
+
10.times { |n|
|
105
|
+
label {
|
106
|
+
text "<label #{n+1}>"
|
107
|
+
}
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
tab_item {
|
114
|
+
text 'Row Layout (vertical)'
|
115
|
+
background :yellow
|
116
|
+
|
117
|
+
row_layout(:vertical) { |l|
|
118
|
+
margin_height 0
|
119
|
+
margin_width 0
|
120
|
+
spacing 10
|
121
|
+
fill true # fills horizontally to match the widest child (opposite to row layout orientation)
|
122
|
+
center false # enable and disable fill to see what this does
|
123
|
+
}
|
124
|
+
|
125
|
+
10.times { |n|
|
126
|
+
label {
|
127
|
+
# layout_data allows a widget to tweak its layout configuration (generating RowData object for RowLayout)
|
128
|
+
layout_data {
|
129
|
+
height 30
|
130
|
+
# width unspecified yet calculated
|
131
|
+
}
|
132
|
+
text "<this is a ver#{'r'*(rand*200).to_i}y wide label #{n+1}>"
|
133
|
+
background :green
|
134
|
+
}
|
135
|
+
|
136
|
+
}
|
137
|
+
|
138
|
+
}
|
139
|
+
|
140
|
+
tab_item {
|
141
|
+
text 'Grid Layout'
|
142
|
+
|
143
|
+
grid_layout {
|
144
|
+
num_columns 5
|
145
|
+
make_columns_equal_width true
|
146
|
+
horizontal_spacing 15
|
147
|
+
vertical_spacing 10
|
148
|
+
|
149
|
+
# grid layout has margin attributes for top, left, right, and bottom
|
150
|
+
# in addition to width and height (and sets margin_width and margin_height to 5 by default)
|
151
|
+
margin_height 0
|
152
|
+
margin_top 20
|
153
|
+
}
|
154
|
+
|
155
|
+
10.times { |n|
|
156
|
+
label {
|
157
|
+
text "<this label is wide enough to fill #{n+1}>"
|
158
|
+
background :white
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
label {
|
163
|
+
# layout_data allows a widget to tweak its layout configuration (generating GridData object for GridLayout)
|
164
|
+
layout_data {
|
165
|
+
width_hint 120
|
166
|
+
height_hint 40
|
167
|
+
}
|
168
|
+
text "<this label is clipped>"
|
169
|
+
background :cyan
|
170
|
+
}
|
171
|
+
|
172
|
+
label {
|
173
|
+
# layout_data allows a widget to tweak its layout configuration (generating GridData object for GridLayout)
|
174
|
+
layout_data {
|
175
|
+
horizontal_span 2
|
176
|
+
}
|
177
|
+
text "<this label spans two columns, so it can contain more text than normal>"
|
178
|
+
background :green
|
179
|
+
}
|
180
|
+
|
181
|
+
label {
|
182
|
+
# layout_data allows a widget to tweak its layout configuration (generating GridData object for GridLayout)
|
183
|
+
layout_data {
|
184
|
+
vertical_span 2
|
185
|
+
vertical_alignment :fill
|
186
|
+
}
|
187
|
+
text "<this label spans two rows, \nso it can contain new lines\n1\n2\n3\n4\n5\n6\n7>"
|
188
|
+
background :yellow
|
189
|
+
}
|
190
|
+
|
191
|
+
5.times { label } # just filler
|
192
|
+
|
193
|
+
label {
|
194
|
+
|
195
|
+
# layout_data allows a widget to tweak its layout configuration (generating GridData object for GridLayout)
|
196
|
+
layout_data {
|
197
|
+
horizontal_span 5
|
198
|
+
horizontal_alignment :fill # could be :beginning, :center or :end too
|
199
|
+
vertical_alignment :fill # could be :beginning, :center, or :end too
|
200
|
+
grab_excess_horizontal_space true
|
201
|
+
grab_excess_vertical_space true
|
202
|
+
}
|
203
|
+
|
204
|
+
# this is a short alternative for specifying what is above
|
205
|
+
# layout_data(:fill, :fill, true, true) {
|
206
|
+
# horizontal_span 5
|
207
|
+
# }
|
208
|
+
|
209
|
+
text "<this label fills all the space it can get\nhorizontally and vertically>"
|
210
|
+
background :magenta
|
211
|
+
}
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
tab_item {
|
217
|
+
text 'Grid Layout (non-equal columns)'
|
218
|
+
|
219
|
+
grid_layout(2, false) # alt syntax: (numColumns, make_columns_equal_width)
|
220
|
+
|
221
|
+
10.times { |n|
|
222
|
+
label {
|
223
|
+
text "Field #{n+1}"
|
224
|
+
}
|
225
|
+
text {
|
226
|
+
layout_data {
|
227
|
+
width_hint 600
|
228
|
+
}
|
229
|
+
|
230
|
+
text "Please enter text"
|
231
|
+
}
|
232
|
+
}
|
233
|
+
|
234
|
+
}
|
235
|
+
|
236
|
+
}
|
237
|
+
|
238
|
+
}
|
239
|
+
|
240
|
+
}
|
241
|
+
end
|
242
|
+
|
243
|
+
HelloLayout.launch
|