glimmer-dsl-swt 4.20.11.1 → 4.20.12.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83a247e9e977044f7294fcf2430d1ec527f15e0c46b372d0e8c2e91cfbb36321
4
- data.tar.gz: 269d918b90ac0b565a27d71a17dfd7b01194e2df6f18c76a2c5b77d496b45202
3
+ metadata.gz: 0373a7dc65537a71945ca562aec3612f9acb7762ce04a54efb64deb3b4089c7f
4
+ data.tar.gz: 77fdddc56f1571a426b9786d6ab5343ab400d9a61efc92644ab62482085f3ce2
5
5
  SHA512:
6
- metadata.gz: 033fb29c9fb0bc37ac6786bb33610ee550628a5def123af28b9c732477329edcb13bca3008581c117fd3751bda9e6c953ac4f69bff319f91848be177dac45d77
7
- data.tar.gz: d286000814adaf8794105b357fbeec08cef2d202436930b64848f914d99eb1bfe27fffd03b51a430495174018ebdae54fb26165a18ca42cf8e8ecfd4bf5b3694
6
+ metadata.gz: baf76febcbe0b29e675c411fa4301cdc1b1ad7b3168a2f63ba91bfdd89a1ac2e8ae35eacebabdeb317bd6b68cbedefeaffc4e2b66e0e460cd2a704f20064c69f
7
+ data.tar.gz: cf93ef1f0efd3ad957c219a8024003c948d9f5c2fc6f260547ccf089786463624287e2648773c3992095dfa38ba0589d95fdf8cfaef2161c71b3d05971870978
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Change Log
2
2
 
3
+ ### 4.20.12.3
4
+
5
+ - Make Custom Shapes support on_event listeners just like Shapes
6
+ - Update Hello, Custom Shape! to take advantage of custom shape listeners (on mouse click, change color)
7
+
8
+ ### 4.20.12.2
9
+
10
+ - Make Shape listeners check inclusion against all sub-shapes
11
+ - Refactor Hello, Canvas Drag & Drop! sample to use composite shapes (e.g. ball containing a ball border)
12
+
13
+ ### 4.20.12.1
14
+
15
+ - Hello, Canvas Drag & Drop! sample
16
+
17
+ ### 4.20.12.0
18
+
19
+ - Canvas Shape Listeners: on_mouse_up, on_mouse_down, on_mouse_move, on_drag_detected
20
+ - Make scaffolding not generate an empty () after shell
21
+ - Hello, Canvas Shape Listeners! Sample
22
+
3
23
  ### 4.20.11.1
4
24
 
