glimmer-dsl-opal 0.26.3 → 0.27.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: cabde097ac994643d49e0af9b78fc1bbc7b2eb15857deb8741c557f4e676a4da
4
- data.tar.gz: a198b93dc21bc2ea93e8542a84bbb83919be9ad0d63355f27dcf1fe4991b682c
3
+ metadata.gz: 885895f5a47d453757426eb0b05e0b413972ef5b11f5c9045c8df92c4c1cd03d
4
+ data.tar.gz: a33b454cd1229e8b6d640d31f55379875fdde969b3634ef85e524496b277117f
5
5
  SHA512:
6
- metadata.gz: b77f3a496e6dd8e8afea59185ba46306b07e9cb0e4fb5e41b97151886292ab1735008e5a58f08251874e25ede8b781f819498f2ef0c84ba4f357f8c13b7c2c0a
7
- data.tar.gz: bc9646367d1cd6476f60edf98cf2a94ff24dd6bff14756b3bcbc1365e79a3cb22869c626bc897f94784c59e3cffe30fe5c5e8fe90915a23fc042d3b4f836ffae
6
+ metadata.gz: dad2612713d1ebcc95cc08fc0bdaddbb45a9f07032af5e583da857adba54327752f853d8f28bfd76d545c7271e9be86e825d42d600c798775328864e8d651927
7
+ data.tar.gz: 037c3e6f77c68a8edf343b3323b543f708adf5f41dffb03944148670ac46aa786cafbecb12675c24a5d4c5e3242ff2929886214d6ea43d9017de588ddc5db486
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.27.0
4
+
5
+ - Hello, Text!
6
+ - Support unbordered `text` widget if SWT style `:none` was passed
7
+ - Support `:center`, `:left`, `:right` SWT styles for `text` widget
8
+ - Support `:read_only` SWT style for `text` widget
9
+ - Support `text` widget `on_verify_text` `event.doit = false` cancellation feature
10
+
3
11
  ## 0.26.3
4
12
 
5
13
  - Support key_event.key_location in all key capturing widgets, not just display
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.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))
148
+ **Alpha Version** 0.27.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))
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)
@@ -269,7 +269,7 @@ gem 'opal', '1.0.5'
269
269
  gem 'opal-rails', '1.1.2'
270
270
  gem 'opal-async', '~> 1.4.0'
271
271
  gem 'opal-jquery', '~> 0.4.4'
272
- gem 'glimmer-dsl-opal', '~> 0.26.3'
272
+ gem 'glimmer-dsl-opal', '~> 0.27.0'
273
273
  gem 'glimmer-dsl-xml', '~> 1.2.0', require: false
274
274
  gem 'glimmer-dsl-css', '~> 1.2.0', require: false
275
275
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.26.3
1
+ 0.27.0
@@ -28,7 +28,7 @@ module Glimmer
28
28
  attr_reader :closeable_children
29
29
 
30
30
  def initialize(parent, args, block)
31
- @closeable_children = args.detect { |arg| SWTProxy[:close] == SWTProxy[arg] }
31
+ @closeable_children = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:close] }
32
32
  super(parent, args, block)
33
33
  end
34
34
 
@@ -3,7 +3,26 @@ require 'glimmer/swt/widget_proxy'
3
3
  module Glimmer
4
4
  module SWT
5
5
  class TextProxy < WidgetProxy
6
- attr_reader :text
6
+ attr_reader :text, :border, :left, :center, :right, :read_only, :wrap, :multi
7
+ alias border? border
8
+ alias left? left
9
+ alias center? center
10
+ alias right? right
11
+ alias read_only? read_only
12
+ alias wrap? wrap
13
+ alias multi? multi
14
+
15
+ def initialize(parent, args, block)
16
+ args << :border if args.empty?
17
+ @border = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:border] }
18
+ @left = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:left] }
19
+ @center = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:center] }
20
+ @right = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:right] }
21
+ @read_only = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:read_only] }
22
+ @wrap = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:wrap] }
23
+ @multi = !!args.detect { |arg| SWTProxy[arg] == SWTProxy[:multi] }
24
+ super(parent, args, block)
25
+ end
7
26
 
8
27
  def text=(value)
9
28
  @text = value
@@ -11,43 +30,86 @@ module Glimmer
11
30
  end
12
31
 
13
32
  def element
14
- 'input'
33
+ @wrap || @multi ? 'textarea' : 'input'
15
34
  end
16
35
 
17
36
  def observation_request_to_event_mapping
