glimmer-dsl-opal 0.19.1 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +27 -2
- data/VERSION +1 -1
- data/lib/glimmer-dsl-opal/samples/hello/hello_spinner.rb +78 -0
- data/lib/glimmer/swt/c_tab_item_proxy.rb +2 -2
- data/lib/glimmer/swt/spinner_proxy.rb +173 -0
- data/lib/glimmer/swt/widget_proxy.rb +10 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 531f953f5ec4fe36dfa9a7bc8e7a98e5155c8dced489215e74b6679543feff1b
|
4
|
+
data.tar.gz: 3e429ff4bac544027a49e458c75b670adf0d3f6110da692f151da6153511e889
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2822a5d9881c20c06c31b4a1115cf08a1cc5e79db5da15ca2cf8491a9f1c9e7114ccb8380e94af27b55f14e7e533a2247890cd11ea06bd2d8a82b7038c9e628d
|
7
|
+
data.tar.gz: ea93b2b373f4aea2c742c09d1e05752899c91ba62d12b5e5cde96492631984cf49e70fcbc8d744ea516ac2bbd42fc00bd58d84b0cc8f297cb04d0d6a45d34210
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.20.0
|
4
|
+
|
5
|
+
- Support `spinner` widget (leaving out automatic insertion of decimal point when digits are specified)
|
6
|
+
- Hello, Spinner! sample
|
7
|
+
|
3
8
|
## 0.19.1
|
4
9
|
|
5
10
|
- Fix widget `font` property support for both `:bold` and `:italic` styles at the same time
|
data/README.md
CHANGED
@@ -143,7 +143,7 @@ Hello, Table! Game Booked
|
|
143
143
|
|
144
144
|
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.
|
145
145
|
|
146
|
-
**Alpha Version** 0.
|
146
|
+
**Alpha Version** 0.20.0 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))
|
147
147
|
|
148
148
|
Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
|
149
149
|
- [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
|
@@ -261,7 +261,7 @@ gem 'opal', '1.0.4'
|
|
261
261
|
gem 'opal-rails', '1.1.2'
|
262
262
|
gem 'opal-async', '~> 1.2.0'
|
263
263
|
gem 'opal-jquery', '~> 0.4.4'
|
264
|
-
gem 'glimmer-dsl-opal', '~> 0.
|
264
|
+
gem 'glimmer-dsl-opal', '~> 0.20.0'
|
265
265
|
gem 'glimmer-dsl-xml', '~> 1.2.0', require: false
|
266
266
|
gem 'glimmer-dsl-css', '~> 1.2.0', require: false
|
267
267
|
|
@@ -799,6 +799,31 @@ You should see "Hello, Arrow!"
|
|
799
799
|
|
800
800
|
![Glimmer DSL for Opal Hello Arrow](images/glimmer-dsl-opal-hello-arrow-item-selected.png)
|
801
801
|
|
802
|
+
#### Hello, Spinner!
|
803
|
+
|
804
|
+
Add the following require statement to `app/assets/javascripts/application.rb`
|
805
|
+
|
806
|
+
```ruby
|
807
|
+
require 'glimmer-dsl-opal/samples/hello/hello_spinner'
|
808
|
+
```
|
809
|
+
|
810
|
+
Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
|
811
|
+
|
812
|
+
![Glimmer DSL for SWT Hello Spinner](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-spinner.png)
|
813
|
+
|
814
|
+
Glimmer app on the web (using `glimmer-dsl-opal` gem):
|
815
|
+
|
816
|
+
Start the Rails server:
|
817
|
+
```
|
818
|
+
rails s
|
819
|
+
```
|
820
|
+
|
821
|
+
Visit `http://localhost:3000`
|
822
|
+
|
823
|
+
You should see "Hello, Spinner!"
|
824
|
+
|
825
|
+
![Glimmer DSL for Opal Hello Spinner](images/glimmer-dsl-opal-hello-spinner.png)
|
826
|
+
|
802
827
|
#### Hello, Browser!
|
803
828
|
|
804
829
|
Add the following require statement to `app/assets/javascripts/application.rb`
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.20.0
|
@@ -0,0 +1,78 @@
|
|
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
|
+
class HelloSpinner
|
23
|
+
class Person
|
24
|
+
attr_accessor :donation
|
25
|
+
end
|
26
|
+
|
27
|
+
include Glimmer::UI::CustomShell
|
28
|
+
|
29
|
+
before_body do
|
30
|
+
@person = Person.new
|
31
|
+
@person.donation = 500 # in cents
|
32
|
+
end
|
33
|
+
|
34
|
+
body {
|
35
|
+
shell {
|
36
|
+
grid_layout
|
37
|
+
|
38
|
+
text 'Hello, Spinner!'
|
39
|
+
|
40
|
+
label {
|
41
|
+
text 'Please select the amount you would like to donate to the poor:'
|
42
|
+
}
|
43
|
+
|
44
|
+
composite {
|
45
|
+
grid_layout 3, false
|
46
|
+
|
47
|
+
label {
|
48
|
+
layout_data {
|
49
|
+
width_hint 240
|
50
|
+
}
|
51
|
+
text 'Amount:'
|
52
|
+
font style: :bold
|
53
|
+
}
|
54
|
+
|
55
|
+
label {
|
56
|
+
text '$'
|
57
|
+
}
|
58
|
+
|
59
|
+
spinner {
|
60
|
+
digits 2 # digits after the decimal point
|
61
|
+
minimum 100 # minimum value (including digits after the decimal point)
|
62
|
+
maximum 15000 # maximum value (including digits after the decimal point)
|
63
|
+
increment 500 # increment on up and down (including digits after the decimal point)
|
64
|
+
page_increment 5000 # page increment on page up and page down (including digits after the decimal point)
|
65
|
+
selection <=> [@person, :donation] # selection must be set last if other properties are configured to ensure value is within bounds
|
66
|
+
}
|
67
|
+
|
68
|
+
label {
|
69
|
+
layout_data(:fill, :center, true, false)
|
70
|
+
text <=> [@person, :donation, on_read: ->(value) { "Thank you for your donation of $#{"%.2f" % (value.to_f / 100.0)}"}]
|
71
|
+
}
|
72
|
+
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
HelloSpinner.launch
|
@@ -52,8 +52,8 @@ module Glimmer
|
|
52
52
|
def font=(value)
|
53
53
|
@font = value.is_a?(FontProxy) ? value : FontProxy.new(self, value)
|
54
54
|
tab_dom_element.css('font-family', @font.name) unless @font.nil?
|
55
|
-
tab_dom_element.css('font-style', 'italic') if @font&.style == :italic || @font&.style
|
56
|
-
tab_dom_element.css('font-weight', 'bold') if @font&.style == :bold || @font&.style
|
55
|
+
tab_dom_element.css('font-style', 'italic') if @font&.style == :italic || [@font&.style].flatten.compact.include?(:italic)
|
56
|
+
tab_dom_element.css('font-weight', 'bold') if @font&.style == :bold || [@font&.style].flatten.compact.include?(:bold)
|
57
57
|
tab_dom_element.css('font-size', "#{@font.height}px") unless @font.nil?
|
58
58
|
end
|
59
59
|
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'glimmer/swt/widget_proxy'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module SWT
|
5
|
+
class SpinnerProxy < WidgetProxy
|
6
|
+
attr_reader :minimum, :maximum, :increment, :page_increment, :digits
|
7
|
+
|
8
|
+
def initialize(parent, args, block)
|
9
|
+
super(parent, args, block)
|
10
|
+
@increment = 1
|
11
|
+
@digits = 0
|
12
|
+
dom_element.spinner
|
13
|
+
end
|
14
|
+
|
15
|
+
def selection=(value)
|
16
|
+
old_value = @selection.to_f
|
17
|
+
if @selection.nil?
|
18
|
+
@selection = value.to_f / divider
|
19
|
+
else
|
20
|
+
@selection = value.to_f
|
21
|
+
end
|
22
|
+
# TODO do not apply digits if last change was done by keyboard not spinner
|
23
|
+
# if @digits.to_i > 0
|
24
|
+
# new_value = "%0.#{@digits.to_i}f" % @selection
|
25
|
+
# dom_element.value = new_value if value.to_f != old_value.to_f
|
26
|
+
# else
|
27
|
+
dom_element.value = @selection if value.to_f != old_value.to_f
|
28
|
+
# end
|
29
|
+
end
|
30
|
+
|
31
|
+
def selection
|
32
|
+
@selection && @selection * divider
|
33
|
+
end
|
34
|
+
|
35
|
+
def text=(value)
|
36
|
+
self.selection = value.to_f
|
37
|
+
end
|
38
|
+
|
39
|
+
def text
|
40
|
+
self.selection.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def minimum=(value)
|
44
|
+
@minimum = value.to_f / divider
|
45
|
+
dom_element.spinner('option', 'min', @minimum)
|
46
|
+
end
|
47
|
+
|
48
|
+
def maximum=(value)
|
49
|
+
@maximum = value.to_f / divider
|
50
|
+
dom_element.spinner('option', 'max', @maximum)
|
51
|
+
end
|
52
|
+
|
53
|
+
def increment=(value)
|
54
|
+
@increment = value.to_f / divider
|
55
|
+
dom_element.spinner('option', 'step', @increment)
|
56
|
+
end
|
57
|
+
|
58
|
+
def page_increment=(value)
|
59
|
+
@page_increment = value.to_f / (@increment * divider)
|
60
|
+
dom_element.spinner('option', 'page', @page_increment)
|
61
|
+
end
|
62
|
+
|
63
|
+
def divider
|
64
|
+
('1' + '0'*@digits.to_i).to_f
|
65
|
+
end
|
66
|
+
|
67
|
+
def digits=(value)
|
68
|
+
@digits = value
|
69
|
+
dom_element.spinner('option', 'numberFormat', "n") if @digits.to_i > 0
|
70
|
+
end
|
71
|
+
|
72
|
+
def element
|
73
|
+
'input'
|
74
|
+
end
|
75
|
+
|
76
|
+
def observation_request_to_event_mapping
|
77
|
+
{
|
78
|
+
'on_widget_selected' => [
|
79
|
+
{
|
80
|
+
event: 'change',
|
81
|
+
event_handler: -> (event_listener) {
|
82
|
+
-> (event) {
|
83
|
+
self.selection = event.target.value
|
84
|
+
event_listener.call(event)
|
85
|
+
}
|
86
|
+
}
|
87
|
+
},
|
88
|
+
{
|
89
|
+
event: 'spinstop',
|
90
|
+
event_handler: -> (event_listener) {
|
91
|
+
-> (event) {
|
92
|
+
self.selection = event.target.value
|
93
|
+
event_listener.call(event)
|
94
|
+
}
|
95
|
+
}
|
96
|
+
},
|
97
|
+
],
|
98
|
+
'on_modify_text' => {
|
99
|
+
event: 'keyup',
|
100
|
+
event_handler: -> (event_listener) {
|
101
|
+
-> (event) {
|
102
|
+
# TODO consider unifying this event handler with on_key_pressed by relying on its result instead of hooking another keyup event
|
103
|
+
if @last_key_pressed_event.nil? || @last_key_pressed_event.doit
|
104
|
+
self.text = event.target.value
|
105
|
+
event_listener.call(event)
|
106
|
+
else
|
107
|
+
# TODO Fix doit false, it's not stopping input
|
108
|
+
event.prevent
|
109
|
+
event.prevent_default
|
110
|
+
event.stop_propagation
|
111
|
+
event.stop_immediate_propagation
|
112
|
+
end
|
113
|
+
}
|
114
|
+
}
|
115
|
+
},
|
116
|
+
'on_key_pressed' => {
|
117
|
+
event: 'keydown',
|
118
|
+
event_handler: -> (event_listener) {
|
119
|
+
-> (event) {
|
120
|
+
@last_key_pressed_event = event
|
121
|
+
self.text = event.target.value
|
122
|
+
# TODO generalize this solution to all widgets that support key presses
|
123
|
+
# TODO support event.location once DOM3 is supported by opal-jquery
|
124
|
+
event.define_singleton_method(:keyCode) {event.which}
|
125
|
+
event.define_singleton_method(:key_code, &event.method(:keyCode))
|
126
|
+
event.define_singleton_method(:character) {event.which.chr}
|
127
|
+
event.define_singleton_method(:stateMask) do
|
128
|
+
state_mask = 0
|
129
|
+
state_mask |= SWTProxy[:alt] if event.alt_key
|
130
|
+
state_mask |= SWTProxy[:ctrl] if event.ctrl_key
|
131
|
+
state_mask |= SWTProxy[:shift] if event.shift_key
|
132
|
+
state_mask |= SWTProxy[:command] if event.meta_key
|
133
|
+
state_mask
|
134
|
+
end
|
135
|
+
event.define_singleton_method(:state_mask, &event.method(:stateMask))
|
136
|
+
doit = true
|
137
|
+
event.define_singleton_method(:doit=) do |value|
|
138
|
+
doit = value
|
139
|
+
end
|
140
|
+
event.define_singleton_method(:doit) { doit }
|
141
|
+
event_listener.call(event)
|
142
|
+
|
143
|
+
# TODO Fix doit false, it's not stopping input
|
144
|
+
unless doit
|
145
|
+
event.prevent
|
146
|
+
event.prevent_default
|
147
|
+
event.stop_propagation
|
148
|
+
event.stop_immediate_propagation
|
149
|
+
end
|
150
|
+
|
151
|
+
doit
|
152
|
+
}
|
153
|
+
}
|
154
|
+
},
|
155
|
+
}
|
156
|
+
end
|
157
|
+
|
158
|
+
def dom
|
159
|
+
text_text = @text
|
160
|
+
text_id = id
|
161
|
+
text_style = css
|
162
|
+
text_class = name
|
163
|
+
# TODO support password field
|
164
|
+
options = {type: 'text', id: text_id, style: text_style, class: text_class, value: text_text, style: 'min-width: 27px;'}
|
165
|
+
options = options.merge('disabled': 'disabled') unless @enabled
|
166
|
+
options = options.merge(type: 'password') if has_style?(:password)
|
167
|
+
@dom ||= html {
|
168
|
+
input(options)
|
169
|
+
}.to_s
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -237,8 +237,8 @@ module Glimmer
|
|
237
237
|
def font=(value)
|
238
238
|
@font = value.is_a?(FontProxy) ? value : FontProxy.new(self, value)
|
239
239
|
dom_element.css('font-family', @font.name) unless @font.nil?
|
240
|
-
dom_element.css('font-style', 'italic') if @font&.style == :italic || @font&.style
|
241
|
-
dom_element.css('font-weight', 'bold') if @font&.style == :bold || @font&.style
|
240
|
+
dom_element.css('font-style', 'italic') if @font&.style == :italic || [@font&.style].flatten.compact.include?(:italic)
|
241
|
+
dom_element.css('font-weight', 'bold') if @font&.style == :bold || [@font&.style].flatten.compact.include?(:bold)
|
242
242
|
dom_element.css('font-size', "#{@font.height}px") unless @font.nil?
|
243
243
|
end
|
244
244
|
|
@@ -851,6 +851,13 @@ module Glimmer
|
|
851
851
|
# }
|
852
852
|
# end,
|
853
853
|
# },
|
854
|
+
SpinnerProxy => {
|
855
|
+
:selection => lambda do |observer|
|
856
|
+
on_widget_selected { |selection_event|
|
857
|
+
observer.call(selection)
|
858
|
+
}
|
859
|
+
end
|
860
|
+
},
|
854
861
|
TextProxy => {
|
855
862
|
:text => lambda do |observer|
|
856
863
|
on_modify_text { |modify_event|
|
@@ -984,6 +991,7 @@ require 'glimmer/swt/table_proxy'
|
|
984
991
|
require 'glimmer/swt/text_proxy'
|
985
992
|
require 'glimmer/swt/radio_proxy'
|
986
993
|
require 'glimmer/swt/scrolled_composite_proxy'
|
994
|
+
require 'glimmer/swt/spinner_proxy'
|
987
995
|
require 'glimmer/swt/styled_text_proxy'
|
988
996
|
|
989
997
|
require 'glimmer/dsl/opal/widget_expression'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-opal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AndyMaleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -307,6 +307,7 @@ files:
|
|
307
307
|
- lib/glimmer-dsl-opal/samples/hello/hello_pop_up_context_menu.rb
|
308
308
|
- lib/glimmer-dsl-opal/samples/hello/hello_radio.rb
|
309
309
|
- lib/glimmer-dsl-opal/samples/hello/hello_radio_group.rb
|
310
|
+
- lib/glimmer-dsl-opal/samples/hello/hello_spinner.rb
|
310
311
|
- lib/glimmer-dsl-opal/samples/hello/hello_tab.rb
|
311
312
|
- lib/glimmer-dsl-opal/samples/hello/hello_table.rb
|
312
313
|
- lib/glimmer-dsl-opal/samples/hello/hello_table/baseball_park.png
|
@@ -420,6 +421,7 @@ files:
|
|
420
421
|
- lib/glimmer/swt/row_layout_proxy.rb
|
421
422
|
- lib/glimmer/swt/scrolled_composite_proxy.rb
|
422
423
|
- lib/glimmer/swt/shell_proxy.rb
|
424
|
+
- lib/glimmer/swt/spinner_proxy.rb
|
423
425
|
- lib/glimmer/swt/style_constantizable.rb
|
424
426
|
- lib/glimmer/swt/styled_text_proxy.rb
|
425
427
|
- lib/glimmer/swt/swt_proxy.rb
|