5
25
  - Make scaffolded app project use bundler optionally only and still load glimmer-dsl-swt otherwise, like in gem-packaged mode (`glimmer package:gem`) to avoid erroring out about bundler.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 4.20.11.1
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 4.20.12.3
2
2
  ## JRuby Desktop Development GUI Framework
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
4
4
  [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
@@ -15,7 +15,7 @@
15
15
  [<img src="https://covers.oreillystatic.com/images/9780596519650/lrg.jpg" width=105 /><br />
16
16
  Featured in JRuby Cookbook](http://shop.oreilly.com/product/9780596519650.do) and [Chalmers/Gothenburg University Software Engineering Master's Lecture Material](http://www.cse.chalmers.se/~bergert/slides/guest_lecture_DSLs.pdf)
17
17
 
18
- [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.11.1 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (report any issues you may encounter).
18
+ [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.12.3 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (report any issues you may encounter).
19
19
 
20
20
  **Starting in version 4.20.0.0, [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) comes with the new [***Shine***](/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#shine) syntax** for highly intuitive and visually expressive View/Model Attribute Mapping, relying on `<=>` for bidirectional (two-way) data-binding and `<=` for unidirectional (one-way) data-binding, providing an alternative to the `bind` keyword (keep in mind that it is still a beta, so default back to `bind` whenever needed).
21
21
 
@@ -45,12 +45,6 @@ shell {
45
45
  }.open
46
46
  ```
47
47
 
48
- Run via `glimmer samples` or directly:
49
-
50
- ```
51
- glimmer samples/hello/hello_world.rb
52
- ```
53
-
54
48
  Glimmer app:
55
49
 
56
50
  ![Hello World](images/glimmer-hello-world.png)
@@ -62,25 +56,25 @@ Learn more about [Hello, World!](docs/reference/GLIMMER_SAMPLES#hello-world).
62
56
  Glimmer GUI DSL code (from [samples/hello/hello_table.rb](samples/hello/hello_table.rb)):
63
57
 
64
58
  ```ruby
65
- # ... model code precedes
66
59
  shell {
67
60
  grid_layout
68
61
 
69
62
  text 'Hello, Table!'
70
63
  background_image File.expand_path('hello_table/baseball_park.png', __dir__)
64
+ image File.expand_path('hello_table/baseball_park.png', __dir__)
71
65
 
72
66
  label {
73
67
  layout_data :center, :center, true, false
74
68
 
75
69
  text 'BASEBALL PLAYOFF SCHEDULE'
76
- background :transparent
70
+ background :transparent if OS.windows?
77
71
  foreground rgb(94, 107, 103)
78
72
  font name: 'Optima', height: 38, style: :bold
79
73
  }
80
74
 
81
75
  combo(:read_only) {
82
76
  layout_data :center, :center, true, false
83
- selection bind(BaseballGame, :playoff_type)
77
+ selection <=> [BaseballGame, :playoff_type]
84
78
  font height: 14
85
79
  }
86
80
 
@@ -121,10 +115,10 @@ shell {
121
115
  }
122
116
 
123
117
  # Data-bind table items (rows) to a model collection property, specifying column properties ordering per nested model
124
- items bind(BaseballGame, :schedule), column_properties(:game_date, :game_time, :ballpark, :home_team, :away_team, :promotion)
118
+ items <=> [BaseballGame, :schedule, column_properties: [:game_date, :game_time, :ballpark, :home_team, :away_team, :promotion]]
125
119
 
126
120
  # Data-bind table selection
127
- selection bind(BaseballGame, :selected_game)
121
+ selection <=> [BaseballGame, :selected_game]
128
122
 
129
123
  # Default initial sort property
130
124
  sort_property :date
@@ -147,20 +141,13 @@ shell {
147
141
  text 'Book Selected Game'
148
142
  layout_data :center, :center, true, false
149
143
  font height: 14
150
- enabled bind(BaseballGame, :selected_game)
144
+ enabled <= [BaseballGame, :selected_game]
151
145
 
152
146
  on_widget_selected {
153
147
  book_selected_game
154
148
  }
155
149
  }
156
- }.open
157
- # ...
158
- ```
159
-
160
- Run via `glimmer samples` or directly:
161
-
162
- ```
163
- glimmer samples/hello/hello_table.rb
150
+ }
164
151
  ```
165
152
 
166
153
  Glimmer App:
@@ -174,7 +161,6 @@ Learn more about [Hello, Table!](docs/reference/GLIMMER_SAMPLES#hello-table).
174
161
  Glimmer GUI DSL code (from [samples/elaborate/tetris.rb](samples/elaborate/tetris.rb)):
175
162
 
176
163
  ```ruby
177
- # ... more code resides in other files (navigate sample files to learn more)
178
164
  shell(:no_resize) {
179
165
  grid_layout {
180
166
  num_columns 2
@@ -196,13 +182,6 @@ shell(:no_resize) {
196
182
  layout_data(:fill, :fill, true, true)
197
183
  }
198
184
  }
199
- # ...
200
- ```
201
-
202
- Run via `glimmer samples` or directly:
203
-
204
- ```
205
- glimmer samples/elaborate/tetris.rb
206
185
  ```
207
186
 
208
187
  Glimmer app:
@@ -347,7 +326,7 @@ jgem install glimmer-dsl-swt
347
326
 
348
327
  Or this command if you want a specific version:
349
328
  ```
350
- jgem install glimmer-dsl-swt -v 4.20.11.1
329
+ jgem install glimmer-dsl-swt -v 4.20.12.3
351
330
  ```
352
331
 
353
332
  `jgem` is JRuby's version of `gem` command.
@@ -375,7 +354,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
375
354
 
376
355
  Add the following to `Gemfile`:
377
356
  ```
378
- gem 'glimmer-dsl-swt', '~> 4.20.11.1'
357
+ gem 'glimmer-dsl-swt', '~> 4.20.12.3'
379
358
  ```
380
359
 
381
360
  And, then run:
@@ -396,7 +375,7 @@ glimmer
396
375
  ```
397
376
 
398
377
  ```
399
- Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.11.1
378
+ Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.12.3
400
379
 
401
380
  Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
402
381
 
@@ -443,7 +422,9 @@ Select a Glimmer task to run: (Press ↑/↓ arrow to move, Enter to select and
443
422
  glimmer scaffold:gem:customwidget[name,namespace] # Scaffold Glimmer::UI::CustomWidget subclass (part of a view) under its own Ruby gem project (namespace is required) [alt: scaffold:gem:cw]
444
423
  ```
445
424
 
446
- Learn more at: [docs/reference/GLIMMER_COMMAND.md](docs/reference/GLIMMER_COMMAND.md)
425
+ Learn more at:
426
+
427
+ [docs/reference/GLIMMER_COMMAND.md](docs/reference/GLIMMER_COMMAND.md)
447
428
 
448
429
  ## Girb (Glimmer irb) Command
449
430
 
@@ -455,7 +436,9 @@ girb
455
436
 
456
437
  ![GIRB](/images/glimmer-girb.png)
457
438
 
458
- Learn more at: [docs/reference/GLIMMER_GIRB.md](docs/reference/GLIMMER_GIRB.md)
439
+ Learn more at:
440
+
441
+ [docs/reference/GLIMMER_GIRB.md](docs/reference/GLIMMER_GIRB.md)
459
442
 
460
443
  ## Glimmer GUI DSL Syntax
461
444
 
@@ -495,13 +478,17 @@ table(:multi) {
495
478
 
496
479
  If you need more widgets, you can check out the [Nebula Project](https://github.com/AndyObtiva/glimmer-cw-nebula) (50+ enterprise-grade custom widgets)
497
480
 
498
- Learn more at: [docs/reference/GLIMMER_GUI_DSL_SYNTAX.md](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md)
481
+ Learn more at:
482
+
483
+ [docs/reference/GLIMMER_GUI_DSL_SYNTAX.md](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md)
499
484
 
500
485
  ## Glimmer Configuration
501
486
 
502
487
  Glimmer configuration may be done via the `Glimmer::Config` module.
503
488
 
504
- Learn more at: [docs/reference/GLIMMER_CONFIGURATION.md](docs/reference/GLIMMER_CONFIGURATION.md)
489
+ Learn more at:
490
+
491
+ [docs/reference/GLIMMER_CONFIGURATION.md](docs/reference/GLIMMER_CONFIGURATION.md)
505
492
 
506
493
  ## Glimmer Style Guide
507
494
 
@@ -509,6 +496,10 @@ Learn more at: [docs/reference/GLIMMER_CONFIGURATION.md](docs/reference/GLIMMER_
509
496
 
510
497
  ## Samples
511
498
 
499
+ See a listing of samples including screenshots and explanations at:
500
+
501
+ [docs/reference/GLIMMER_SAMPLES.md](/docs/reference/GLIMMER_SAMPLES.md)
502
+
512
503
  Check the [samples](/docs/reference/GLIMMER_SAMPLES.md) directory in [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) for examples on how to write Glimmer applications. To run a sample, make sure to install the `glimmer-dsl-swt` gem first and then run:
513
504
  ```
514
505
  glimmer samples
@@ -518,8 +509,6 @@ glimmer samples
518
509
 
519
510
  ![Glimmer Meta-Sample](/images/glimmer-meta-sample.png)
520
511
 
521
- See a listing of samples including screenshots and explanations at: [docs/reference/GLIMMER_SAMPLES.md](/docs/reference/GLIMMER_SAMPLES.md)
522
-
523
512
  ## In Production
524
513
 
525
514
  The following production apps have been built with Glimmer.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.20.11.1
1
+ 4.20.12.3
@@ -44,6 +44,8 @@
44
44
  - [Hello, Canvas Transform!](#hello-canvas-transform)
45
45
  - [Hello, Canvas Path!](#hello-canvas-path)
46
46
  - [Hello, Canvas Data Binding!](#hello-canvas-data-binding)
47
+ - [Hello, Canvas Shape Listeners!](#hello-canvas-shape-listeners)
48
+ - [Hello, Canvas Drag and Drop!](#hello-canvas-drag-and-drop)
47
49
  - [Hello, Cursor!](#hello-cursor)
48
50
  - [Hello, Progress Bar!](#hello-progress-bar)
49
51
  - [Hello, Tree!](#hello-tree)
@@ -816,6 +818,32 @@ Hello, Canvas Data Binding!
816
818
 
817
819
  ![Hello Canvas Data Binding Line Changed](/images/glimmer-hello-canvas-data-binding-line-changed.png)
818
820
 
821
+ #### Hello, Canvas Shape Listeners!
822
+
823
+ This sample demonstrates Canvas Shape DSL listeners, which are constrained within the bounds of their owning shape.
824
+
825
+ Code:
826
+
827
+ [samples/hello/hello_canvas_shape_listeners.rb](/samples/hello/hello_canvas_shape_listeners.rb)
828
+
829
+ Hello, Canvas Shape Listeners!
830
+
831
+ ![Hello Canvas Shape Listeners](/images/glimmer-hello-canvas-shape-listeners.png)
832
+
833
+ Hello, Canvas Shape Listeners! - Dragged Circle
834
+
835
+ ![Hello Canvas Shape Listeners Dragged](/images/glimmer-hello-canvas-shape-listeners-dragged.png)
836
+
837
+ #### Hello, Canvas Drag and Drop!
838
+
839
+ This sample demonstrates Canvas Shape DSL drag and drop (different from standard widget drag and drop).
840
+
841
+ Code:
842
+
843
+ [samples/hello/hello_canvas_drag_and_drop.rb](/samples/hello/hello_canvas_drag_and_drop.rb)
844
+
845
+ ![Hello Canvas Drag and Drop](/images/glimmer-hello-canvas-drag-and-drop.gif)
846
+
819
847
  #### Hello, Cursor!
820
848
 
821
849
  This sample demonstrates the use of the `cursor` property keyword to change the mouse cursor.
Binary file
@@ -39,7 +39,7 @@ module Glimmer
39
39
  SWT,
40
40
  %w[
41
41
  layout
42
- widget_listener
42
+ listener
43
43
  combo_selection_data_binding
44
44
  checkbox_group_selection_data_binding
45
45
  radio_group_selection_data_binding
@@ -21,19 +21,20 @@
21
21
 
22
22
  require 'glimmer/dsl/expression'
23
23
  require 'glimmer/swt/display_proxy'
24
+ require 'glimmer/swt/custom/shape'
25
+ require 'glimmer/ui/custom_shape'
24
26
 
25
27
  module Glimmer
26
28
  module DSL
27
29
  module SWT
28
- class WidgetListenerExpression < Expression
29
- include_package 'org.eclipse.swt.widgets'
30
-
30
+ # Widget, Shape, and Display listener experssion
31
+ class ListenerExpression < Expression
31
32
  def can_interpret?(parent, keyword, *args, &block)
32
33
  Glimmer::Config.logger.debug {"keyword starts with on_: #{keyword.start_with?('on_')}"}
33
34
  return false unless keyword.start_with?('on_')
34
- widget_or_display_parentage = parent.respond_to?(:swt_widget) || parent.is_a?(Glimmer::SWT::DisplayProxy)
35
- Glimmer::Config.logger.debug {"parent #{parent} is a widget or display: #{widget_or_display_parentage}"}
36
- return false unless widget_or_display_parentage
35
+ proper_parent = parent.respond_to?(:swt_widget) || parent.is_a?(Glimmer::SWT::DisplayProxy) || parent.is_a?(Glimmer::SWT::Custom::Shape) || parent.is_a?(Glimmer::UI::CustomShape)
36
+ Glimmer::Config.logger.debug {"parent #{parent} is a widget, shape, or display: #{proper_parent}"}
37
+ return false unless proper_parent
37
38
  Glimmer::Config.logger.debug {"block exists?: #{!block.nil?}"}
38
39
  raise Glimmer::Error, "Listener is missing block for keyword: #{keyword}" unless block_given?
39
40
  Glimmer::Config.logger.debug {"args are empty?: #{args.empty?}"}
@@ -640,7 +640,7 @@ module Glimmer
640
640
  ## Top-most widget must be a shell or another custom shell
641
641
  #
642
642
  body {
643
- shell(#{':fill_screen' if shell_type == :desktopify}) {
643
+ shell#{'(:fill_screen)' if shell_type == :desktopify} {
644
644
  # Replace example content below with custom shell content
645
645
  minimum_size #{shell_type == :desktopify ? '768, 432' : '420, 240'}
646
646
  image File.join(APP_ROOT, 'package', 'windows', "#{human_name(shell_type == :gem ? custom_shell_name : current_dir_name)}.ico") if OS.windows?
@@ -239,6 +239,7 @@ module Glimmer
239
239
  end
240
240
  end
241
241
  end
242
+ alias translate move_by
242
243
 
243
244
  # rotates shape for an angle around its center
244
245
  # this operation is not cumulative (it resets angle every time)
@@ -508,6 +509,7 @@ module Glimmer
508
509
  def set_attribute(attribute_name, *args)
509
510
  options = args.last if args.last.is_a?(Hash)
510
511
  args.pop if !options.nil? && !options[:redraw].nil?
512
+ options ||= {}
511
513
  perform_redraw = @perform_redraw
512
514
  perform_redraw = options[:redraw] if perform_redraw.nil? && !options.nil?
513
515
  perform_redraw ||= true
@@ -528,11 +530,12 @@ module Glimmer
528
530
  @properties[ruby_attribute_getter_name] = args
529
531
  amend_method_name_options_based_on_properties! if @content_added && new_property
530
532
  property_change = true
533
+ calculated_paint_args_changed! if container?
531
534
  end
532
535
  if @content_added && perform_redraw && !drawable.is_disposed
533
536
  redrawn = false
534
537
  unless property_change
535
- @calculated_paint_args = false
538
+ calculated_paint_args_changed!(children: false)
536
539
  if is_a?(PathSegment)
537
540
  root_path&.calculated_path_args = @calculated_path_args = false
538
541
  calculated_args_changed!
@@ -548,7 +551,7 @@ module Glimmer
548
551
  end
549
552
  # TODO consider redrawing an image proxy's gc in the future
550
553
  # TODO consider ensuring only a single redraw happens for a hierarchy of nested shapes
551
- drawable.redraw unless redrawn || drawable.is_a?(ImageProxy)
554
+ drawable.redraw if !redrawn && !drawable.is_a?(ImageProxy)
552
555
  end
553
556
  end
554
557
 
@@ -563,6 +566,19 @@ module Glimmer
563
566
  end
564
567
  end
565
568
 
569
+ def can_handle_observation_request?(observation_request)
570
+ drawable.can_handle_observation_request?(observation_request)
571
+ end
572
+
573
+ def handle_observation_request(observation_request, &block)
574
+ shape_block = lambda do |event|
575
+ included = include?(event.x, event.y)
576
+ included ||= expanded_shapes.detect { |shape| shape.include?(event.x, event.y) }
577
+ block.call(event) if included
578
+ end
579
+ drawable.handle_observation_request(observation_request, &shape_block)
580
+ end
581
+
566
582
  # Sets data just like SWT widgets
567
583
  def set_data(key=nil, value)
568
584
  @data ||= {}
@@ -776,7 +792,7 @@ module Glimmer
776
792
  extent_args << extent_flags unless extent_flags.nil?
777
793
  self.extent = paint_event.gc.send("#{@name}Extent", *extent_args)
778
794
  end
779
- if !@extent.nil? && (old_extent&.x != @extent&.x || old_extent&.y != @extent&.y)
795
+ if !@extent.nil? && (old_extent&.x != @extent&.x || old_extent&.y != @extent&.y) # TODO add a check to text content changing too
780
796
  calculated_args_changed!
781
797
  parent.calculated_args_changed_for_defaults! if parent.is_a?(Shape)
782
798
  end
@@ -798,6 +814,12 @@ module Glimmer
798
814
  shapes.each(&:calculated_args_changed!) if children
799
815
  end
800
816
 
817
+ def calculated_paint_args_changed!(children: true)
818
+ @calculated_paint_args = nil
819
+ @all_parent_properties = nil
820
+ shapes.each(&:calculated_paint_args_changed!) if children
821
+ end
822
+
801
823
  # Notifies object that calculated args changed for defaults. Returns true if redrawing and false otherwise.
802
824
  def calculated_args_changed_for_defaults!
803
825
  has_default_dimensions = default_width? || default_height?
@@ -1191,7 +1213,8 @@ module Glimmer
1191
1213
  end
1192
1214
  end
1193
1215
  else
1194
- @properties = all_parent_properties.merge(@properties)
1216
+ @original_properties ||= @properties
1217
+ @properties = all_parent_properties.merge(@original_properties)
1195
1218
  @properties['background'] = [@drawable.background] if fill? && !has_some_background?
1196
1219
  @properties['foreground'] = [@drawable.foreground] if @drawable.respond_to?(:foreground) && draw? && !has_some_foreground?
1197
1220
  # TODO regarding alpha, make sure to reset it to parent stored alpha once we allow setting shape properties on parents directly without shapes
@@ -180,7 +180,7 @@ module Glimmer
180
180
  raise Glimmer::Error, 'Invalid custom shape for having no body! Please define body block!' if body_block.nil?
181
181
  @body_root = instance_exec(&body_block)
182
182
  raise Glimmer::Error, 'Invalid custom shape for having an empty body! Please fill body block!' if @body_root.nil?
183
- auto_exec do
183
+ auto_exec do # TODO is this necessary given shape is a lightweight construct (not SWT widget) ?
184
184
  @body_root.set_data('custom_shape', self)
185
185
  end
186
186
  execute_hook('after_body')
@@ -254,6 +254,16 @@ module Glimmer
254
254
  end
255
255
  end
256
256
 
257
+ # TODO consider bringing observer_registrations method from CustomWidget if needed
258
+
259
+ def can_handle_observation_request?(observation_request)
260
+ body_root&.can_handle_observation_request?(observation_request)
261
+ end
262
+
263
+ def handle_observation_request(observation_request, &block)
264
+ body_root.handle_observation_request(observation_request, &block)
265
+ end
266
+
257
267
  def method_missing(method, *args, &block)
258
268
  # TODO Consider supporting a glimmer error silencing option for methods defined here
259
269
  # but fail the glimmer DSL for the right reason to avoid seeing noise in the log output
@@ -0,0 +1,101 @@
1
+ require 'glimmer-dsl-swt'
2
+
3
+ class HelloCanvasDragAndDrop
4
+ include Glimmer::UI::CustomShell
5
+
6
+ body {
7
+ shell {
8
+ row_layout(:vertical) {
9
+ margin_width 0
10
+ margin_height 0
11
+ fill true
12
+ center true
13
+ }
14
+ text 'Hello, Canvas Drag & Drop!'
15
+
16
+ label(:center) {
17
+ text 'Drag orange balls and drop in the square.'
18
+ font height: 16
19
+ }
20
+
21
+ canvas {
22
+ layout_data {
23
+ width 350
24
+ height 350
25
+ }
26
+
27
+ background :white
28
+
29
+ @drop_square = rectangle(150, 260, 50, 50) {
30
+ background :white
31
+
32
+ # unspecified width and height become max width and max height by default
33
+ @drop_square_border = rectangle(0, 0) {
34
+ foreground :black
35
+ line_width 3
36
+ line_style :dash
37
+ }
38
+
39
+ @number_shape = text {
40
+ x :default
41
+ y :default
42
+ string '0'
43
+ }
44
+
45
+ on_mouse_move do
46
+ if @dragging
47
+ @drop_square_border.foreground = :red
48
+ end
49
+ end
50
+
51
+ on_mouse_up do
52
+ if @dragging
53
+ ball_count = @number_shape.string.to_i
54
+ @number_shape.dispose
55
+ @drop_square.content {
56
+ @number_shape = text {
57
+ x :default
58
+ y :default
59
+ string (ball_count + 1).to_s
60
+ }
61
+ }
62
+ @dragging.dispose
63
+ end
64
+ end
65
+ }
66
+
67
+ 10.times do |n|
68
+ an_oval = oval((rand*300).to_i, (rand*200).to_i, 50, 50) {
69
+ background rgb(255, 165, 0)
70
+
71
+ # unspecified width and height become max width and max height by default
72
+ oval(0, 0) {
73
+ foreground :black
74
+ }
75
+
76
+ on_drag_detected do |event|
77
+ @dragging = an_oval
78
+ @last_x = event.x
79
+ @last_y = event.y
80
+ end
81
+ }
82
+ end
83
+
84
+ on_mouse_up do
85
+ @drop_square_border.foreground = :black
86
+ @dragging = nil
87
+ end
88
+
89
+ on_mouse_move do |event|
90
+ if @dragging
91
+ @dragging.move_by((event.x - @last_x), (event.y - @last_y))
92
+ @last_x = event.x
93
+ @last_y = event.y
94
+ end
95
+ end
96
+ }
97
+ }
98
+ }
99
+ end
100
+
101
+ HelloCanvasDragAndDrop.launch
@@ -0,0 +1,171 @@
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 HelloCanvasShapeListeners
25
+ include Glimmer::UI::CustomShell
26
+
27
+ attr_accessor :shape_name, :listener_event, :dragged_shape
28
+
29
+ body {
30
+ shell {
31
+ row_layout(:vertical) {
32
+ fill true
33
+ center true
34
+ margin_width 0
35
+ margin_height 0
36
+ }
37
+
38
+ text 'Hello, Canvas Shape Listeners!'
39
+
40
+ label(:center) {
41
+ text 'Current Shape:'
42
+ font style: :bold
43
+ }
44
+ label(:center) {
45
+ text <= [self, :shape_name]
46
+ }
47
+
48
+ label(:center) {
49
+ text 'Current Event:'
50
+ font style: :bold
51
+ }
52
+ label(:center) {
53
+ text <= [self, :listener_event]
54
+ }
55
+
56
+ canvas { |canvas_proxy|
57
+ layout_data {
58
+ width 350
59
+ height 200
60
+ }
61
+
62
+ background :white
63
+
64
+ @rectangle = rectangle(25, 25, 50, 50) {
65
+ background :red
66
+
67
+ # these listener events are limited to the rectangle bounds
68
+
69
+ on_mouse_down do |event|
70
+ self.shape_name = 'Square'
71
+ self.listener_event = 'Mouse Down'
72
+ end
73
+
74
+ on_drag_detected do |event|
75
+ self.shape_name = 'Square'
76
+ self.listener_event += ' / Drag Detected'
77
+ self.dragged_shape = @rectangle
78
+ end
79
+
80
+ on_mouse_move do |event|
81
+ if listener_event.to_s.empty? || shape_name != 'Square'
82
+ self.listener_event = "Mouse Move"
83
+ elsif !listener_event.to_s.include?('Mouse Move')
84
+ self.listener_event += " / Mouse Move"
85
+ end
86
+ self.shape_name = 'Square'
87
+ end
88
+
89
+ on_mouse_up do |event|
90
+ self.shape_name = 'Square'
91
+ self.listener_event += ' / Mouse Up'
92
+ self.dragged_shape = nil
93
+ end
94
+ }
95
+
96
+ @oval = oval(150, 120, 50, 50) {
97
+ background :green
98
+
99
+ # these listener events are limited to the oval bounds
100
+
101
+ on_mouse_down do |event|
102
+ self.shape_name = 'Circle'
103
+ self.listener_event = 'Mouse Down'
104
+ end
105
+
106
+ on_drag_detected do |event|
107
+ self.shape_name = 'Circle'
108
+ self.listener_event += ' / Drag Detected'
109
+ self.dragged_shape = @oval
110
+ end
111
+
112
+ on_mouse_move do |event|
113
+ if listener_event.to_s.empty? || shape_name != 'Circle'
114
+ self.listener_event = "Mouse Move"
115
+ elsif !listener_event.to_s.include?('Mouse Move')
116
+ self.listener_event += " / Mouse Move"
117
+ end
118
+ self.shape_name = 'Circle'
119
+ end
120
+
121
+ on_mouse_up do |event|
122
+ self.shape_name = 'Circle'
123
+ self.listener_event += ' / Mouse Up'
124
+ self.dragged_shape = nil
125
+ end
126
+ }
127
+
128
+ @polygon = polygon(260, 25, 300, 25, 260, 65) {
129
+ background :blue
130
+
131
+ # these listener events are limited to the polygon bounds
132
+
133
+ on_mouse_down do |event|
134
+ self.shape_name = 'Triangle'
135
+ self.listener_event = 'Mouse Down'
136
+ end
137
+
138
+ on_drag_detected do |event|
139
+ self.shape_name = 'Triangle'
140
+ self.listener_event += ' / Drag Detected'
141
+ self.dragged_shape = @polygon
142
+ end
143
+
144
+ on_mouse_move do |event|
145
+ if listener_event.to_s.empty? || shape_name != 'Triangle'
146
+ self.listener_event = "Mouse Move"
147
+ elsif !listener_event.to_s.include?('Mouse Move')
148
+ self.listener_event += " / Mouse Move"
149
+ end
150
+ self.shape_name = 'Triangle'
151
+ end
152
+
153
+ on_mouse_up do |event|
154
+ self.shape_name = 'Triangle'
155
+ self.listener_event += ' / Mouse Up'
156
+ self.dragged_shape = nil
157
+ end
158
+ }
159
+
160
+ # This is a general canvas listener event, which is used to move shape even if mouse goes out of its bounds
161
+ on_mouse_move do |event|
162
+ dragged_shape.move_by(event.x - @last_x.to_f, event.y - @last_y.to_f) if dragged_shape
163
+ @last_x = event.x
164
+ @last_y = event.y
165
+ end
166
+ }
167
+ }
168
+ }
169
+ end
170
+
171
+ HelloCanvasShapeListeners.launch
@@ -65,8 +65,13 @@ class HelloCustomShape
65
65
  y_location = (rand*HEIGHT/2).to_i%HEIGHT + (rand*15).to_i
66
66
  foreground_color = rgb(rand*255, rand*255, rand*255)
67
67
 
68
- stick_figure(x: x_location, y: y_location, width: 35+n*2, height: 35+n*2) {
68
+ a_stick_figure = stick_figure(x: x_location, y: y_location, width: 35+n*2, height: 35+n*2) {
69
69
  foreground foreground_color
70
+
71
+ # on mouse click, change color
72
+ on_mouse_up do
73
+ a_stick_figure.foreground = rgb(rand*255, rand*255, rand*255)
74
+ end
70
75
  }
71
76
  }
72
77
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-swt
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.20.11.1
4
+ version: 4.20.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-23 00:00:00.000000000 Z
11
+ date: 2021-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -438,6 +438,7 @@ files:
438
438
  - lib/glimmer/dsl/swt/layout_data_expression.rb
439
439
  - lib/glimmer/dsl/swt/layout_expression.rb
440
440
  - lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb
441
+ - lib/glimmer/dsl/swt/listener_expression.rb
441
442
  - lib/glimmer/dsl/swt/menu_bar_expression.rb
442
443
  - lib/glimmer/dsl/swt/menu_expression.rb
443
444
  - lib/glimmer/dsl/swt/message_box_expression.rb
@@ -462,7 +463,6 @@ files:
462
463
  - lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb
463
464
  - lib/glimmer/dsl/swt/tree_properties_expression.rb
464
465
  - lib/glimmer/dsl/swt/widget_expression.rb
465
- - lib/glimmer/dsl/swt/widget_listener_expression.rb
466
466
  - lib/glimmer/launcher.rb
467
467
  - lib/glimmer/rake_task.rb
468
468
  - lib/glimmer/rake_task/list.rb
@@ -576,7 +576,9 @@ files:
576
576
  - samples/hello/hello_canvas_animation.rb
577
577
  - samples/hello/hello_canvas_animation_multi.rb
578
578
  - samples/hello/hello_canvas_data_binding.rb
579
+ - samples/hello/hello_canvas_drag_and_drop.rb
579
580
  - samples/hello/hello_canvas_path.rb
581
+ - samples/hello/hello_canvas_shape_listeners.rb
580
582
  - samples/hello/hello_canvas_transform.rb
581
583
  - samples/hello/hello_checkbox.rb
582
584
  - samples/hello/hello_checkbox_group.rb