37
+ myself = self
18
38
  {
19
- 'on_modify_text' => {
20
- event: 'keyup',
21
- event_handler: -> (event_listener) {
22
- -> (event) {
23
- # TODO consider unifying this event handler with on_key_pressed by relying on its result instead of hooking another keyup event
24
- # TODO add all attributes for on_modify_text modify event
25
- if @last_key_pressed_event.nil? || @last_key_pressed_event.doit
39
+ 'on_verify_text' => [
40
+ {
41
+ event: 'beforeinput',
42
+ event_handler: -> (event_listener) {
43
+ -> (event) {
44
+ event.define_singleton_method(:widget) {myself}
45
+ event.define_singleton_method(:text) {`#{event.to_n}.originalEvent.data` || ''}
46
+ selection_start = `#{event.target}[0].selectionStart`
47
+ selection_end = `#{event.target}[0].selectionEnd`
48
+ if `#{event.to_n}.originalEvent.inputType` == 'deleteContentBackward' && selection_start == selection_end
49
+ selection_start -= 1
50
+ selection_start = 0 if selection_start < 0
51
+ end
52
+ event.define_singleton_method(:start) do
53
+ selection_start
54
+ end
55
+ event.define_singleton_method(:end) {selection_end}
56
+ doit = true
57
+ event.define_singleton_method(:doit=) do |value|
58
+ doit = value
59
+ end
60
+ event.define_singleton_method(:doit) { doit }
61
+ event_listener.call(event)
62
+
63
+ if !doit
64
+ `#{event.to_n}.originalEvent.returnValue = false`
65
+ end
66
+
67
+ doit
68
+ }
69
+ }
70
+ },
71
+ {
72
+ event: 'input',
73
+ event_handler: -> (event_listener) {
74
+ -> (event) {
75
+ event.define_singleton_method(:widget) {myself}
76
+ @text = event.target.value
77
+ }
78
+ }
79
+ }
80
+ ],
81
+ 'on_modify_text' => [
82
+ {
83
+ event: 'input',
84
+ event_handler: -> (event_listener) {
85
+ -> (event) {
86
+ # TODO add all attributes for on_modify_text modify event
87
+ event.define_singleton_method(:widget) {myself}
26
88
  @text = event.target.value
27
89
  event_listener.call(event)
28
- else
29
- # TODO Fix doit false, it's not stopping input
30
- event.prevent
31
- event.prevent_default
32
- event.stop_propagation
33
- event.stop_immediate_propagation
34
- end
90
+ }
35
91
  }
36
92
  }
37
- },
93
+ ],
38
94
  }
39
95
  end
40
96
 
41
97
  def dom
42
98
  text_text = @text
43
99
  text_id = id
44
- text_style = css
100
+ text_style = 'min-width: 27px; '
101
+ text_style += 'border: none; ' if !@border
102
+ text_style += 'text-align: left; ' if @left
103
+ text_style += 'text-align: center; ' if @center
104
+ text_style += 'text-align: right; ' if @right
45
105
  text_class = name
46
- options = {type: 'text', id: text_id, style: text_style, class: text_class, value: text_text, style: 'min-width: 27px;'}
106
+ options = {type: 'text', id: text_id, style: text_style, class: text_class, value: text_text}
47
107
  options = options.merge('disabled': 'disabled') unless @enabled
108
+ options = options.merge('readonly': 'readonly') if @read_only
109
+ options = options.merge('contenteditable': 'true')
48
110
  options = options.merge(type: 'password') if has_style?(:password)
49
111
  @dom ||= html {
50
- input(options)
112
+ send(element, options)
51
113
  }.to_s
52
114
  end
53
115
  end
@@ -158,7 +158,7 @@ module Glimmer
158
158
  @block = block
159
159
  # TODO consider changing children to an array (why is it a Set if order matters?)
160
160
  @children = Set.new # TODO consider moving to composite
161
- @enabled = true
161
+ @enabled = true if @enabled.nil?
162
162
  DEFAULT_INITIALIZERS[self.class.underscored_widget_name(self).to_s.to_sym]&.call(self)
163
163
  @parent.post_initialize_child(self) # TODO rename to post_initialize_child to be closer to glimmer-dsl-swt terminology
164
164
  end
@@ -616,6 +616,7 @@ module Glimmer
616
616
  JS_KEY_CODE_TO_SWT_KEY_CODE_MAP[event.which] || event.which
617
617
  }
618
618
  event.define_singleton_method(:key_code, &event.method(:keyCode))
619
+ event.define_singleton_method(:widget) {myself}
619
620
  event.define_singleton_method(:character) {event.which.chr}
620
621
  event.define_singleton_method(:stateMask) do
621
622
  state_mask = 0
@@ -658,6 +659,7 @@ module Glimmer
658
659
  JS_KEY_CODE_TO_SWT_KEY_CODE_MAP[event.which] || event.which
659
660
  }
660
661
  event.define_singleton_method(:key_code, &event.method(:keyCode))
662
+ event.define_singleton_method(:widget) {myself}
661
663
  event.define_singleton_method(:character) {event.which.chr}
662
664
  event.define_singleton_method(:stateMask) do
663
665
  state_mask = 0
