glimmer-dsl-opal 0.9.3 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +28 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +114 -49
  5. data/VERSION +1 -1
  6. data/lib/display.rb +1 -1
  7. data/lib/glimmer-dsl-opal.rb +3 -2
  8. data/lib/glimmer-dsl-opal/ext/file.rb +1 -1
  9. data/lib/glimmer-dsl-opal/ext/glimmer/dsl/engine.rb +8 -4
  10. data/lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_repository.rb +4 -4
  11. data/lib/glimmer-dsl-opal/samples/elaborate/login.rb +7 -7
  12. data/lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb +3 -3
  13. data/lib/glimmer-dsl-opal/samples/hello/hello_browser.rb +1 -1
  14. data/lib/glimmer-dsl-opal/samples/hello/hello_button.rb +2 -2
  15. data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox.rb +5 -5
  16. data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox_group.rb +1 -1
  17. data/lib/glimmer-dsl-opal/samples/hello/hello_combo.rb +2 -2
  18. data/lib/glimmer-dsl-opal/samples/hello/hello_computed.rb +6 -6
  19. data/lib/glimmer-dsl-opal/samples/hello/hello_computed/contact.rb +1 -1
  20. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_shell.rb +1 -1
  21. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_widget.rb +1 -1
  22. data/lib/glimmer-dsl-opal/samples/hello/hello_date_time.rb +5 -5
  23. data/lib/glimmer-dsl-opal/samples/hello/hello_dialog.rb +78 -0
  24. data/lib/glimmer-dsl-opal/samples/hello/hello_group.rb +7 -7
  25. data/lib/glimmer-dsl-opal/samples/hello/hello_list_multi_selection.rb +2 -2
  26. data/lib/glimmer-dsl-opal/samples/hello/hello_list_single_selection.rb +2 -2
  27. data/lib/glimmer-dsl-opal/samples/hello/hello_menu_bar.rb +1 -1
  28. data/lib/glimmer-dsl-opal/samples/hello/hello_message_box.rb +1 -1
  29. data/lib/glimmer-dsl-opal/samples/hello/hello_pop_up_context_menu.rb +1 -1
  30. data/lib/glimmer-dsl-opal/samples/hello/hello_radio.rb +7 -7
  31. data/lib/glimmer-dsl-opal/samples/hello/hello_radio_group.rb +1 -1
  32. data/lib/glimmer-dsl-opal/samples/hello/hello_tab.rb +1 -1
  33. data/lib/glimmer-dsl-opal/samples/hello/hello_table.rb +1 -1
  34. data/lib/glimmer-dsl-opal/samples/hello/hello_world.rb +1 -1
  35. data/lib/glimmer-dsl-swt.rb +1 -1
  36. data/lib/glimmer/data_binding/table_items_binding.rb +2 -1
  37. data/lib/glimmer/dsl/opal/async_exec_expression.rb +1 -1
  38. data/lib/glimmer/dsl/opal/bind_expression.rb +24 -25
  39. data/lib/glimmer/dsl/opal/block_property_expression.rb +1 -1
  40. data/lib/glimmer/dsl/opal/checkbox_group_selection_data_binding_expression.rb +1 -1
  41. data/lib/glimmer/dsl/opal/color_expression.rb +1 -1
  42. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +7 -7
  43. data/lib/glimmer/dsl/opal/dialog_expression.rb +20 -0
  44. data/lib/glimmer/dsl/opal/display_expression.rb +1 -1
  45. data/lib/glimmer/dsl/opal/dsl.rb +5 -1
  46. data/lib/glimmer/dsl/opal/exec_expression.rb +1 -1
  47. data/lib/glimmer/dsl/opal/font_expression.rb +1 -1
  48. data/lib/glimmer/dsl/opal/menu_bar_expression.rb +1 -1
  49. data/lib/glimmer/dsl/opal/menu_expression.rb +2 -2
  50. data/lib/glimmer/dsl/opal/message_box_expression.rb +1 -1
  51. data/lib/glimmer/dsl/opal/property_expression.rb +2 -1
  52. data/lib/glimmer/dsl/opal/radio_group_selection_data_binding_expression.rb +1 -1
  53. data/lib/glimmer/dsl/opal/rgb_expression.rb +1 -1
  54. data/lib/glimmer/dsl/opal/rgba_expression.rb +1 -1
  55. data/lib/glimmer/dsl/opal/shape_expression.rb +26 -0
  56. data/lib/glimmer/dsl/opal/shell_expression.rb +1 -1
  57. data/lib/glimmer/dsl/opal/shine_data_binding_expression.rb +49 -0
  58. data/lib/glimmer/dsl/opal/swt_expression.rb +4 -4
  59. data/lib/glimmer/dsl/opal/sync_exec_expression.rb +1 -1
  60. data/lib/glimmer/dsl/opal/widget_expression.rb +1 -1
  61. data/lib/glimmer/swt.rb +1 -1
  62. data/lib/glimmer/swt/color_proxy.rb +1 -1
  63. data/lib/glimmer/swt/combo_proxy.rb +1 -0
  64. data/lib/glimmer/swt/composite_proxy.rb +18 -2
  65. data/lib/glimmer/swt/control_editor.rb +1 -1
  66. data/lib/glimmer/swt/custom/checkbox_group.rb +1 -1
  67. data/lib/glimmer/swt/custom/radio_group.rb +1 -1
  68. data/lib/glimmer/swt/dialog_proxy.rb +188 -0
  69. data/lib/glimmer/swt/display_proxy.rb +132 -9
  70. data/lib/glimmer/swt/font_proxy.rb +1 -1
  71. data/lib/glimmer/swt/grid_layout_proxy.rb +28 -33
  72. data/lib/glimmer/swt/label_proxy.rb +1 -1
  73. data/lib/glimmer/swt/latest_dialog_proxy.rb +44 -0
  74. data/lib/glimmer/swt/latest_message_box_proxy.rb +4 -2
  75. data/lib/glimmer/swt/latest_shell_proxy.rb +7 -3
  76. data/lib/glimmer/swt/layout_data_proxy.rb +4 -0
  77. data/lib/glimmer/swt/layout_proxy.rb +9 -6
  78. data/lib/glimmer/swt/make_shift_shell_proxy.rb +1 -1
  79. data/lib/glimmer/swt/menu_item_proxy.rb +1 -1
  80. data/lib/glimmer/swt/menu_proxy.rb +1 -1
  81. data/lib/glimmer/swt/message_box_proxy.rb +23 -17
  82. data/lib/glimmer/swt/row_layout_proxy.rb +34 -7
  83. data/lib/glimmer/swt/shell_proxy.rb +43 -9
  84. data/lib/glimmer/swt/style_constantizable.rb +1 -1
  85. data/lib/glimmer/swt/swt_proxy.rb +1 -1
  86. data/lib/glimmer/swt/tab_folder_proxy.rb +1 -1
  87. data/lib/glimmer/swt/table_editor.rb +1 -1
  88. data/lib/glimmer/swt/table_item_proxy.rb +1 -1
  89. data/lib/glimmer/swt/table_proxy.rb +1 -1
  90. data/lib/glimmer/swt/widget_proxy.rb +53 -21
  91. data/lib/glimmer/ui/custom_shell.rb +17 -3
  92. data/lib/glimmer/ui/custom_widget.rb +1 -1
  93. data/lib/glimmer/util/proc_tracker.rb +17 -6
  94. data/lib/net/http.rb +1 -1
  95. data/lib/os.rb +1 -1
  96. metadata +17 -11
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Andy Maleh
1
+ # Copyright (c) 2020-2021 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Andy Maleh
1
+ # Copyright (c) 2020-2021 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
@@ -0,0 +1,188 @@
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/display_proxy'
24
+
25
+ module Glimmer
26
+ module SWT
27
+ class DialogProxy < CompositeProxy
28
+ STYLE = <<~CSS
29
+ .ui-dialog .ui-dialog-content {
30
+ background: rgb(235, 235, 235);
31
+ }
32
+ .ui-dialog-titlebar {
33
+ background: rgb(80, 116, 211);
34
+ color: white;
35
+ }
36
+ .ui-dialog .dialog .ui-widget-overlay {
37
+ z-index: 10 !important;
38
+ background-color: rgba(0, 0, 0, 0.4);
39
+ opacity: 1;
40
+ }
41
+ .ui-dialog * {
42
+ z-index: 200 !important;
43
+ }
44
+ CSS
45
+
46
+
47
+ # .close {
48
+ # color: #aaaaaa;
49
+ # float: right;
50
+ # font-weight: bold;
51
+ # margin: 5px;
52
+ # }
53
+ # .close:hover,
54
+ # .close:focus {
55
+ # color: #000;
56
+ # text-decoration: none;
57
+ # cursor: pointer;
58
+ # }
59
+
60
+ attr_reader :text
61
+
62
+ def initialize(parent, args, block)
63
+ i = 0
64
+ @parent = parent
65
+ @parent = nil if parent.is_a?(LatestShellProxy)
66
+ @parent ||= DisplayProxy.instance.shells.detect(&:open?) || ShellProxy.new([])
67
+ @args = args
68
+ @block = block
69
+ @children = Set.new
70
+ @enabled = true
71
+ DisplayProxy.instance.opened_dialogs.last&.suspend_event_handling
72
+ DisplayProxy.instance.dialogs << self
73
+ @parent.post_initialize_child(self)
74
+ end
75
+
76
+ def text=(txt)
77
+ @text = txt
78
+ if @init
79
+ dom_element.dialog('option', 'title', @text)
80
+ else
81
+ dom_element.attr('title', @text)
82
+ end
83
+ end
84
+
85
+ def open?
86
+ @open
87
+ end
88
+
89
+ def open
90
+ owned_proc = Glimmer::Util::ProcTracker.new(owner: self, invoked_from: :open) {
91
+ shell.open(async: false) unless shell.open?
92
+ unless @init
93
+ dom_element.remove_class('hide')
94
+ dom_element.dialog('auto_open' => false)
95
+ @init = true
96
+ dom_element.dialog('option', 'appendTo', parent.path)
97
+ dom_element.dialog('option', 'modal', true) # NOTE: Not Working! Doing manually below by relying on overlay in ShellProxy.
98
+ unless DisplayProxy.instance.dialogs.any?(&:open?) # only add for first dialog open
99
+ Element['.dialog-overlay'].remove_class('hide')
100
+ end
101
+ dom_element.dialog('option', 'closeOnEscape', true)
102
+ dom_element.dialog('option', 'draggable', true)
103
+ dom_element.dialog('option', 'width', 'auto')
104
+ dom_element.dialog('option', 'minHeight', 'none')
105
+ dom_element.on('dialogclose') do
106
+ unless @hiding
107
+ close
108
+ else
109
+ @hiding = false
110
+ end
111
+ end
112
+ else
113
+ dom_element.dialog('open')
114
+ end
115
+ @open = true
116
+ }
117
+ DisplayProxy.instance.async_exec(owned_proc)
118
+ end
119
+
120
+ def hide
121
+ @hiding = true
122
+ dom_element.dialog('close')
123
+ @open = false
124
+ Element['.dialog-overlay'].add_class('hide') unless DisplayProxy.instance.dialogs.any?(&:open?)
125
+ end
126
+
127
+ def close
128
+ dom_element.dialog('destroy')
129
+ dom_element.remove
130
+ @open = false
131
+ @init = false
132
+ Element['.dialog-overlay'].add_class('hide') unless DisplayProxy.instance.dialogs.any?(&:open?)
133
+ parent.children.delete(self)
134
+ shell.close if shell.children.empty?
135
+ DisplayProxy.instance.dialogs.delete(self)
136
+ DisplayProxy.instance.opened_dialogs.last&.resume_event_handling
137
+ end
138
+
139
+
140
+ def content(&block)
141
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Opal::DialogExpression.new, 'dialog', &block)
142
+ end
143
+
144
+ def path
145
+ if @init # it gets moved once initialized by jQuery UI, so only ID is reliable then
146
+ "##{id}"
147
+ else
148
+ super
149
+ end
150
+ end
151
+
152
+ def suspend_event_handling
153
+ super
154
+ Element["[aria-describedby=#{id}]"].css('z-index', 9)
155
+ end
156
+
157
+ def resume_event_handling
158
+ super
159
+ Element["[aria-describedby=#{id}]"].css('z-index', 100)
160
+ end
161
+
162
+ # def selector
163
+ # super + ' .close'
164
+ # end
165
+ #
166
+ # def listener_path
167
+ # widget_path + ' .close'
168
+ # end
169
+ #
170
+ # def observation_request_to_event_mapping
171
+ # {
172
+ # 'on_widget_selected' => {
173
+ # event: 'click'
174
+ # },
175
+ # }
176
+ # end
177
+
178
+ def dom
179
+ @dom ||= html {
180
+ div(id: id, class: "#{name} modal hide", title: text) {
181
+ }
182
+ }.to_s
183
+ end
184
+ end
185
+ end
186
+ end
187
+
188
+ require 'glimmer/dsl/opal/dialog_expression'
@@ -1,3 +1,5 @@
1
+ require 'glimmer/swt/widget_proxy'
2
+
1
3
  module Glimmer
