glimmer-dsl-opal 0.15.1 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,241 @@
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 HelloLayout
23
+ include Glimmer::UI::CustomShell
24
+
25
+ body {
26
+ shell {
27
+ # shell (which is a composite) has fill_layout(:horizontal) by default with no margins
28
+ text 'Hello, Layout!'
29
+ tab_folder {
30
+
31
+ # every tab item has its own composite, which can set a layout
32
+ tab_item {
33
+ text 'Fill Layout (horizontal)'
34
+
35
+ fill_layout(:horizontal) {
36
+ margin_width 30
37
+ margin_height 40
38
+ spacing 5
39
+ }
40
+
41
+ 10.times { |n|
42
+ label {
43
+ text "<label #{n+1}>"
44
+ }
45
+
46
+ }
47
+
48
+ }
49
+
50
+ tab_item {
51
+ text 'Fill Layout (vertical)'
52
+
53
+ fill_layout {
54
+ type :vertical # alternative way of specifying orientation
55
+ margin_width 40
56
+ margin_height 30
57
+ spacing 10
58
+ }
59
+
60
+ 10.times { |n|
61
+ label(:center) {
62
+ text "<label #{n+1}>"
63
+ }
64
+
65
+ }
66
+
67
+ }
68
+
69
+ tab_item {
70
+ text 'Row Layout (horizontal)'
71
+
72
+ row_layout(:horizontal) {
73
+ # row layout has margin attributes for top, left, right, and bottom
74
+ # in addition to width and height (and sets margin_width and margin_height to 5 by default)
75
+ margin_top 40
76
+ margin_left 30
77
+ spacing 5
78
+ wrap false
79
+ center true
80
+ justify true
81
+ }
82
+
83
+ 10.times { |n|
84
+ label {
85
+ text "<label #{n+1}>"
86
+ }
87
+
88
+ }
89
+
90
+ }
91
+
92
+ tab_item {
93
+ text 'Row Layout (wrap on shrink)'
94
+
95
+ row_layout { # :horizontal is the default type
96
+ margin_height 40
97
+ margin_width 30
98
+ spacing 35
99
+ # wrap true # is the default
100
+ }
101
+
102
+ 10.times { |n|
103
+ label {
104
+ text "<label #{n+1}>"
105
+ }
106
+
107
+ }
108
+
109
+ }
110
+
111
+ tab_item {
112
+ text 'Row Layout (vertical)'
113
+ background :yellow
114
+
115
+ row_layout(:vertical) { |l|
116
+ margin_height 0
117
+ margin_width 0
118
+ spacing 10
119
+ fill true # fills horizontally to match the widest child (opposite to row layout orientation)
120
+ center false # enable and disable fill to see what this does
121
+ }
122
+
123
+ 10.times { |n|
124
+ label {
125
+ # layout_data allows a widget to tweak its layout configuration (generating RowData object for RowLayout)
126
+ layout_data {
127
+ height 30
128
+ # width unspecified yet calculated
129
+ }
130
+ text "<this is a ver#{'r'*(rand*200).to_i}y wide label #{n+1}>"
131
+ background :green
132
+ }
133
+
134
+ }
135
+
136
+ }
137
+
138
+ tab_item {
139
+ text 'Grid Layout'
140
+
141
+ grid_layout {
142
+ num_columns 5
143
+ make_columns_equal_width true
144
+ horizontal_spacing 15
145
+ vertical_spacing 10
146
+
147
+ # grid layout has margin attributes for top, left, right, and bottom
148
+ # in addition to width and height (and sets margin_width and margin_height to 5 by default)
149
+ margin_height 0
150
+ margin_top 20
151
+ }
152
+
153
+ 10.times { |n|
154
+ label {
155
+ text "<this label is wide enough to fill #{n+1}>"
156
+ background :white
157
+ }
158
+ }
159
+
160
+ label {
161
+ # layout_data allows a widget to tweak its layout configuration (generating GridData object for GridLayout)
162
+ layout_data {
163
+ width_hint 120
164
+ height_hint 40
165
+ }
166
+ text "<this label is clipped>"
167
+ background :cyan
168
+ }
169
+
170
+ label {
171
+ # layout_data allows a widget to tweak its layout configuration (generating GridData object for GridLayout)
172
+ layout_data {
173
+ horizontal_span 2
174
+ }
175
+ text "<this label spans two columns, so it can contain more text than normal>"
176
+ background :green
177
+ }
178
+
179
+ label {
180
+ # layout_data allows a widget to tweak its layout configuration (generating GridData object for GridLayout)
181
+ layout_data {
182
+ vertical_span 2
183
+ vertical_alignment :fill
184
+ }
185
+ text "<this label spans two rows, \nso it can contain new lines\n1\n2\n3\n4\n5\n6\n7>"
186
+ background :yellow
187
+ }
188
+
189
+ 5.times { label } # just filler
190
+
191
+ label {
192
+
193
+ # layout_data allows a widget to tweak its layout configuration (generating GridData object for GridLayout)
194
+ layout_data {
195
+ horizontal_span 5
196
+ horizontal_alignment :fill # could be :beginning, :center or :end too
197
+ vertical_alignment :fill # could be :beginning, :center, or :end too
198
+ grab_excess_horizontal_space true
199
+ grab_excess_vertical_space true
200
+ }
201
+
202
+ # this is a short alternative for specifying what is above
203
+ # layout_data(:fill, :fill, true, true) {
204
+ # horizontal_span 5
205
+ # }
206
+
207
+ text "<this label fills all the space it can get\nhorizontally and vertically>"
208
+ background :magenta
209
+ }
210
+
211
+ }
212
+
213
+
214
+ tab_item {
215
+ text 'Grid Layout (non-equal columns)'
216
+
217
+ grid_layout(2, false) # alt syntax: (numColumns, make_columns_equal_width)
218
+
219
+ 10.times { |n|
220
+ label {
221
+ text "Field #{n+1}"
222
+ }
223
+ text {
224
+ layout_data {
225
+ width_hint 600
226
+ }
227
+
228
+ text "Please enter text"
229
+ }
230
+ }
231
+
232
+ }
233
+
234
+ }
235
+
236
+ }
237
+
238
+ }
239
+ end
240
+
241
+ HelloLayout.launch
@@ -0,0 +1,11 @@
1
+ module Glimmer
2
+ # Consumer Rails apps can set these attributes in their assets.rb file
3
+ module Config
4
+ class << self
5
+ # (server-side option) used to collect image paths for copying to assets & matching in Opal to download and use in Glimmer GUI
6
+ def gems_having_image_paths
7
+ @gems_having_image_paths ||= []
8
+ end
9
+ end
10
+ end
11
+ end
@@ -37,6 +37,9 @@ 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
40
43
  raise Glimmer::Error, "menu may only be nested under a widget (like shell or another menu)!"
