glimmer-dsl-opal 0.25.4 → 0.26.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -1
  3. data/README.md +40 -5
  4. data/VERSION +1 -1
  5. data/lib/glimmer/dsl/opal/menu_expression.rb +0 -3
  6. data/lib/glimmer/swt/combo_proxy.rb +0 -39
  7. data/lib/glimmer/swt/control_editor.rb +2 -2
  8. data/lib/glimmer/swt/date_time_proxy.rb +0 -37
  9. data/lib/glimmer/swt/dialog_proxy.rb +11 -4
  10. data/lib/glimmer/swt/display_proxy.rb +1 -83
  11. data/lib/glimmer/swt/shell_proxy.rb +28 -1
  12. data/lib/glimmer/swt/spinner_proxy.rb +0 -39
  13. data/lib/glimmer/swt/table_item_proxy.rb +0 -20
  14. data/lib/glimmer/swt/table_proxy.rb +4 -0
  15. data/lib/glimmer/swt/text_proxy.rb +1 -39
  16. data/lib/glimmer/swt/widget_proxy.rb +177 -58
  17. data/lib/glimmer/ui/custom_shell.rb +2 -0
  18. data/lib/glimmer/ui/custom_widget.rb +2 -0
  19. data/lib/glimmer-dsl-opal/samples/elaborate/tetris/model/block.rb +48 -0
  20. data/lib/glimmer-dsl-opal/samples/elaborate/tetris/model/game.rb +275 -0
  21. data/lib/glimmer-dsl-opal/samples/elaborate/tetris/model/past_game.rb +39 -0
  22. data/lib/glimmer-dsl-opal/samples/elaborate/tetris/model/tetromino.rb +329 -0
  23. data/lib/glimmer-dsl-opal/samples/elaborate/tetris/view/block.rb +36 -0
  24. data/lib/glimmer-dsl-opal/samples/elaborate/tetris/view/high_score_dialog.rb +122 -0
  25. data/lib/glimmer-dsl-opal/samples/elaborate/tetris/view/playfield.rb +56 -0
  26. data/lib/glimmer-dsl-opal/samples/elaborate/tetris/view/score_lane.rb +83 -0
  27. data/lib/glimmer-dsl-opal/samples/elaborate/tetris/view/tetris_menu_bar.rb +136 -0
  28. data/lib/glimmer-dsl-opal/samples/elaborate/tetris.rb +155 -0
  29. data/lib/glimmer-dsl-opal.rb +1 -0
  30. metadata +12 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d82f0649f5baefa289ee1facb6102608e4d84e5a98e84a775ab1112f1698cc3d
4
- data.tar.gz: da29c7ccd153e217867d2dd47afc7611311d79511461bb9395529a6561551cca
3
+ metadata.gz: cabde097ac994643d49e0af9b78fc1bbc7b2eb15857deb8741c557f4e676a4da
4
+ data.tar.gz: a198b93dc21bc2ea93e8542a84bbb83919be9ad0d63355f27dcf1fe4991b682c
5
5
  SHA512:
6
- metadata.gz: 427deabace568823bb59fc9e09dbbbdc7c37c22c25dd131daa41fa61a88cc61a7cc746480d733b2862055fe798a05728ca1a809bacba839068ae346f9ce005da
7
- data.tar.gz: bf34f31729b7c49c25442f12292042c92faf9eeb97e02582d87ad25f548a201ba574af4d00d5280166235c157509b95c2e5412a9e06f3f3924ea2738c6a3555a
6
+ metadata.gz: b77f3a496e6dd8e8afea59185ba46306b07e9cb0e4fb5e41b97151886292ab1735008e5a58f08251874e25ede8b781f819498f2ef0c84ba4f357f8c13b7c2c0a
7
+ data.tar.gz: bc9646367d1cd6476f60edf98cf2a94ff24dd6bff14756b3bcbc1365e79a3cb22869c626bc897f94784c59e3cffe30fe5c5e8fe90915a23fc042d3b4f836ffae
data/CHANGELOG.md CHANGED
@@ -1,8 +1,31 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.26.3
4
+
5
+ - Support key_event.key_location in all key capturing widgets, not just display
6
+
7
+ ## 0.26.2
8
+
9
+ - Support key_event.key_location to distinguish between left and right alt/shift/command/ctrl buttons
10
+ - Use right/left alt/shift keys in Tetris for rotate right and rotate left
11
+
12
+ ## 0.26.1
13
+
14
+ - Support display on_swt_keydown event keyCode/key_code values for arrow keys and alt/shift/ctrl
15
+ - Use arrow keys for movement in Tetris
16
+ - Use alt/shift keys for rotate right in Tetris
17
+
18
+ ## 0.26.0
19
+
20
+ - Tetris elaborate sample (minimal initial version of the one in Glimmer DSL for SWT)
21
+ - Support `menu_item` `selection` attribute data-binding for `:check` and `:radio` SWT styles
22
+ - Set 'custom_shell' data for custom shell on its body_root
23
+ - Provide parent_proxy on custom widgets as an alternative to parent for compatibility with Glimmer DSL for SWT
24
+ - Have custom widgets derive their parent from body root if not passed in explicitly
25
+
3
26
  ## 0.25.4
4
27
 
5
- - Upgrade to opal-async 1.4.0
28
+ - Upgrade to opal-async 1.4.0
6
29
  - Update Hello, Custom Widget! to utilize `Array#async_cycle` instead of `Array#cycle`
7
30
 
8
31
  ## 0.25.3
data/README.md CHANGED
@@ -145,7 +145,7 @@ Hello, Table! Game Booked
145
145
 
146
146
  NOTE: Glimmer DSL for Opal is an alpha project. Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
147
147
 