2
4
  module SWT
3
5
  class DisplayProxy < WidgetProxy
@@ -5,6 +7,9 @@ module Glimmer
5
7
  def instance
6
8
  @instance ||= new
7
9
  end
10
+
11
+ attr_accessor :open_custom_shells_in_current_window
12
+ alias open_custom_shells_in_current_window? open_custom_shells_in_current_window
8
13
  end
9
14
 
10
15
  def initialize
@@ -32,20 +37,50 @@ module Glimmer
32
37
  @message_boxes ||= []
33
38
  end
34
39
 
40
+ def dialogs
41
+ @dialogs ||= []
42
+ end
43
+
44
+ def modals
45
+ message_boxes + dialogs
46
+ end
47
+
48
+ def message_box_open?
49
+ message_boxes.any?(&:open?)
50
+ end
51
+
52
+ def dialog_open?
53
+ dialogs.any?(&:open?)
54
+ end
55
+
56
+ def opened_dialogs
57
+ dialogs.select(&:open?)
58
+ end
59
+
60
+ def modal_open?
61
+ message_box_open? or dialog_open?
62
+ end
63
+
35
64
  def render
36
65
  # No rendering as body is rendered as part of ShellProxy.. this class only serves as an SWT Display utility
37
66
  end
38
67
 