41
44
  end
42
45
  end
@@ -0,0 +1,42 @@
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
+ require 'glimmer/swt/button_proxy'
24
+
25
+ module Glimmer
26
+ module SWT
27
+ class ArrowProxy < ButtonProxy
28
+ def initialize(parent, args, block)
29
+ if args.to_a.include?(:left)
30
+ @text = '<'
31
+ elsif args.to_a.include?(:right)
32
+ @text = '>'
33
+ elsif args.to_a.include?(:up)
34
+ @text = '^'
35
+ else
36
+ @text = 'v'
37
+ end
38
+ super(parent, args, block)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,24 @@
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
+
1
22
  require 'glimmer/swt/widget_proxy'
2
23
  require 'glimmer/swt/radio_proxy'
3
24
  require 'glimmer/swt/checkbox_proxy'
@@ -11,6 +32,8 @@ module Glimmer
11
32
  RadioProxy.new(parent, args, block)
12
33
  elsif args.to_a.include?(:check)
13
34
  CheckboxProxy.new(parent, args, block)
35
+ elsif args.to_a.include?(:arrow)
36
+ ArrowProxy.new(parent, args, block)
14
37
  else
15
38
  new(parent, args, block)
16
39
  end
@@ -29,9 +52,21 @@ module Glimmer
29
52
  end
