glimmer-dsl-opal 0.19.0 → 0.21.0

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: 5617b16e9da429aeac72049da8803530ff80be0573a4a97e9f40dc7d543f3869
4
- data.tar.gz: 90b2d967c42ca61c617d874f070c6a63dc79edeb172566a1c38baffa4f3de51c
3
+ metadata.gz: 4dbe9f418aaf69cea9d11235337a4915e0545e0fcded7591f5b8e04c7195721d
4
+ data.tar.gz: dabf17fe41390a4ea6d5f4d88d71c27782eaf0ef96948f67845d9d8ab8bdbc0a
5
5
  SHA512:
6
- metadata.gz: 671f9759f18ac9c60b0ca61c1a2186b2ce04965262848c649cb184037e904bc9a73190a57312e0b233598fcf689f1d19eec0fd69a30f8b03db22d633567bf18a
7
- data.tar.gz: c5a473ce5ea0e281f53684ebc0eb7cb74517cb30318cd355b42b20e3b70d3cf880e530eadc2b0fb2b577cd1fada551afe774b06930dc2d00853e0237d64bef75
6
+ metadata.gz: 0f84635205c0f8a86575fee0c1b72760052bb3722467196d067f469111f923d4195264ab4563bf3b5e37155d51e061d7d1f35f2b43acd77ca4d922ceabba4255
7
+ data.tar.gz: 6f6f984e402e801fe336448ab7997ac2dacb40d1fe2a05c35ae4a937394325b48de250c98e4cf6fde8313b3f6d73d88eab180520b889bdd9f146828565baf1af
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.21.0
4
+
5
+ - Support `scale` widget
6
+ - Hello, Scale!
7
+ - Support `slider` widget
8
+ - Hello, Slider!
9
+
10
+ ## 0.20.1
11
+
12
+ - Support `spinner` automatic insertion of decimal point when `digits` attribute is specified
13
+
14
+ ## 0.20.0
15
+
16
+ - Support `spinner` widget (leaving out automatic insertion of decimal point when digits are specified)
17
+ - Hello, Spinner! sample
18
+
19
+ ## 0.19.1
20
+
21
+ - Fix widget `font` property support for both `:bold` and `:italic` styles at the same time
22
+
3
23
  ## 0.19.0
4
24
 
5
25
  - Change `tab_item` default background/foreground color to better match Glimmer DSL for SWT
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.19.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))
146
+ **Alpha Version** 0.21.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.19.0'
264
+ gem 'glimmer-dsl-opal', '~> 0.21.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,81 @@ 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, Scale!
803
+
804
+ Add the following require statement to `app/assets/javascripts/application.rb`
805
+
806
+ ```ruby
807
+ require 'glimmer-dsl-opal/samples/hello/hello_scale'
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 Scale](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-scale.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, Scale!"
824
+
825
+ ![Glimmer DSL for Opal Hello Scale](images/glimmer-dsl-opal-hello-scale.png)
826
+
827
+ #### Hello, Slider!
828
+
829
+ Add the following require statement to `app/assets/javascripts/application.rb`
830
+
831
+ ```ruby
832
+ require 'glimmer-dsl-opal/samples/hello/hello_slider'
833
+ ```
834
+
835
+ Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
836
+
837
+ ![Glimmer DSL for SWT Hello Slider](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-slider.png)
838
+
839
+ Glimmer app on the web (using `glimmer-dsl-opal` gem):
840
+
841
+ Start the Rails server:
842
+ ```
843
+ rails s
844
+ ```
845
+
846
+ Visit `http://localhost:3000`
847
+
848
+ You should see "Hello, Slider!"
849
+
850
+ ![Glimmer DSL for Opal Hello Slider](images/glimmer-dsl-opal-hello-slider.png)
851
+
852
+ #### Hello, Spinner!
853
+
854
+ Add the following require statement to `app/assets/javascripts/application.rb`
855
+
856
+ ```ruby
857
+ require 'glimmer-dsl-opal/samples/hello/hello_spinner'
858
+ ```
859
+
860
+ Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
861
+
862
+ ![Glimmer DSL for SWT Hello Spinner](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-spinner.png)
863
+
864
+ Glimmer app on the web (using `glimmer-dsl-opal` gem):
865
+
866
+ Start the Rails server:
867
+ ```
868
+ rails s
869
+ ```
870
+
871
+ Visit `http://localhost:3000`
872
+
873
+ You should see "Hello, Spinner!"
874
+
875
+ ![Glimmer DSL for Opal Hello Spinner](images/glimmer-dsl-opal-hello-spinner.png)
876
+
802
877
  #### Hello, Browser!