39
- def async_exec(&block)
40
- executer = lambda do
41
- if Document.find('.modal').to_a.empty?
42
- block.call
43
- else
44
- sleep(0.05)
45
- Async::Task.new(&executer)
46
- end
68
+ def beep
69
+ # TODO (simulate beep from SWT display flashing the screen and making a noise if possible)
70
+ end
71
+
72
+ def async_exec(proc_tracker = nil, &block)
73
+ block = proc_tracker unless proc_tracker.nil?
74
+ queue = nil # general queue
75
+ if !proc_tracker.nil? && proc_tracker.invoked_from.to_s == 'open' && modal_open? &&
76
+ (
77
+ proc_tracker.owner.is_a?(MessageBoxProxy) ||
78
+ (dialog_open? && proc_tracker.owner.is_a?(DialogProxy) && opened_dialogs.last == WidgetProxy.widget_handling_listener&.dialog_ancestor)
79
+ )
80
+ queue = WidgetProxy.widget_handling_listener
47
81
  end
48
- Async::Task.new(&executer)
82
+ return block.call if !modal_open?
83
+ schedule_async_exec(block, queue)
49
84
  end
50
85
  # sync_exec kept for API compatibility reasons
51
86
  alias sync_exec async_exec
@@ -60,7 +95,34 @@ module Glimmer
60
95
  event.singleton_class.define_method(:character) do