148
- **Alpha Version** 0.25.4 only supports bare-minimum capabilities for the included [samples](https://github.com/AndyObtiva/glimmer-dsl-opal#samples) (originally written for [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt))
148
+ **Alpha Version** 0.26.3 only supports bare-minimum capabilities for the included [samples](https://github.com/AndyObtiva/glimmer-dsl-opal#samples) (originally written for [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt))
149
149
 
150
150
  Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
151
151
  - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
@@ -196,6 +196,7 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
196
196
  - [Elaborate Samples](#elaborate-samples)
197
197
  - [Login](#login)
198
198
  - [Contact Manager](#contact-manager)
199
+ - [Tetris](#tetris)
199
200
  - [Tic Tac Toe](#tic-tac-toe)
200
201
  - [User Profile](#user-profile)
201
202
  - [Weather](#weather)
@@ -235,7 +236,7 @@ Alternatively, web developers may directly use [Glimmer DSL for Opal](https://ru
235
236
  ## Pre-requisites
236
237
 
237
238
  - Rails 5.2: [https://github.com/rails/rails/tree/5-2-stable](https://github.com/rails/rails/tree/5-2-stable)
238
- - Opal 1.0.4: [https://github.com/opal/opal](https://github.com/opal/opal)
239
+ - Opal 1.0.5: [https://github.com/opal/opal](https://github.com/opal/opal)
239
240
  - Opal-Rails 1.1.2: [https://github.com/opal/opal-rails](https://github.com/opal/opal-rails)
240
241
  - jQuery 3: [https://code.jquery.com/](https://code.jquery.com/) (jQuery 3.5.1 is included in the [glimmer-dsl-opal](https://rubygems.org/gems/glimmer-dsl-opal) gem)
241
242
  - jQuery-UI 1.12: [https://code.jquery.com/](https://jqueryui.com/) (jQuery-UI 1.12.1 is included in the [glimmer-dsl-opal](https://rubygems.org/gems/glimmer-dsl-opal) gem)
@@ -252,7 +253,7 @@ Please follow the following steps to setup.
252
253
  Install a Rails 5 gem:
253
254
 
254
255
  ```
255
- gem install rails -v5.2.4.4
256
+ gem install rails -v5.2.6
256
257
  ```
257
258
 
258
259
  Start a new Rails 5 app:
@@ -264,11 +265,11 @@ rails new glimmer_app_server
264
265
  Add the following to `Gemfile`:
265
266
 
266
267
  ```
267
- gem 'opal', '1.0.4'
268
+ gem 'opal', '1.0.5'
268
269
  gem 'opal-rails', '1.1.2'
269
270
  gem 'opal-async', '~> 1.4.0'
270
271
  gem 'opal-jquery', '~> 0.4.4'
271
- gem 'glimmer-dsl-opal', '~> 0.25.4'
272
+ gem 'glimmer-dsl-opal', '~> 0.26.3'
272
273
  gem 'glimmer-dsl-xml', '~> 1.2.0', require: false
273
274
  gem 'glimmer-dsl-css', '~> 1.2.0', require: false
274
275
 
@@ -2584,6 +2585,40 @@ Glimmer DSL for Opal Contact Manager Edit Done
2584
2585
 
2585
2586
  ![Glimmer DSL for Opal Contact Manager Edit Done](images/glimmer-dsl-opal-contact-manager-edit-done.png)
2586
2587
 
2588
+ #### Tetris
2589
+
2590
+ This is a minimal initial version of the [Tetris seen in Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_SAMPLES.md#glimmer-tetris).
2591
+
2592
+ Note that while the Glimmer GUI DSL code is mostly the same, some of the behavioral code around threads is changed
2593
+ into async Opal code via the [opal-async](https://github.com/AndyObtiva/opal-async) gem due to the async nature of transpiled JavaScript.
2594
+
2595
+ Still, this sample has done the remarkable feat of reusing all of the Tetris model/view logic from Glimmer DSL for SWT mostly unchanged.
2596
+
2597
+ Add the following require statement to `app/assets/javascripts/application.rb`
2598
+
2599
+ ```ruby
2600
+ require 'glimmer-dsl-opal/samples/elaborate/tetris'
2601
+ ```
2602
+
2603
+ Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
2604
+
2605
+ ![Glimmer DSL for SWT Tetris](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-tetris.png)
2606
+
2607
+ Glimmer app on the web (using `glimmer-dsl-opal` gem):
2608
+
2609
+ Start the Rails server:
2610
+ ```
2611
+ rails s
2612
+ ```
2613
+
2614
+ Visit `http://localhost:3000`
2615
+
2616
+ You should see "Tetris" (a minimal version of the one in Glimmer DSL for SWT)
2617
+
2618
+ ![Glimmer DSL for Opal Tetris](images/glimmer-dsl-opal-tetris.png)
2619
+
2620
+ ![Glimmer DSL for Opal Tetris Video](images/glimmer-dsl-opal-tetris.gif)
2621
+
2587
2622
  #### Tic Tac Toe
2588
2623
 
2589
2624
  Add the following require statement to `app/assets/javascripts/application.rb`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.25.4
1
+ 0.26.3
@@ -37,9 +37,6 @@ module Glimmer
37
37
  if parent.is_a?(Glimmer::SWT::WidgetProxy)
38
38
  return true
39
39
  else
40
- puts 'parent'
41
- puts parent.class
42
- puts parent
43
40
  raise Glimmer::Error, "menu may only be nested under a widget (like shell or another menu)!"
44
41
  end
45
42
  end
@@ -55,45 +55,6 @@ module Glimmer
55
55
  }
56
56
  }
57
57
  },
58
- 'on_key_pressed' => {
59
- event: 'keydown',
60
- event_handler: -> (event_listener) {
61
- -> (event) {
62
- @last_key_pressed_event = event
63
- @text = event.target.value
64
- # TODO generalize this solution to all widgets that support key presses
65
- # TODO support event.location once DOM3 is supported by opal-jquery
66
- event.define_singleton_method(:keyCode) {event.which}
67
- event.define_singleton_method(:key_code, &event.method(:keyCode))
68
- event.define_singleton_method(:character) {event.which.chr}
69
- event.define_singleton_method(:stateMask) do
70
- state_mask = 0
71
- state_mask |= SWTProxy[:alt] if event.alt_key
72
- state_mask |= SWTProxy[:ctrl] if event.ctrl_key
73
- state_mask |= SWTProxy[:shift] if event.shift_key
74
- state_mask |= SWTProxy[:command] if event.meta_key
75
- state_mask
76
- end
77
- event.define_singleton_method(:state_mask, &event.method(:stateMask))
78
- doit = true
79
- event.define_singleton_method(:doit=) do |value|
80
- doit = value
81
- end
82
- event.define_singleton_method(:doit) { doit }
83
- event_listener.call(event)
84
-
85
- # TODO Fix doit false, it's not stopping input
86
- unless doit
87
- event.prevent
88
- event.prevent_default
89
- event.stop_propagation
90
- event.stop_immediate_propagation
91
- end
92
-
93
- doit
94
- }
95
- }
96
- },
97
58
  }
98
59
  end
99
60
 
@@ -27,8 +27,8 @@ module Glimmer
27
27
  ATTRIBUTES = [:grabHorizontal, :grabVertical, :horizontalAlignment, :verticalAlignment, :minimumWidth, :minimumHeight]
28
28
  attr_accessor(*ATTRIBUTES)
29
29
  ATTRIBUTES.each do |attribute|
30
- alias_method attribute.underscore, attribute
31
- alias_method "#{attribute.underscore}=", "#{attribute}="
30
+ alias_method attribute.to_s.underscore, attribute
31
+ alias_method "#{attribute.to_s.underscore}=", "#{attribute}="
32
32
  end
33
33
 
34
34
  # TODO consider supporting a java_attr_accessor to get around having to generate all the aliases manually
@@ -136,43 +136,6 @@ module Glimmer
136
136
  }
137
137
  },
138
138
  ],
139
- 'on_key_pressed' => {
140
- event: 'keydown',
141
- event_handler: -> (event_listener) {
142
- -> (event) {
143
- # TODO generalize this solution to all widgets that support key presses
144
- # TODO support event.location once DOM3 is supported by opal-jquery
145
- event.define_singleton_method(:keyCode) {event.which}
146
- event.define_singleton_method(:key_code, &event.method(:keyCode))
147
- event.define_singleton_method(:character) {event.which.chr}
148
- event.define_singleton_method(:stateMask) do
149
- state_mask = 0
150
- state_mask |= SWTProxy[:alt] if event.alt_key
151
- state_mask |= SWTProxy[:ctrl] if event.ctrl_key
152
- state_mask |= SWTProxy[:shift] if event.shift_key
153
- state_mask |= SWTProxy[:command] if event.meta_key
154
- state_mask
155
- end
156
- event.define_singleton_method(:state_mask, &event.method(:stateMask))
157
- doit = true
158
- event.define_singleton_method(:doit=) do |value|
159
- doit = value
160
- end
161
- event.define_singleton_method(:doit) { doit }
162
- event_listener.call(event)
163
-
164
- # TODO Fix doit false, it's not stopping input
165
- unless doit
166
- event.prevent
167
- event.prevent_default
168
- event.stop_propagation
169
- event.stop_immediate_propagation
170
- end
171
-
172
- doit
173
- }
174
- }
175
- },
176
139
  }
177
140
  end
178
141
 
@@ -19,12 +19,13 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- require 'glimmer/swt/widget_proxy'
23
22
  require 'glimmer/swt/display_proxy'
23
+ require 'glimmer/swt/widget_proxy'
24
+ require 'glimmer/swt/shell_proxy'
24
25
 
25
26
  module Glimmer
26
27
  module SWT
27
- class DialogProxy < CompositeProxy
28
+ class DialogProxy < ShellProxy
28
29
  STYLE = <<~CSS
29
30
  .ui-dialog .ui-dialog-content {
30
31
  background: rgb(235, 235, 235);
@@ -86,7 +87,7 @@ module Glimmer
86
87
  @open
87
88
  end
88
89
 
89
- def open
90
+ def open(async: true)
90
91
  owned_proc = Glimmer::Util::ProcTracker.new(owner: self, invoked_from: :open) {
91
92
  shell.open(async: false) unless shell.open?
92
93
  unless @init
@@ -113,8 +114,13 @@ module Glimmer
113
114
  dom_element.dialog('open')
114
115
  end
115
116
  @open = true
117
+ listeners_for('swt_show').each {|listener| listener.call(Event.new(widget: self))}
116
118
  }
117
- DisplayProxy.instance.async_exec(owned_proc)
119
+ if async
120
+ DisplayProxy.instance.async_exec(owned_proc)
121
+ else
122
+ owned_proc.call
123
+ end
118
124
  end
119
125
 
120
126
  def hide
@@ -129,6 +135,7 @@ module Glimmer
129
135
  dom_element.remove
130
136
  @open = false
131
137
  @init = false
138
+ listeners_for('swt_close').each {|listener| listener.call(Event.new(widget: self))}
132
139
  Element['.dialog-overlay'].add_class('hide') unless DisplayProxy.instance.dialogs.any?(&:open?)
133
140
  parent.children.delete(self)
134
141
  shell.close if shell.children.empty?
@@ -1,4 +1,5 @@
1
1
  require 'glimmer/swt/widget_proxy'
2
+ require 'glimmer/swt/swt_proxy'
2
3
 
3
4
  module Glimmer
4
5
  module SWT
@@ -85,89 +86,6 @@ module Glimmer
85
86
  # sync_exec kept for API compatibility reasons
86
87
  alias sync_exec async_exec
87
88
 
88
- def observation_request_to_event_mapping
89
- {
90
- 'on_swt_keydown' => [
91
- {
92
- event: 'keypress',
93
- event_handler: -> (event_listener) {
94
- -> (event) {
95
- event.singleton_class.define_method(:character) do
96
- which || key_code
97
- end
98
- event.define_singleton_method(:keyCode) {event.which}
99
- event.define_singleton_method(:key_code, &event.method(:keyCode))
100
- event.define_singleton_method(:character) {event.which.chr}
101
- event.define_singleton_method(:stateMask) do
102
- state_mask = 0
103
- state_mask |= SWTProxy[:alt] if event.alt_key
104
- state_mask |= SWTProxy[:ctrl] if event.ctrl_key
105
- state_mask |= SWTProxy[:shift] if event.shift_key
106
- state_mask |= SWTProxy[:command] if event.meta_key
107
- state_mask
108
- end
109
- event.define_singleton_method(:state_mask, &event.method(:stateMask))
110
- doit = true
111
- event.define_singleton_method(:doit=) do |value|
112
- doit = value
113
- end
114
- event.define_singleton_method(:doit) { doit }
115
- event_listener.call(event)
116
-
117
- # TODO Fix doit false, it's not stopping input
118
- unless doit
119
- event.prevent
120
- event.prevent_default
121
- event.stop_propagation
122
- event.stop_immediate_propagation
123
- end
124
-
125
- doit
126
- }
127
- }
128
- },
129
- {
130
- event: 'keydown',
131
- event_handler: -> (event_listener) {
132
- -> (event) {
133
- event.singleton_class.define_method(:character) do
134
- which || key_code
135
- end
136
- event.define_singleton_method(:keyCode) {event.which}
137
- event.define_singleton_method(:key_code, &event.method(:keyCode))
138
- event.define_singleton_method(:character) {event.which.chr}
139
- event.define_singleton_method(:stateMask) do
140
- state_mask = 0
141
- state_mask |= SWTProxy[:alt] if event.alt_key
142
- state_mask |= SWTProxy[:ctrl] if event.ctrl_key
143
- state_mask |= SWTProxy[:shift] if event.shift_key
144
- state_mask |= SWTProxy[:command] if event.meta_key
145
- state_mask
146
- end
147
- event.define_singleton_method(:state_mask, &event.method(:stateMask))
148
- doit = true
149
- event.define_singleton_method(:doit=) do |value|
150
- doit = value
151
- end
152
- event.define_singleton_method(:doit) { doit }
153
- event_listener.call(event) if event.key_code != 13 && (event.key_code == 127 || event.key_code <= 31)
154
-
155
- # TODO Fix doit false, it's not stopping input
156
- unless doit
157
- event.prevent
158
- event.prevent_default
159
- event.stop_propagation
160
- event.stop_immediate_propagation
161
- end
162
-
163
- doit
164
- }
165
- }
166
- }
167
- ]
168
- }
169
- end
170
-
171
89
  private
172
90
 
173
91
  def async_exec_queues
@@ -69,6 +69,7 @@ module Glimmer
69
69
  HEIGHT_MIN = 0
70
70
 
71
71
  def initialize(args)
72
+ # TODO set parent
72
73
  @args = args
73
74
  @children = []
74
75
  render # TODO attach to specific element
@@ -78,7 +79,7 @@ module Glimmer
78
79
  self.minimum_size = Point.new(WIDTH_MIN, HEIGHT_MIN)
79
80
  DisplayProxy.instance.shells << self
80
81
  end
81
-
82
+
82
83
  def post_add_content
83
84
  `$( document ).tooltip()`
84
85
  end
@@ -128,6 +129,16 @@ module Glimmer
128
129
  dom_element.css('min-height', "#{@minimum_size.y}px")
129
130
  end
130
131
 
132
+ def handle_observation_request(keyword, original_event_listener)
133
+ case keyword
134
+ when 'on_swt_show', 'on_swt_close', 'on_shell_closed'
135
+ keyword = 'on_swt_close' if keyword == 'on_shell_closed'
136
+ listeners_for(keyword.sub(/^on_/, '')) << original_event_listener.to_proc
137
+ else
138
+ super(keyword, original_event_listener)
139
+ end
140
+ end
141
+
131
142
  def style_dom_css
132
143
  <<~CSS
133
144
  .hide {
@@ -169,6 +180,7 @@ module Glimmer
169
180
  DisplayProxy.instance.shells.select(&:open?).reject {|s| s == self}.map(&:hide)
170
181
  dom_element.remove_class('hide')
171
182
  @open = true
183
+ listeners_for('swt_show').each {|listener| listener.call(Event.new(widget: self))}
172
184
  end
173
185
  end
174
186
  if async
@@ -177,6 +189,7 @@ module Glimmer
177
189
  work.call
178
190
  end
179
191
  end
192
+ alias show open
180
193
 
181
194
  def hide
182
195
  dom_element.add_class('hide')
@@ -187,11 +200,25 @@ module Glimmer
187
200
  DisplayProxy.instance.shells.delete(self)
188
201
  dom_element.remove
189
202
  @open = false
203
+ listeners_for('swt_close').each {|listener| listener.call(Event.new(widget: self))}
190
204
  end
191
205
 
192
206
  def open?
193
207
  @open
194
208
  end
209
+
210
+ def visible
211
+ @open
212
+ end
213
+ alias visible? visible
214
+
215
+ def visible=(value)
216
+ if value
217
+ show(async: false)
218
+ else
219
+ hide
220
+ end
221
+ end
195
222
  end
196
223
  end
197
224
  end