30
53
 
31
54
  def observation_request_to_event_mapping
55
+ myself = self
32
56
  {
33
57
  'on_widget_selected' => {
34
- event: 'click'
58
+ event: 'click',
59
+ event_handler: -> (event_listener) {
60
+ -> (event) {
61
+ event.define_singleton_method(:widget) {myself}
62
+ doit = true
63
+ event.define_singleton_method(:doit=) do |value|
64
+ doit = value
65
+ end
66
+ event.define_singleton_method(:doit) { doit }
67
+ event_listener.call(event)
68
+ }
69
+ }
35
70
  },
36
71
  }
37
72
  end
@@ -28,13 +28,11 @@ module Glimmer
28
28
 
29
29
  def initialize(parent, args)
30
30
  super(parent, args)
31
- @type = @args.first || :horizontal
31
+ self.type = @args.first || :horizontal
32
32
  self.margin_width = 15
33
33
  self.margin_height = 15
34
34
  @parent.css_classes << 'fill-layout'
35
- @parent.css_classes << (horizontal? ? 'fill-layout-horizontal' : 'fill-layout-vertical')
36
35
  @parent.dom_element.add_class('fill-layout')
37
- @parent.dom_element.add_class(horizontal? ? 'fill-layout-horizontal' : 'fill-layout-vertical')
38
36
  end
39
37
 
40
38
  def horizontal?
@@ -44,6 +42,14 @@ module Glimmer
44
42
  def vertical?
45
43
  @type == :vertical
46
44
  end
45
+
46
+ def type=(value)
47
+ @parent.dom_element.remove_class(horizontal? ? 'fill-layout-horizontal' : 'fill-layout-vertical')
48
+ @parent.css_classes.delete(horizontal? ? 'fill-layout-horizontal' : 'fill-layout-vertical')
49
+ @type = value
50
+ @parent.dom_element.add_class(horizontal? ? 'fill-layout-horizontal' : 'fill-layout-vertical')
51
+ @parent.css_classes << horizontal? ? 'fill-layout-horizontal' : 'fill-layout-vertical'
52
+ end
47
53
 
48
54
  def margin_width=(pixels)
49
55
  @margin_width = pixels
@@ -12,48 +12,31 @@ module Glimmer
12
12
  }
13
13
  CSS
14
14
 
15
- attr_reader :num_columns, :make_columns_equal_width, :horizontal_spacing, :vertical_spacing, :margin_width, :margin_height
15
+ attr_reader :num_columns, :make_columns_equal_width, :horizontal_spacing, :vertical_spacing, :margin_width, :margin_height, :margin_top, :margin_right, :margin_bottom, :margin_left
16
16
 
17
17
  def num_columns=(columns)
18
18
  @num_columns = columns
19
- # TODO do the following instead of reapply
20
- # @parent.add_css_class("num-columns-#{@num_columns}")
21
- # reinitialize # TODO reimplement without using reinitialize
22
- layout_css = <<~CSS
23
- grid-template-columns: #{'auto ' * @num_columns.to_i};
24
- grid-row-gap: #{@vertical_spacing}px;
25
- grid-column-gap: #{@horizontal_spacing}px;
26
- CSS
27
- if @parent.css_classes.include?('grid-layout')
28
- layout_css.split(";").map(&:strip).map {|l| l.split(':').map(&:strip)}.each do |key, value|
29
- @parent.dom_element.css(key, value) unless key.nil?
30
- end
31
- if @parent.is_a?(GroupProxy)
32
- @parent.dom_element.find('legend').css('grid-column-start', "span #{@num_columns.to_i}")
33
- end
34
- else
35
- layout_css.split(";").map(&:strip).map {|l| l.split(':').map(&:strip)}.each do |key, value|
36
- @parent.dom_element.css(key, 'initial') unless key.nil?
37
- end
38
- end
19
+ @parent.dom_element.css('grid-template-columns', 'auto ' * @num_columns.to_i)
20
+ @parent.dom_element.find('legend').css('grid-column-start', "span #{@num_columns.to_i}") if @parent.is_a?(GroupProxy)
39
21
  end