@@ -0,0 +1,149 @@
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 HelloText
23
+ include Glimmer::UI::CustomShell
24
+
25
+ attr_accessor :default, :no_border, :center, :left, :right, :password, :telephone, :read_only, :wrap, :multi
26
+
27
+ before_body do
28
+ self.default = 'default is :border style'
29
+ self.no_border = 'no border'
30
+ self.center = 'centered'
31
+ self.left = 'left-aligned'
32
+ self.right = 'right-aligned'
33
+ self.password = 'password'
34
+ self.telephone = '555-555-5555'
35
+ self.read_only = 'Telephone area code is 555'
36
+ self.wrap = 'wraps if text content is too long like this example'
37
+ self.multi = "multi-line enables hitting enter,\nbut works like wrap on the web"
38
+ end
39
+
40
+ body {
41
+ shell {
42
+ grid_layout 2, false
43
+
44
+ text 'Hello, Text!'
45
+ minimum_size 350, 100
46
+
47
+ label {
48
+ text 'text'
49
+ }
50
+ text { # includes :border style by default
51
+ layout_data :fill, :center, true, false
52
+ text <=> [self, :default]
53
+ }
54
+
55
+ label {
56
+ text 'text(:none)'
57
+ }
58
+ text(:none) { # no border
59
+ layout_data :fill, :center, true, false
60
+ text <=> [self, :no_border]
61
+ }
62
+
63
+ label {
64
+ text 'text(:center, :border)'
65
+ }
66
+ text(:center, :border) {
67
+ layout_data :fill, :center, true, false
68
+ text <=> [self, :center]
69
+ }
70
+
71
+ label {
72
+ text 'text(:left, :border)'
73
+ }
74
+ text(:left, :border) {
75
+ layout_data :fill, :center, true, false
76
+ text <=> [self, :left]
77
+ }
78
+
79
+ label {
80
+ text 'text(:right, :border)'
81
+ }
82
+ text(:right, :border) {
83
+ layout_data :fill, :center, true, false
84
+ text <=> [self, :right]
85
+ }
86
+
87
+ label {
88
+ text 'text(:password, :border)'
89
+ }
90
+ text(:password, :border) {
91
+ layout_data :fill, :center, true, false
92
+ text <=> [self, :password]
93
+ }
94
+
95
+ label {
96
+ text 'text(:read_only, :border)'
97
+ }
98
+ text(:read_only, :border) {
99
+ layout_data :fill, :center, true, false
100
+ text <=> [self, :read_only]
101
+ }
102
+
103
+ label {
104
+ text 'text with event handlers'
105
+ }
106
+ text {
107
+ layout_data :fill, :center, true, false
108
+ text <=> [self, :telephone]
109
+
110
+ # this event kicks in just after the user typed and before modifying the text attribute value
111
+ on_verify_text do |verify_event|
112
+ new_text = verify_event.widget.text.clone
113
+ # new_text[verify_event.start...verify_event.end] = verify_event.text # Opal does not allow string mutation like JRuby in Glimmer DSL for SWT
114
+ new_text = "#{new_text[0...verify_event.start]}#{verify_event.text}#{new_text[verify_event.end..-1]}"
115
+ verify_event.doit = telephone?(new_text)
116
+ end
117
+
118
+ # this event kicks in just after the text widget is verified and modified
119
+ on_modify_text do |modify_event|
120
+ self.read_only = "Telephone area code is #{modify_event.widget.text.gsub(/[^0-9]/, '')[0...3]}"
121
+ end
122
+ }
123
+
124
+ label {
125
+ text 'text(:wrap, :border)'
126
+ }
127
+ text(:wrap, :border) {
128
+ layout_data(:fill, :center, true, false) {
129
+ width_hint 100
130
+ }
131
+ text <=> [self, :wrap]
132
+ }
133
+
134
+ label {
135
+ text 'text(:multi, :border)'
136
+ }
137
+ text(:multi, :border) {
138
+ layout_data :fill, :center, true, false
139
+ text <=> [self, :multi]
140
+ }
141
+ }
142
+ }
143
+
144
+ def telephone?(text)
145
+ !!text.match(/^\d{0,3}[-.\/]?\d{0,3}[-.\/]?\d{0,4}$/)
146
+ end
147
+ end
148
+
149
+ HelloText.launch
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.26.3
4
+ version: 0.27.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-26 00:00:00.000000000 Z
11
+ date: 2021-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -328,6 +328,7 @@ files:
328
328
  - lib/glimmer-dsl-opal/samples/hello/hello_tab.rb
329
329
  - lib/glimmer-dsl-opal/samples/hello/hello_table.rb
330
330
  - lib/glimmer-dsl-opal/samples/hello/hello_table/baseball_park.png
331
+ - lib/glimmer-dsl-opal/samples/hello/hello_text.rb
331
332
  - lib/glimmer-dsl-opal/samples/hello/hello_world.rb
332
333
  - lib/glimmer-dsl-opal/samples/hello/images/denmark.png
333
334
  - lib/glimmer-dsl-opal/samples/hello/images/finland.png