803
878
 
804
879
  Add the following require statement to `app/assets/javascripts/application.rb`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.19.0
1
+ 0.21.0
@@ -0,0 +1,55 @@
1
+ # Copyright (c) 2020-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 HelloScale
23
+ include Glimmer::UI::CustomShell
24
+
25
+ attr_accessor :value
26
+
27
+ before_body do
28
+ @value = 50
29
+ end
30
+
31
+ body {
32
+ shell {
33
+ row_layout(:vertical) {
34
+ fill true
35
+ center true
36
+ }
37
+
38
+ text 'Hello, Scale!'
39
+
40
+ label(:center) {
41
+ text <= [self, :value]
42
+ }
43
+
44
+ scale { # optionally takes :vertical or :horizontal (default) SWT style
45
+ minimum 0
46
+ maximum 100
47
+ selection <=> [self, :value]
48
+ }
49
+
50
+ }
51
+
52
+ }
53
+ end
54
+
55
+ HelloScale.launch
@@ -0,0 +1,56 @@
1
+ # Copyright (c) 2020-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 HelloSlider
23
+ include Glimmer::UI::CustomShell
24
+
25
+ attr_accessor :value
26
+
27
+ before_body do
28
+ @value = 50
29
+ end
30
+
31
+ body {
32
+ shell {
33
+ row_layout(:vertical) {
34
+ fill true
35
+ center true
36
+ }
37
+
38
+ text 'Hello, Slider!'
39
+
40
+ label(:center) {
41
+ text <= [self, :value]
42
+ }
43
+
44
+ slider { # optionally takes :vertical or :horizontal (default) SWT style
45
+ minimum 0
46
+ maximum 110 # leave room for 10 extra (slider stops at 100)
47
+ page_increment 10 # page increment occurs when clicking area between slider and beginning or end
48
+ selection <=> [self, :value]
49
+ }
50
+
51
+ }
52
+
53
+ }
54
+ end
55
+
56
+ HelloSlider.launch
@@ -0,0 +1,78 @@
1
+ # Copyright (c) 2020-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&.to_a&.include?(:italic)
56
- tab_dom_element.css('font-weight', 'bold') if @font&.style == :bold || @font&.style&.to_a&.include?(:bold)
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,98 @@
1
+ # Copyright (c) 2020-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/swt/widget_proxy'
23
+
24
+ module Glimmer
25
+ module SWT
26
+ class ScaleProxy < WidgetProxy
27
+ attr_reader :selection, :minimum, :maximum, :increment
28
+
29
+ def initialize(parent, args, block)
30
+ super(parent, args, block)
31
+ dom_element.slider
32
+ end
33
+
34
+ def selection=(value)
35
+ old_value = @selection.to_f
36
+ @selection = value.to_f
37
+ dom_element.slider('option', 'value', @selection)
38
+ end
39
+ alias set_selection selection=
40
+
41
+ def minimum=(value)
42
+ @minimum = value.to_f
43
+ dom_element.slider('option', 'min', @minimum)
44
+ end
45
+
46
+ def maximum=(value)
47
+ @maximum = value.to_f
48
+ dom_element.slider('option', 'max', @maximum)
49
+ end
50
+
51
+ def increment=(value)
52
+ @increment = value.to_f
53
+ dom_element.slider('option', 'step', @increment)
54
+ end
55
+
56
+ def element
57
+ 'div'
58
+ end
59
+
60
+ def observation_request_to_event_mapping
61
+ {
62
+ 'on_widget_selected' => [
63
+ {
64
+ event: 'change',
65
+ event_handler: -> (event_listener) {
66
+ -> (event) {
67
+ self.selection = dom_element.slider('option', 'value')
68
+ event_listener.call(event)
69
+ }
70
+ }
71
+ },
72
+ {
73
+ event: 'slidestop',
74
+ event_handler: -> (event_listener) {
75
+ -> (event) {
76
+ self.selection = dom_element.slider('option', 'value')
77
+ event_listener.call(event)
78
+ }
79
+ }
80
+ },
81
+ ],
82
+ }
83
+ end
84
+
85
+ def dom
86
+ scale_selection = @selection
87
+ scale_id = id
88
+ scale_style = css
89
+ scale_class = name
90
+ options = {type: 'text', id: scale_id, style: scale_style, class: scale_class, value: scale_selection}
91
+ options = options.merge('disabled': 'disabled') unless @enabled
92
+ @dom ||= html {
93
+ div(options)
94
+ }.to_s
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,100 @@
1
+ # Copyright (c) 2020-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/swt/widget_proxy'
23
+
24
+ module Glimmer
25
+ module SWT
26
+ class SliderProxy < WidgetProxy
27
+ attr_reader :selection, :minimum, :maximum, :page_increment
28
+
29
+ def initialize(parent, args, block)
30
+ super(parent, args, block)
31
+ dom_element.slider
32
+ self.page_increment = 10 # default page increment
33
+ end
34
+
35
+ def selection=(value)
36
+ old_value = @selection.to_f
37
+ @selection = value.to_f
38
+ dom_element.slider('option', 'value', @selection)
39
+ end
40
+ alias set_selection selection=
41
+
42
+ def minimum=(value)
43
+ @minimum = value.to_f
44
+ dom_element.slider('option', 'min', @minimum)
45
+ end
46
+
47
+ def maximum=(value)
48
+ # being compatible with slider quirk in Glimmer DSL for SWT (does not reach max yet max - 10)
49
+ @maximum = value.to_f - 10
50
+ dom_element.slider('option', 'max', @maximum)
51
+ end
52
+
53
+ def page_increment=(value)
54
+ @page_increment = value.to_f
55
+ dom_element.slider('option', 'step', @page_increment)
56
+ end
57
+
58
+ def element
59
+ 'div'
60
+ end
61
+
62
+ def observation_request_to_event_mapping
63
+ {
64
+ 'on_widget_selected' => [
65
+ {
66
+ event: 'change',
67
+ event_handler: -> (event_listener) {
68
+ -> (event) {
69
+ self.selection = dom_element.slider('option', 'value')
70
+ event_listener.call(event)
71
+ }
72
+ }
73
+ },
74
+ {
75
+ event: 'slidestop',
76
+ event_handler: -> (event_listener) {
77
+ -> (event) {
78
+ self.selection = dom_element.slider('option', 'value')
79
+ event_listener.call(event)
80
+ }
81
+ }
82
+ },
83
+ ],
84
+ }
85
+ end
86
+
87
+ def dom
88
+ slider_selection = @selection
89
+ slider_id = id
90
+ slider_style = css
91
+ slider_class = name
92
+ options = {type: 'text', id: slider_id, style: slider_style, class: slider_class, value: slider_selection}
93
+ options = options.merge('disabled': 'disabled') unless @enabled
94
+ @dom ||= html {
95
+ div(options)
96
+ }.to_s
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,211 @@
1
+ # Copyright (c) 2020-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/swt/widget_proxy'
23
+
24
+ module Glimmer
25
+ module SWT
26
+ class SpinnerProxy < WidgetProxy
27
+ attr_reader :minimum, :maximum, :increment, :page_increment, :digits
28
+
29
+ def initialize(parent, args, block)
30
+ super(parent, args, block)
31
+ @increment = 1
32
+ @digits = 0
33
+ dom_element.spinner
34
+ end
35
+
36
+ def selection=(value, format_digits: true)
37
+ old_value = @selection.to_f
38
+ if @selection.nil?
39
+ @selection = value.to_f / divider
40
+ else
41
+ @selection = value.to_f
42
+ end
43
+ if value.to_i != old_value.to_i
44
+ if format_digits && @digits.to_i > 0
45
+ new_value = "%0.#{@digits.to_i}f" % @selection
46
+ dom_element.value = new_value
47
+ else
48
+ dom_element.value = @selection if @selection != 0
49
+ end
50
+ end
51
+ end
52
+ alias set_selection selection=
53
+
54
+ def selection
55
+ @selection && @selection * divider
56
+ end
57
+
58
+ def text=(value)
59
+ self.selection = value.to_f
60
+ end
61
+
62
+ def text
63
+ self.selection.to_s
64
+ end
65
+
66
+ def minimum=(value)
67
+ @minimum = value.to_f / divider
68
+ dom_element.spinner('option', 'min', @minimum)
69
+ end
70
+
71
+ def maximum=(value)
72
+ @maximum = value.to_f / divider
73
+ dom_element.spinner('option', 'max', @maximum)
74
+ end
75
+
76
+ def increment=(value)
77
+ @increment = value.to_f / divider
78
+ dom_element.spinner('option', 'step', @increment)
79
+ end
80
+
81
+ def page_increment=(value)
82
+ @page_increment = value.to_f / (@increment * divider)
83
+ dom_element.spinner('option', 'page', @page_increment)
84
+ end
85
+
86
+ def divider
87
+ ('1' + '0'*@digits.to_i).to_f
88
+ end
89
+
90
+ def digits=(value)
91
+ @digits = value
92
+ dom_element.spinner('option', 'numberFormat', "n") if @digits.to_i > 0
93
+ end
94
+
95
+ def element
96
+ 'input'
97
+ end
98
+
99
+ def observation_request_to_event_mapping
100
+ {
101
+ 'on_widget_selected' => [
102
+ {
103
+ event: 'change',
104
+ event_handler: -> (event_listener) {
105
+ -> (event) {
106
+ self.selection = event.target.value
107
+ event_listener.call(event)
108
+ }
109
+ }
110
+ },
111
+ {
112
+ event: 'keyup',
113
+ event_handler: -> (event_listener) {
114
+ -> (event) {
115
+ @keyup = true # ensures spinstop event does not set selection if caused by key up entry
116
+ }
117
+ }
118
+ },
119
+ {
120
+ event: 'spin',
121
+ event_handler: -> (event_listener) {
122
+ -> (event) {
123
+ @keyup = false
124
+ }
125
+ }
126
+ },
127
+ {
128
+ event: 'spinstop',
129
+ event_handler: -> (event_listener) {
130
+ -> (event) {
131
+ self.set_selection(event.target.value, format_digits: !@keyup)
132
+ @keyup = false
133
+ event_listener.call(event)
134
+ }
135
+ }
136
+ },
137
+ ],
138
+ 'on_modify_text' => {
139
+ event: 'keyup',
140
+ event_handler: -> (event_listener) {
141
+ -> (event) {
142
+ # TODO consider unifying this event handler with on_key_pressed by relying on its result instead of hooking another keyup event
143
+ if @last_key_pressed_event.nil? || @last_key_pressed_event.doit
144
+ self.text = event.target.value
145
+ event_listener.call(event)
146
+ else
147
+ # TODO Fix doit false, it's not stopping input
148
+ event.prevent
149
+ event.prevent_default
150
+ event.stop_propagation
151
+ event.stop_immediate_propagation
152
+ end
153
+ }
154
+ }
155
+ },
156
+ 'on_key_pressed' => {
157
+ event: 'keydown',
158
+ event_handler: -> (event_listener) {
159
+ -> (event) {
160
+ @last_key_pressed_event = event
161
+ self.text = event.target.value
162
+ # TODO generalize this solution to all widgets that support key presses
163
+ # TODO support event.location once DOM3 is supported by opal-jquery
164
+ event.define_singleton_method(:keyCode) {event.which}
165
+ event.define_singleton_method(:key_code, &event.method(:keyCode))
166
+ event.define_singleton_method(:character) {event.which.chr}
167
+ event.define_singleton_method(:stateMask) do
168
+ state_mask = 0
169
+ state_mask |= SWTProxy[:alt] if event.alt_key
170
+ state_mask |= SWTProxy[:ctrl] if event.ctrl_key
171
+ state_mask |= SWTProxy[:shift] if event.shift_key
172
+ state_mask |= SWTProxy[:command] if event.meta_key
173
+ state_mask
174
+ end
175
+ event.define_singleton_method(:state_mask, &event.method(:stateMask))
176
+ doit = true
177
+ event.define_singleton_method(:doit=) do |value|
178
+ doit = value
179
+ end
180
+ event.define_singleton_method(:doit) { doit }
181
+ event_listener.call(event)
182
+
183
+ # TODO Fix doit false, it's not stopping input
184
+ unless doit
185
+ event.prevent
186
+ event.prevent_default
187
+ event.stop_propagation
188
+ event.stop_immediate_propagation
189
+ end
190
+
191
+ doit
192
+ }
193
+ }
194
+ },
195
+ }
196
+ end
197
+
198
+ def dom
199
+ text_text = @text
200
+ text_id = id
201
+ text_style = css
202
+ text_class = name
203
+ options = {type: 'text', id: text_id, style: text_style, class: text_class, value: text_text, style: 'min-width: 27px;'}
204
+ options = options.merge('disabled': 'disabled') unless @enabled
205
+ @dom ||= html {
206
+ input(options)
207
+ }.to_s
208
+ end
209
+ end
210
+ end
211
+ end
@@ -81,7 +81,6 @@ module Glimmer
81
81
  text_id = id