61
96
  which || key_code
62
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 }
63
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
64
126
  }
65
127
  }
66
128
  },
@@ -71,13 +133,74 @@ module Glimmer
71
133
  event.singleton_class.define_method(:character) do
72
134
  which || key_code
73
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 }
74
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
75
164
  }
76
165
  }
77
166
  }
78
167
  ]
79
168
  }
80
169
  end
170
+
171
+ private
172
+
173
+ def async_exec_queues
174
+ @async_exec_queues ||= {}
175
+ end
176
+
177
+ def async_exec_queue(widget_handling_listener = nil)
178
+ async_exec_queues[widget_handling_listener] ||= []
179
+ end
180
+
181
+ def no_widget_handling_listener_work?
182
+ async_exec_queues.reject {|key, value| key.nil?}.values.reduce(:+).to_a.empty?
183
+ end
184
+
185
+ def schedule_async_exec(block, queue)
186
+ async_exec_queue(queue).unshift(block)
187
+
188
+ # TODO consider the need for locking to avoid race conditions (rare or impossible case)
189
+ if async_exec_queue(queue).size == 1
190
+ executer = lambda do
191
+ # queue could be a widget handling listener queue
192
+ # TODO see if there are more intricate cases of opening a dialog from a widget listener handler
193
+ if !message_box_open? && (!dialog_open? || queue&.dialog_ancestor == opened_dialogs.last) && ((!queue.nil? && async_exec_queues.keys.last == queue) || no_widget_handling_listener_work?)
194
+ block = async_exec_queue(queue).pop
195
+ block&.call
196
+ Async::Task.new(delay: 1, &executer) if async_exec_queue(queue).any?
197
+ else
198
+ Async::Task.new(delay: 100, &executer)
199
+ end
200
+ end
201
+ Async::Task.new(delay: 1, &executer)
202
+ end
203
+ end
81
204
  end
