glimmer-dsl-swt 4.18.5.5 → 4.18.7.0
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 +42 -0
- data/README.md +4 -4
- data/VERSION +1 -1
- data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +95 -5
- data/docs/reference/GLIMMER_PACKAGING_AND_DISTRIBUTION.md +2 -0
- data/docs/reference/GLIMMER_SAMPLES.md +67 -0
- data/glimmer-dsl-swt.gemspec +18 -6
- data/lib/glimmer/dsl/swt/animation_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/custom_shape_expression.rb +61 -0
- data/lib/glimmer/dsl/swt/custom_widget_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/dsl.rb +1 -0
- data/lib/glimmer/dsl/swt/expand_item_expression.rb +4 -4
- data/lib/glimmer/dsl/swt/image_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/multiply_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/shape_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/transform_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/widget_expression.rb +2 -1
- data/lib/glimmer/swt/color_proxy.rb +1 -1
- data/lib/glimmer/swt/custom/shape.rb +173 -53
- data/lib/glimmer/swt/custom/shape/cubic.rb +118 -0
- data/lib/glimmer/swt/custom/shape/line.rb +47 -4
- data/lib/glimmer/swt/custom/shape/path.rb +240 -0
- data/lib/glimmer/swt/custom/shape/path_segment.rb +135 -0
- data/lib/glimmer/swt/custom/shape/point.rb +33 -0
- data/lib/glimmer/swt/custom/shape/polygon.rb +2 -2
- data/lib/glimmer/swt/custom/shape/quad.rb +114 -0
- data/lib/glimmer/swt/display_proxy.rb +1 -1
- data/lib/glimmer/swt/message_box_proxy.rb +1 -1
- data/lib/glimmer/swt/proxy_properties.rb +1 -1
- data/lib/glimmer/swt/shell_proxy.rb +1 -1
- data/lib/glimmer/swt/tab_folder_proxy.rb +52 -0
- data/lib/glimmer/swt/transform_proxy.rb +1 -1
- data/lib/glimmer/swt/widget_proxy.rb +1 -1
- data/lib/glimmer/ui/custom_shape.rb +281 -0
- data/samples/elaborate/mandelbrot_fractal.rb +1 -1
- data/samples/elaborate/stock_ticker.rb +214 -0
- data/samples/hello/hello_canvas.rb +3 -0
- data/samples/hello/hello_canvas_data_binding.rb +214 -0
- data/samples/hello/hello_canvas_path.rb +120 -0
- data/samples/hello/hello_custom_shape.rb +78 -0
- data/samples/hello/hello_shape.rb +71 -0
- metadata +16 -4
@@ -379,7 +379,7 @@ class MandelbrotFractal
|
|
379
379
|
image @mandelbrot_image
|
380
380
|
}
|
381
381
|
@canvas.set_size @mandelbrot_image.bounds.width, @mandelbrot_image.bounds.height
|
382
|
-
@scrolled_composite.
|
382
|
+
@scrolled_composite.set_min_size(Point.new(@mandelbrot_image.bounds.width, @mandelbrot_image.bounds.height))
|
383
383
|
if @location_x && @location_y
|
384
384
|
# center on mouse click location
|
385
385
|
factor = (zoom / last_zoom)
|
@@ -0,0 +1,214 @@
|
|
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
|
+
# This Sample is an Early Alpha (New Canvas Path DSL Feature)
|
25
|
+
|
26
|
+
class StockTicker
|
27
|
+
class Stock
|
28
|
+
class << self
|
29
|
+
attr_writer :price_min, :price_max
|
30
|
+
|
31
|
+
def price_min
|
32
|
+
@price_min ||= 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def price_max
|
36
|
+
@price_max ||= 600
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
attr_reader :name, :prices
|
41
|
+
attr_accessor :price
|
42
|
+
|
43
|
+
def initialize(name, price)
|
44
|
+
@name = name
|
45
|
+
@price = price
|
46
|
+
@prices = [@price]
|
47
|
+
@delta_sign = 1
|
48
|
+
start_new_trend!
|
49
|
+
end
|
50
|
+
|
51
|
+
def tick!
|
52
|
+
@tick_count = @tick_count.to_i + 1
|
53
|
+
delta = @tick_count%@trend_length
|
54
|
+
if delta == 0
|
55
|
+
@delta_sign *= -1
|
56
|
+
start_new_trend!
|
57
|
+
end
|
58
|
+
prices << self.price = [[@price + @delta_sign*delta, Stock.price_min].max, Stock.price_max].min
|
59
|
+
end
|
60
|
+
|
61
|
+
def start_new_trend!
|
62
|
+
@trend_length = (rand*12).to_i + 1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
include Glimmer::UI::CustomShell
|
67
|
+
|
68
|
+
before_body {
|
69
|
+
@stocks = [
|
70
|
+
Stock.new('DELL', 81),
|
71
|
+
Stock.new('AAPL', 121),
|
72
|
+
Stock.new('MSFT', 232),
|
73
|
+
Stock.new('ADBE', 459),
|
74
|
+
]
|
75
|
+
@stock_colors = [:red, :dark_green, :blue, :dark_magenta]
|
76
|
+
margin = 5
|
77
|
+
@tabs = ['Lines', 'Quadratic Bezier Curves', 'Cubic Bezier Curves', 'Points'].map {|title| {title: title, stock_paths: []}}
|
78
|
+
@stocks.each_with_index do |stock, stock_index|
|
79
|
+
observe(stock, :price) do |new_price|
|
80
|
+
begin
|
81
|
+
@tabs.each do |tab|
|
82
|
+
new_x = stock.prices.count - 1
|
83
|
+
new_y = @tabs.first[:canvas].bounds.height - new_price - 1
|
84
|
+
if new_x > 0
|
85
|
+
case tab[:title]
|
86
|
+
when 'Cubic Bezier Curves'
|
87
|
+
if new_x%3 == 0 && stock.prices[new_x] && stock.prices[new_x - 1] && stock.prices[new_x - 2]
|
88
|
+
tab[:stock_paths][stock_index].content {
|
89
|
+
cubic(new_x - 2 + margin, @tabs.first[:canvas].bounds.height - stock.prices[new_x - 2] - 1, new_x - 1 + margin, @tabs.first[:canvas].bounds.height - stock.prices[new_x - 1] - 1, new_x + margin, new_y)
|
90
|
+
}
|
91
|
+
end
|
92
|
+
when 'Quadratic Bezier Curves'
|
93
|
+
if new_x%2 == 0 && stock.prices[new_x] && stock.prices[new_x - 1]
|
94
|
+
tab[:stock_paths][stock_index].content {
|
95
|
+
quad(new_x - 1 + margin, @tabs.first[:canvas].bounds.height - stock.prices[new_x - 1] - 1, new_x + margin, new_y)
|
96
|
+
}
|
97
|
+
end
|
98
|
+
when 'Lines'
|
99
|
+
tab[:stock_paths][stock_index].content {
|
100
|
+
line(new_x + margin, new_y)
|
101
|
+
}
|
102
|
+
when 'Points'
|
103
|
+
tab[:stock_paths][stock_index].content {
|
104
|
+
point(new_x + margin, new_y)
|
105
|
+
}
|
106
|
+
end
|
107
|
+
new_x_location = new_x + 2*margin
|
108
|
+
canvas_width = tab[:canvas].bounds.width
|
109
|
+
if new_x_location > canvas_width
|
110
|
+
tab[:canvas].set_size(new_x_location, @tabs.first[:canvas].bounds.height)
|
111
|
+
tab[:canvas].cursor = :hand
|
112
|
+
tab[:scrolled_composite].set_min_size(new_x_location, @tabs.first[:canvas].bounds.height)
|
113
|
+
tab[:scrolled_composite].set_origin(tab[:scrolled_composite].origin.x + 1, tab[:scrolled_composite].origin.y) if (tab[:scrolled_composite].origin.x + tab[:scrolled_composite].client_area.width) == canvas_width
|
114
|
+
end
|
115
|
+
else
|
116
|
+
tab[:canvas_header].content {
|
117
|
+
text(stock.name, 15, new_y - 10) {
|
118
|
+
foreground @stock_colors[stock_index]
|
119
|
+
font height: 14
|
120
|
+
}
|
121
|
+
}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
rescue => e
|
125
|
+
Glimmer::Config.logger.error {e.full_message}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
}
|
130
|
+
|
131
|
+
after_body {
|
132
|
+
@thread = Thread.new {
|
133
|
+
loop {
|
134
|
+
@stocks.each(&:tick!)
|
135
|
+
sleep(0.01)
|
136
|
+
}
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
body {
|
141
|
+
shell {
|
142
|
+
fill_layout {
|
143
|
+
margin_width 15
|
144
|
+
margin_height 15
|
145
|
+
}
|
146
|
+
text 'Stock Ticker'
|
147
|
+
minimum_size 650, 650
|
148
|
+
background :white
|
149
|
+
@tab_folder = tab_folder {
|
150
|
+
@tabs.each do |tab|
|
151
|
+
tab_item {
|
152
|
+
grid_layout(2, false) {
|
153
|
+
margin_width 0
|
154
|
+
margin_height 0
|
155
|
+
}
|
156
|
+
text tab[:title]
|
157
|
+
|
158
|
+
tab[:canvas_header] = canvas {
|
159
|
+
layout_data(:center, :fill, false, true)
|
160
|
+
}
|
161
|
+
tab[:scrolled_composite] = scrolled_composite {
|
162
|
+
layout_data :fill, :fill, true, true
|
163
|
+
tab[:canvas] = canvas {
|
164
|
+
background :white
|
165
|
+
|
166
|
+
@stocks.count.times do |stock_index|
|
167
|
+
tab[:stock_paths][stock_index] = path {
|
168
|
+
antialias :on
|
169
|
+
foreground @stock_colors[stock_index]
|
170
|
+
}
|
171
|
+
end
|
172
|
+
|
173
|
+
on_mouse_down {
|
174
|
+
@drag_detected = false
|
175
|
+
}
|
176
|
+
|
177
|
+
on_drag_detected { |drag_detect_event|
|
178
|
+
@drag_detected = true
|
179
|
+
@drag_start_x = drag_detect_event.x
|
180
|
+
@drag_start_y = drag_detect_event.y
|
181
|
+
}
|
182
|
+
|
183
|
+
on_mouse_move { |mouse_event|
|
184
|
+
if @drag_detected
|
185
|
+
origin = tab[:scrolled_composite].origin
|
186
|
+
new_x = origin.x - (mouse_event.x - @drag_start_x)
|
187
|
+
new_y = origin.y - (mouse_event.y - @drag_start_y)
|
188
|
+
tab[:scrolled_composite].set_origin(new_x, new_y)
|
189
|
+
end
|
190
|
+
}
|
191
|
+
|
192
|
+
on_mouse_up { |mouse_event|
|
193
|
+
@drag_detected = false
|
194
|
+
}
|
195
|
+
}
|
196
|
+
}
|
197
|
+
}
|
198
|
+
end
|
199
|
+
}
|
200
|
+
|
201
|
+
on_swt_show {
|
202
|
+
Stock.price_min = 25
|
203
|
+
Stock.price_max = @tabs.first[:canvas].bounds.height - 6
|
204
|
+
}
|
205
|
+
|
206
|
+
on_widget_disposed {
|
207
|
+
@thread.kill # safe to kill as data is in memory only
|
208
|
+
}
|
209
|
+
}
|
210
|
+
}
|
211
|
+
end
|
212
|
+
|
213
|
+
StockTicker.launch
|
214
|
+
|
@@ -53,6 +53,9 @@ class HelloCanvas
|
|
53
53
|
}
|
54
54
|
rectangle(50, 20, 300, 150, 30, 50) {
|
55
55
|
background :magenta
|
56
|
+
rectangle(:default, :default, :max, :max, 30, 50) {
|
57
|
+
foreground :yellow
|
58
|
+
}
|
56
59
|
rectangle([:default, -70], :default, :default, [:default, 1]) {
|
57
60
|
foreground :cyan
|
58
61
|
text {
|
@@ -0,0 +1,214 @@
|
|
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 HelloCanvasDataBinding
|
25
|
+
include Glimmer::GUI::CustomWindow # alias for Glimmer::UI::CustomShell
|
26
|
+
|
27
|
+
CANVAS_WIDTH = 300
|
28
|
+
CANVAS_HEIGHT = 300
|
29
|
+
|
30
|
+
attr_accessor :x1_value, :y1_value, :x2_value, :y2_value, :foreground_red, :foreground_green, :foreground_blue, :line_width_value, :line_style_value
|
31
|
+
|
32
|
+
def foreground_value
|
33
|
+
rgb(foreground_red, foreground_green, foreground_blue)
|
34
|
+
end
|
35
|
+
|
36
|
+
def line_style_value_options
|
37
|
+
[:solid, :dash, :dot, :dashdot, :dashdotdot]
|
38
|
+
end
|
39
|
+
|
40
|
+
before_body {
|
41
|
+
self.x1_value = 0
|
42
|
+
self.y1_value = 0
|
43
|
+
self.x2_value = CANVAS_WIDTH
|
44
|
+
self.y2_value = CANVAS_HEIGHT
|
45
|
+
self.foreground_red = 28
|
46
|
+
self.foreground_green = 128
|
47
|
+
self.foreground_blue = 228
|
48
|
+
self.line_width_value = 3
|
49
|
+
self.line_style_value = :dot
|
50
|
+
}
|
51
|
+
|
52
|
+
body {
|
53
|
+
shell {
|
54
|
+
text 'Hello, Canvas Data-Binding!'
|
55
|
+
|
56
|
+
tab_folder {
|
57
|
+
tab_item {
|
58
|
+
grid_layout(6, true) {
|
59
|
+
margin_width 0
|
60
|
+
margin_height 0
|
61
|
+
horizontal_spacing 0
|
62
|
+
vertical_spacing 0
|
63
|
+
}
|
64
|
+
text 'line'
|
65
|
+
|
66
|
+
label {
|
67
|
+
layout_data(:fill, :center, false, false) {
|
68
|
+
horizontal_span 3
|
69
|
+
}
|
70
|
+
text 'x1'
|
71
|
+
}
|
72
|
+
label {
|
73
|
+
layout_data(:fill, :center, false, false) {
|
74
|
+
horizontal_span 3
|
75
|
+
}
|
76
|
+
text 'y1'
|
77
|
+
}
|
78
|
+
spinner {
|
79
|
+
layout_data(:fill, :center, false, false) {
|
80
|
+
horizontal_span 3
|
81
|
+
}
|
82
|
+
maximum CANVAS_WIDTH
|
83
|
+
increment 3
|
84
|
+
selection bind(self, :x1_value)
|
85
|
+
}
|
86
|
+
spinner {
|
87
|
+
layout_data(:fill, :center, false, false) {
|
88
|
+
horizontal_span 3
|
89
|
+
}
|
90
|
+
maximum CANVAS_HEIGHT
|
91
|
+
increment 3
|
92
|
+
selection bind(self, :y1_value)
|
93
|
+
}
|
94
|
+
label {
|
95
|
+
layout_data(:fill, :center, false, false) {
|
96
|
+
horizontal_span 3
|
97
|
+
}
|
98
|
+
text 'x2'
|
99
|
+
}
|
100
|
+
label {
|
101
|
+
layout_data(:fill, :center, false, false) {
|
102
|
+
horizontal_span 3
|
103
|
+
}
|
104
|
+
text 'y2'
|
105
|
+
}
|
106
|
+
spinner {
|
107
|
+
layout_data(:fill, :center, false, false) {
|
108
|
+
horizontal_span 3
|
109
|
+
}
|
110
|
+
maximum CANVAS_WIDTH
|
111
|
+
increment 3
|
112
|
+
selection bind(self, :x2_value)
|
113
|
+
}
|
114
|
+
spinner {
|
115
|
+
layout_data(:fill, :center, false, false) {
|
116
|
+
horizontal_span 3
|
117
|
+
}
|
118
|
+
maximum CANVAS_HEIGHT
|
119
|
+
increment 3
|
120
|
+
selection bind(self, :y2_value)
|
121
|
+
}
|
122
|
+
label {
|
123
|
+
layout_data(:fill, :center, false, false) {
|
124
|
+
horizontal_span 2
|
125
|
+
}
|
126
|
+
text 'foreground red'
|
127
|
+
}
|
128
|
+
label {
|
129
|
+
layout_data(:fill, :center, false, false) {
|
130
|
+
horizontal_span 2
|
131
|
+
}
|
132
|
+
text 'foreground green'
|
133
|
+
}
|
134
|
+
label {
|
135
|
+
layout_data(:fill, :center, false, false) {
|
136
|
+
horizontal_span 2
|
137
|
+
}
|
138
|
+
text 'foreground blue'
|
139
|
+
}
|
140
|
+
spinner {
|
141
|
+
layout_data(:fill, :center, false, false) {
|
142
|
+
horizontal_span 2
|
143
|
+
}
|
144
|
+
maximum 255
|
145
|
+
increment 10
|
146
|
+
selection bind(self, :foreground_red)
|
147
|
+
}
|
148
|
+
spinner {
|
149
|
+
layout_data(:fill, :center, false, false) {
|
150
|
+
horizontal_span 2
|
151
|
+
}
|
152
|
+
maximum 255
|
153
|
+
increment 10
|
154
|
+
selection bind(self, :foreground_green)
|
155
|
+
}
|
156
|
+
spinner {
|
157
|
+
layout_data(:fill, :center, false, false) {
|
158
|
+
horizontal_span 2
|
159
|
+
}
|
160
|
+
maximum 255
|
161
|
+
increment 10
|
162
|
+
selection bind(self, :foreground_blue)
|
163
|
+
}
|
164
|
+
label {
|
165
|
+
layout_data(:fill, :center, false, false) {
|
166
|
+
horizontal_span 3
|
167
|
+
}
|
168
|
+
text 'line width'
|
169
|
+
}
|
170
|
+
label {
|
171
|
+
layout_data(:fill, :center, false, false) {
|
172
|
+
horizontal_span 3
|
173
|
+
}
|
174
|
+
text 'line style'
|
175
|
+
}
|
176
|
+
spinner {
|
177
|
+
layout_data(:fill, :center, false, false) {
|
178
|
+
horizontal_span 3
|
179
|
+
}
|
180
|
+
maximum 255
|
181
|
+
selection bind(self, :line_width_value)
|
182
|
+
}
|
183
|
+
combo(:read_only) {
|
184
|
+
layout_data(:fill, :center, false, false) {
|
185
|
+
horizontal_span 3
|
186
|
+
}
|
187
|
+
selection bind(self, :line_style_value)
|
188
|
+
}
|
189
|
+
canvas {
|
190
|
+
layout_data(:center, :center, false, false) {
|
191
|
+
horizontal_span 6
|
192
|
+
width_hint CANVAS_WIDTH
|
193
|
+
height_hint CANVAS_WIDTH
|
194
|
+
}
|
195
|
+
background :white
|
196
|
+
|
197
|
+
line {
|
198
|
+
x1 bind(self, :x1_value)
|
199
|
+
y1 bind(self, :y1_value)
|
200
|
+
x2 bind(self, :x2_value)
|
201
|
+
y2 bind(self, :y2_value)
|
202
|
+
foreground bind(self, :foreground_value, computed_by: [:foreground_red, :foreground_green, :foreground_blue])
|
203
|
+
line_width bind(self, :line_width_value)
|
204
|
+
line_style bind(self, :line_style_value)
|
205
|
+
}
|
206
|
+
}
|
207
|
+
}
|
208
|
+
}
|
209
|
+
}
|
210
|
+
}
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
HelloCanvasDataBinding.launch
|