82
82
  text_style = css
83
83
  text_class = name
84
- # TODO support password field
85
84
  options = {type: 'text', id: text_id, style: text_style, class: text_class, value: text_text, style: 'min-width: 27px;'}
86
85
  options = options.merge('disabled': 'disabled') unless @enabled
87
86
  options = options.merge(type: 'password') if has_style?(:password)
@@ -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
241
- dom_element.css('font-weight', 'bold') if @font&.style == :bold
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,27 @@ module Glimmer
851
851
  # }
852
852
  # end,
853
853
  # },
854
+ ScaleProxy => {
855
+ :selection => lambda do |observer|
856
+ on_widget_selected { |selection_event|
857
+ observer.call(selection)
858
+ }
859
+ end
860
+ },
861
+ SliderProxy => {
862
+ :selection => lambda do |observer|
863
+ on_widget_selected { |selection_event|
864
+ observer.call(selection)
865
+ }
866
+ end
867
+ },
868
+ SpinnerProxy => {
869
+ :selection => lambda do |observer|
870
+ on_widget_selected { |selection_event|
871
+ observer.call(selection)
872
+ }
873
+ end
874
+ },
854
875
  TextProxy => {
855
876
  :text => lambda do |observer|
856
877
  on_modify_text { |modify_event|
@@ -943,13 +964,6 @@ module Glimmer
943
964
  # observer.call(getSelection)
944
965
  # }
945
966
  # end
946
- # },
947
- # Java::OrgEclipseSwtWidgets::Spinner => {
948
- # :selection => lambda do |observer|
949
- # on_widget_selected { |selection_event|
950
- # observer.call(getSelection)
951
- # }
952
- # end
953
967
  # },
954
968
  }
955
969
  end
@@ -983,7 +997,10 @@ require 'glimmer/swt/table_item_proxy'
983
997
  require 'glimmer/swt/table_proxy'
984
998
  require 'glimmer/swt/text_proxy'
985
999
  require 'glimmer/swt/radio_proxy'
1000
+ require 'glimmer/swt/scale_proxy'
986
1001
  require 'glimmer/swt/scrolled_composite_proxy'
1002
+ require 'glimmer/swt/slider_proxy'
1003
+ require 'glimmer/swt/spinner_proxy'
987
1004
  require 'glimmer/swt/styled_text_proxy'
988
1005
 
989
1006
  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.19.0
4
+ version: 0.21.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-15 00:00:00.000000000 Z
11
+ date: 2021-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -307,6 +307,9 @@ 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_scale.rb
311
+ - lib/glimmer-dsl-opal/samples/hello/hello_slider.rb
312
+ - lib/glimmer-dsl-opal/samples/hello/hello_spinner.rb
310
313
  - lib/glimmer-dsl-opal/samples/hello/hello_tab.rb
311
314
  - lib/glimmer-dsl-opal/samples/hello/hello_table.rb
312
315
  - lib/glimmer-dsl-opal/samples/hello/hello_table/baseball_park.png
@@ -418,8 +421,11 @@ files:
418
421
  - lib/glimmer/swt/property_owner.rb
419
422
  - lib/glimmer/swt/radio_proxy.rb
420
423
  - lib/glimmer/swt/row_layout_proxy.rb
424
+ - lib/glimmer/swt/scale_proxy.rb
421
425
  - lib/glimmer/swt/scrolled_composite_proxy.rb
422
426
  - lib/glimmer/swt/shell_proxy.rb
427
+ - lib/glimmer/swt/slider_proxy.rb
428
+ - lib/glimmer/swt/spinner_proxy.rb
423
429
  - lib/glimmer/swt/style_constantizable.rb
424
430
  - lib/glimmer/swt/styled_text_proxy.rb
425
431
  - lib/glimmer/swt/swt_proxy.rb