-
Notifications
You must be signed in to change notification settings - Fork 6
/
hello_cool_bar.rb
92 lines (78 loc) · 2.71 KB
/
hello_cool_bar.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
# Copyright (c) 2007-2024 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer-dsl-swt'
class HelloCoolBar
include Glimmer::UI::CustomShell
attr_accessor :operation, :font_size
def font_size_options
(10..30).to_a.map(&:to_s)
end
before_body do
self.font_size = '30'
end
body {
shell {
fill_layout(:vertical) {
margin_width 0
margin_height 0
}
text 'Hello, Cool Bar!'
minimum_size 280, 50
cool_bar { # optionally takes a :flat style and/or :vertical style if you need vertical layout
tool_bar {
tool_item {
image File.expand_path('./images/cut.png', __dir__), height: 16
on_widget_selected do
self.operation = 'Cut'
end
}
tool_item {
image File.expand_path('./images/copy.png', __dir__), height: 16
on_widget_selected do
self.operation = 'Copy'
end
}
tool_item {
image File.expand_path('./images/paste.png', __dir__), height: 16
on_widget_selected do
self.operation = 'Paste'
end
}
}
tool_bar {
tool_item {
text 'Font Size'
}
# a combo can be nested in a tool_bar (it auto-generates a tool_item for itself behind the scenes)
combo {
selection <=> [self, :font_size]
}
}
}
label {
font <= [self, :font_size, on_read: ->(size) { {height: size.to_i} }]
text <= [self, :operation]
text <= [self, :font_size]
}
}
}
end
HelloCoolBar.launch