40
22
 
41
23
  def make_columns_equal_width=(equal_width)
42
24
  @make_columns_equal_width = equal_width
43
- # @parent.add_css_class('make_columns_equal_width') if @make_columns_equal_width
44
- # reinitialize # TODO reimplement without using reinitialize
25
+ if @make_columns_equal_width
26
+ @parent.dom_element.css('grid-template-columns', "#{100.0/@num_columns.to_f}% " * @num_columns.to_i)
27
+ else
28
+ @parent.dom_element.css('grid-template-columns', 'auto ' * @num_columns.to_i)
29
+ end
45
30
  end
46
31
 
47
32
  def horizontal_spacing=(spacing)
48
33
  @horizontal_spacing = spacing
49
- # @parent.add_css_class("horizontal-spacing-#{@horizontal_spacing}")
50
- # reinitialize # TODO reimplement without using reinitialize
34
+ @parent.dom_element.css('grid-column-gap', "#{@horizontal_spacing}px")
51
35
  end
52
36
 
53
37
  def vertical_spacing=(spacing)
54
38
  @vertical_spacing = spacing
55
- # @parent.add_css_class("vertical-spacing-#{@vertical_spacing}")
56
- # reinitialize # TODO reimplement without using reinitialize
39
+ @parent.dom_element.css('grid-row-gap', "#{@vertical_spacing}px")
57
40
  end
58
41
 
59
42
  def margin_width=(pixels)
@@ -72,6 +55,38 @@ module Glimmer
72
55
  @parent.dom_element.css('padding-top', effective_margin_height)
73
56
  @parent.dom_element.css('padding-bottom', effective_margin_height)
74
57
  end
58
+
59
+ def margin_top=(pixels)
60
+ @margin_top = pixels
61
+ # Using padding for width since margin-right isn't getting respected with width 100%
62
+ effective_margin_top = @margin_top
63
+ effective_margin_top += 9 if @parent.is_a?(GroupProxy)
64
+ @parent.dom_element.css('padding-top', effective_margin_top)
65
+ end
66
+
67
+ def margin_right=(pixels)
68
+ @margin_right = pixels
69
+ effective_margin_right = @margin_right
70
+ effective_margin_right += 6 if @parent.is_a?(GroupProxy)
71
+ @parent.dom_element.css('padding-right', effective_margin_right)
72
+ end
73
+
74
+ def margin_bottom=(pixels)
75
+ @margin_bottom = pixels
76
+ # Using padding for width since margin-right isn't getting respected with width 100%
77
+ effective_margin_bottom = @margin_bottom
78
+ effective_margin_bottom += 9 if @parent.is_a?(GroupProxy)
79
+ @parent.dom_element.css('padding-bottom', effective_margin_bottom)
80
+ end
81
+
82
+ def margin_left=(pixels)
83
+ @margin_left = pixels
84
+ effective_margin_left = @margin_left
85
+ effective_margin_left += 6 if @parent.is_a?(GroupProxy)
86
+ @parent.dom_element.css('padding-left', effective_margin_left)
87
+ end
88
+
89
+
75
90
 
76
91
  def initialize(parent, args)
77
92
  super(parent, args)
@@ -79,7 +94,8 @@ module Glimmer
79
94
  self.vertical_spacing = 10
80
95
  self.margin_width = 15
81
96
  self.margin_height = 15
82
- self.num_columns = @args.first || 1
97
+ self.num_columns = @args[0] || 1
98
+ self.make_columns_equal_width = @args[1] || false
83
99
  end
84
100
  end
85
101
  end