glimmer-dsl-swt 4.18.5.3 → 4.18.6.2

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.
@@ -34,6 +34,7 @@ module Glimmer
34
34
  class Shape
35
35
  class Rectangle < Shape
36
36
  def parameter_names
37
+ # TODO consider optimizing just like text where it is set upon updating attribute and here you just return a variable
37
38
  if @args.to_a.size >= 6
38
39
  rectangle_round_parameter_names
39
40
  elsif @args.to_a.size == 5
@@ -81,11 +82,11 @@ module Glimmer
81
82
  end
82
83
 
83
84
  def point_xy_array
84
- [[x, y], [x + width, y], [x + width, y + height], [x, y + height]]
85
+ [[x, y], [x + calculated_width, y], [x + calculated_width, y + calculated_height], [x, y + calculated_height]]
85
86
  end
86
87
 
87
88
  def absolute_point_xy_array
88
- [[absolute_x, absolute_y], [absolute_x + width, absolute_y], [absolute_x + width, absolute_y + height], [absolute_x, absolute_y + height]]
89
+ [[absolute_x, absolute_y], [absolute_x + calculated_width, absolute_y], [absolute_x + calculated_width, absolute_y + calculated_height], [absolute_x, absolute_y + calculated_height]]
89
90
  end
90
91
 
91
92
  # checks if drawn or filled rectangle includes the point denoted by x and y (if drawn, it only returns true if point lies on the edge)
@@ -33,8 +33,6 @@ module Glimmer
33
33
  # That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
34
34
  class Shape
35
35
  class Text < Shape
36
- attr_accessor :extent
37
-
38
36
  def parameter_names
39
37
  @parameter_names || text_parameter_names
40
38
  end
@@ -69,11 +67,11 @@ module Glimmer
69
67
  end
70
68
 
71
69
  def width
72
- extent&.x
70
+ @extent&.x
73
71
  end
74
72
 
75
73
  def height
76
- extent&.y
74
+ @extent&.y
77
75
  end
78
76
 
79
77
  end
@@ -52,6 +52,10 @@ module Glimmer
52
52
  def dialog_class(keyword)
53
53
  the_class = eval(keyword.camelcase(:upper))
54
54
  the_class if the_class.ancestors.include?(org.eclipse.swt.widgets.Dialog)
55
+ rescue => e
56
+ Glimmer::Config.logger.debug {"Dialog for keyword #{keyword} not found!"}
57
+ Glimmer::Config.logger.debug { e.full_message }
58
+ nil
55
59
  end
56
60
  end
57
61
 
@@ -73,7 +73,7 @@ module Glimmer
73
73
  Glimmer::SWT::DisplayProxy.instance.auto_exec do
74
74
  result = if proxy_source_object&.respond_to?(attribute_setter(attribute_name))
75
75
  swt_widget_operation = true
76
- proxy_source_object&.send(attribute_setter(attribute_name), *args) unless proxy_source_object&.send(attribute_getter(attribute_name)) == args.first
76
+ proxy_source_object&.send(attribute_setter(attribute_name), *args) unless (proxy_source_object&.respond_to?(attribute_getter(attribute_name)) && proxy_source_object&.send(attribute_getter(attribute_name))) == args.first
77
77
  elsif proxy_source_object&.respond_to?(ruby_attribute_setter(attribute_name))
78
78
  swt_widget_operation = true
79
79
  proxy_source_object&.send(ruby_attribute_setter(attribute_name), args)
@@ -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.swt_widget.set_min_size(Point.new(@mandelbrot_image.bounds.width, @mandelbrot_image.bounds.height))
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,220 @@
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
+
150
+ @tab_folder = tab_folder {
151
+ @tabs.each do |tab|
152
+ tab_item {
153
+ grid_layout(2, false) {
154
+ margin_width 0
155
+ margin_height 0
156
+ }
157
+ text tab[:title]
158
+
159
+ tab[:canvas_header] = canvas {
160
+ layout_data(:center, :fill, false, true)
161
+ }
162
+ tab[:scrolled_composite] = scrolled_composite {
163
+ layout_data :fill, :fill, true, true
164
+ tab[:canvas] = canvas {
165
+ background :white
166
+
167
+ @stocks.count.times do |stock_index|
168
+ tab[:stock_paths][stock_index] = path {
169
+ antialias :on
170
+ foreground @stock_colors[stock_index]
171
+ }
172
+ end
173
+
174
+ on_mouse_down {
175
+ @drag_detected = false
176
+ }
177
+
178
+ on_drag_detected { |drag_detect_event|
179
+ @drag_detected = true
180
+ @drag_start_x = drag_detect_event.x
181
+ @drag_start_y = drag_detect_event.y
182
+ }
183
+
184
+ on_mouse_move { |mouse_event|
185
+ if @drag_detected
186
+ origin = tab[:scrolled_composite].origin
187
+ new_x = origin.x - (mouse_event.x - @drag_start_x)
188
+ new_y = origin.y - (mouse_event.y - @drag_start_y)
189
+ tab[:scrolled_composite].set_origin(new_x, new_y)
190
+ end
191
+ }
192
+
193
+ on_mouse_up { |mouse_event|
194
+ @drag_detected = false
195
+ }
196
+ }
197
+ }
198
+ }
199
+ end
200
+ }
201
+
202
+ on_swt_show {
203
+ Stock.price_min = 25
204
+ Stock.price_max = @tabs.first[:canvas].bounds.height - 6
205
+ # pre-initialize all tabs by selecting them so that they render content when they are later in the background
206
+ @tab_folder.items.each do |item|
207
+ @tab_folder.selection = item
208
+ end
209
+ @tab_folder.selection = @tab_folder.items.first
210
+ }
211
+
212
+ on_widget_disposed {
213
+ @thread.kill # safe to kill as data is in memory only
214
+ }
215
+ }
216
+ }
217
+ end
218
+
219
+ StockTicker.launch
220
+
@@ -25,9 +25,20 @@ class HelloCanvas
25
25
  include Glimmer::UI::CustomShell