82
205
  end
83
206
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Andy Maleh
1
+ # Copyright (c) 2020-2021 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
@@ -14,39 +14,46 @@ module Glimmer
14
14
 
15
15
  attr_reader :num_columns, :make_columns_equal_width, :horizontal_spacing, :vertical_spacing, :margin_width, :margin_height
16
16
 
17
- def initialize(parent, args)
18
- super(parent, args)
19
- self.horizontal_spacing = 10
20
- self.vertical_spacing = 10
21
- self.margin_width = 15
22
- self.margin_height = 15
23
- self.num_columns = @args.first || 1
24
- reapply
25
- end
26
-
27
17
  def num_columns=(columns)
28
18
  @num_columns = columns
29
19
  # TODO do the following instead of reapply
30
20
  # @parent.add_css_class("num-columns-#{@num_columns}")
31
- reapply
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
32
39
  end
33
40
 
34
41
  def make_columns_equal_width=(equal_width)
35
42
  @make_columns_equal_width = equal_width
36
43
  # @parent.add_css_class('make_columns_equal_width') if @make_columns_equal_width
37
- reapply
44
+ # reinitialize # TODO reimplement without using reinitialize
38
45
  end
39
46
 
40
47
  def horizontal_spacing=(spacing)
41
48
  @horizontal_spacing = spacing
42
49
  # @parent.add_css_class("horizontal-spacing-#{@horizontal_spacing}")
43
- reapply
50
+ # reinitialize # TODO reimplement without using reinitialize
44
51
  end
45
52
 
46
53
  def vertical_spacing=(spacing)
47
54
  @vertical_spacing = spacing
48
55
  # @parent.add_css_class("vertical-spacing-#{@vertical_spacing}")
49
- reapply
56
+ # reinitialize # TODO reimplement without using reinitialize
50
57
  end
51
58
 
52
59
  def margin_width=(pixels)
@@ -66,25 +73,13 @@ module Glimmer
66
73
  @parent.dom_element.css('padding-bottom', effective_margin_height)
67
74
  end
68
75
 
69
- def reapply
70
- # TODO get rid of this method
71
- layout_css = <<~CSS
72
- grid-template-columns: #{'auto ' * @num_columns.to_i};
73
- grid-row-gap: #{@vertical_spacing}px;
74
- grid-column-gap: #{@horizontal_spacing}px;
75
- CSS
76
- if @parent.css_classes.include?('grid-layout')
77
- layout_css.split(";").map(&:strip).map {|l| l.split(':').map(&:strip)}.each do |key, value|
78
- @parent.dom_element.css(key, value) unless key.nil?
79
- end
80
- if @parent.is_a?(GroupProxy)
81
- @parent.dom_element.find('legend').css('grid-column-start', "span #{@num_columns.to_i}")
82
- end
83
- else
84
- layout_css.split(";").map(&:strip).map {|l| l.split(':').map(&:strip)}.each do |key, value|
85
- @parent.dom_element.css(key, 'initial') unless key.nil?
86
- end
87
- end
76
+ def initialize(parent, args)
77
+ super(parent, args)
78
+ self.horizontal_spacing = 10
79
+ self.vertical_spacing = 10
80
+ self.margin_width = 15
81
+ self.margin_height = 15
82
+ self.num_columns = @args.first || 1
88
83
  end
89
84
  end
90
85
  end