26
26
 
27
27
  attr_accessor :selected_shape
28
+ attr_accessor :artist
28
29
 
29
30
  before_body {
30
31
  @image_object = image(File.expand_path('../../icons/scaffold_app.png', __dir__), width: 50)
32
+ @artist = ''
33
+ }
34
+
35
+ after_body {
36
+ Thread.new {
37
+ 'Picasso'.chars.each do |character|
38
+ sleep(1)
39
+ self.artist += character
40
+ end
41
+ }
31
42
  }
32
43
 
33
44
  body {
@@ -38,10 +49,36 @@ class HelloCanvas
38
49
  @canvas = canvas {
39
50
  background :yellow
40
51
  rectangle(0, 0, 220, 400) {
41
- background :red
52
+ background rgb(255, 0, 0)
42
53
  }
43
54
  rectangle(50, 20, 300, 150, 30, 50) {
44
55
  background :magenta
56
+ rectangle([:default, -70], :default, :default, [:default, 1]) {
57
+ foreground :cyan
58
+ text {
59
+ string bind(self, :artist)
60
+ x :default, 1 # add 1 pixel to default x (shape centered within parent horizontally)
61
+ y :default, 1 # add 1 pixel to default y (shape centered within parent vertically)
62
+ background :yellow
63
+ foreground :dark_magenta
64
+ font name: 'Courier', height: 30
65
+ }
66
+ }
67
+ rectangle(155, 30) { # width and height are assumed to be the default (calculated from children)
68
+ foreground :yellow
69
+ 3.times { |n|
70
+ line(45, 70 + n*10, 65 + n*10, 30 + n*10) {
71
+ foreground :yellow
72
+ }
73
+ }
74
+ 10.times {|n|
75
+ point(15 + n*5, 50 + n*5) {
76
+ foreground :yellow
77
+ }
78
+ }
79
+ polyline(45, 60, 55, 20, 65, 60, 85, 80, 45, 60)
80
+ image(@image_object, 0, 5)
81
+ }
45
82
  }
46
83
  rectangle(150, 200, 100, 70, true) {
47
84
  background :dark_magenta
@@ -51,26 +88,6 @@ class HelloCanvas
51
88
  background :magenta
52
89
  foreground :dark_blue
53
90
  }
54
- rectangle(205, 50, 88, 96) {
55
- foreground :yellow
56
- 3.times { |n|
57
- line(45, 70 + n*10, 65 + n*10, 30 + n*10) {
58
- foreground :yellow
59
- }
60
- }
61
- 10.times {|n|
62
- point(15 + n*5, 50 + n*5) {
63
- foreground :yellow
64
- }
65
- }
66
- polyline(45, 60, 55, 20, 65, 60, 85, 80, 45, 60)
67
- image(@image_object, 0, 5)
68
- }
69
- text('Picasso', 60, 80) {
70
- background :yellow
71
- foreground :dark_magenta
72
- font name: 'Courier', height: 30
73
- }
74
91
  oval(110, 310, 100, 100) {
75
92
  # patterns provide a differnet way to make gradients
76
93
  background_pattern 0, 0, 105, 0, :yellow, rgb(128, 138, 248)
@@ -0,0 +1,193 @@
1
+ require 'glimmer-dsl-swt'
2
+
3
+ class HelloCanvasDataBinding
4
+ include Glimmer::GUI::CustomWindow
5
+
6
+ CANVAS_WIDTH = 300
7
+ CANVAS_HEIGHT = 300
8
+
9
+ attr_accessor :x1_value, :y1_value, :x2_value, :y2_value, :foreground_red, :foreground_green, :foreground_blue, :line_width_value, :line_style_value
10
+
11
+ def foreground_value
12
+ rgb(foreground_red, foreground_green, foreground_blue)
13
+ end
14
+
15
+ def line_style_value_options
16
+ [:line_solid, :line_dash, :line_dot, :line_dashdot, :line_dashdotdot]
17
+ end
18
+
19
+ before_body {
20
+ self.x1_value = 0
21
+ self.y1_value = 0
22
+ self.x2_value = CANVAS_WIDTH
23
+ self.y2_value = CANVAS_HEIGHT
24
+ self.foreground_red = 28
25
+ self.foreground_green = 128
26
+ self.foreground_blue = 228
27
+ self.line_width_value = 3
28
+ self.line_style_value = :line_dot
29
+ }
30
+
31
+ body {
32
+ shell {
33
+ text 'Hello, Canvas Data-Binding!'
34
+
35
+ tab_folder {
36
+ tab_item {
37
+ grid_layout(6, true) {
38
+ margin_width 0
39
+ margin_height 0
40
+ horizontal_spacing 0
41
+ vertical_spacing 0
42
+ }
43
+ text 'line'
44
+
45
+ label {
46
+ layout_data(:fill, :center, false, false) {
47
+ horizontal_span 3
48
+ }
49
+ text 'x1'
50
+ }
51
+ label {
52
+ layout_data(:fill, :center, false, false) {
53
+ horizontal_span 3
54
+ }
55
+ text 'y1'
56
+ }
57
+ spinner {
58
+ layout_data(:fill, :center, false, false) {
59
+ horizontal_span 3
60
+ }
61
+ maximum CANVAS_WIDTH
62
+ increment 3
63
+ selection bind(self, :x1_value)
64
+ }
65
+ spinner {
66
+ layout_data(:fill, :center, false, false) {
67
+ horizontal_span 3
68
+ }
69
+ maximum CANVAS_HEIGHT
70
+ increment 3
71
+ selection bind(self, :y1_value)
72
+ }
73
+ label {
74
+ layout_data(:fill, :center, false, false) {
75
+ horizontal_span 3
76
+ }
77
+ text 'x2'
78
+ }
79
+ label {
80
+ layout_data(:fill, :center, false, false) {
81
+ horizontal_span 3
82
+ }
83
+ text 'y2'
84
+ }
85
+ spinner {
86
+ layout_data(:fill, :center, false, false) {
87
+ horizontal_span 3
88
+ }
89
+ maximum CANVAS_WIDTH
90
+ increment 3
91
+ selection bind(self, :x2_value)
92
+ }
93
+ spinner {
94
+ layout_data(:fill, :center, false, false) {
95
+ horizontal_span 3
96
+ }
97
+ maximum CANVAS_HEIGHT
98
+ increment 3
99
+ selection bind(self, :y2_value)
100
+ }
101
+ label {
102
+ layout_data(:fill, :center, false, false) {
103
+ horizontal_span 2
104
+ }
105
+ text 'foreground red'
106
+ }
107
+ label {
108
+ layout_data(:fill, :center, false, false) {
109
+ horizontal_span 2
110
+ }
111
+ text 'foreground green'
112
+ }
113
+ label {
114
+ layout_data(:fill, :center, false, false) {
115
+ horizontal_span 2
116
+ }
117
+ text 'foreground blue'
118
+ }
119
+ spinner {
120
+ layout_data(:fill, :center, false, false) {
121
+ horizontal_span 2
122
+ }
123
+ maximum 255
124
+ increment 10
125
+ selection bind(self, :foreground_red)
126
+ }
127
+ spinner {
128
+ layout_data(:fill, :center, false, false) {
129
+ horizontal_span 2
130
+ }
131
+ maximum 255
132
+ increment 10
133
+ selection bind(self, :foreground_green)
134
+ }
135
+ spinner {
136
+ layout_data(:fill, :center, false, false) {
137
+ horizontal_span 2
138
+ }
139
+ maximum 255
140
+ increment 10
141
+ selection bind(self, :foreground_blue)
142
+ }
143
+ label {
144
+ layout_data(:fill, :center, false, false) {
145
+ horizontal_span 3
146
+ }
147
+ text 'line width'
148
+ }
149
+ label {
150
+ layout_data(:fill, :center, false, false) {
151
+ horizontal_span 3
152
+ }
153
+ text 'line style'
154
+ }
155
+ spinner {
156
+ layout_data(:fill, :center, false, false) {
157
+ horizontal_span 3
158
+ }
159
+ maximum 255
160
+ selection bind(self, :line_width_value)
161
+ }
162
+ combo(:read_only) {
163
+ layout_data(:fill, :center, false, false) {
164
+ horizontal_span 3
165
+ }
166
+ selection bind(self, :line_style_value)
167
+ }
168
+ canvas {
169
+ layout_data(:center, :center, false, false) {
170
+ horizontal_span 6
171
+ width_hint CANVAS_WIDTH
172
+ height_hint CANVAS_WIDTH
173
+ }
174
+ background :white
175
+
176
+ line {
177
+ x1 bind(self, :x1_value)
178
+ y1 bind(self, :y1_value)
179
+ x2 bind(self, :x2_value)
180
+ y2 bind(self, :y2_value)
181
+ foreground bind(self, :foreground_value, computed_by: [:foreground_red, :foreground_green, :foreground_blue])
182
+ line_width bind(self, :line_width_value)
183
+ line_style bind(self, :line_style_value)
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
190
+
191
+ end
192
+
193
+ HelloCanvasDataBinding.launch