glimmer-dsl-opal 0.16.1 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -2
  3. data/README.md +158 -4
  4. data/VERSION +1 -1
  5. data/lib/cgi.rb +14 -0
  6. data/lib/glimmer-dsl-opal.rb +1 -0
  7. data/lib/glimmer-dsl-opal/samples/hello/hello_arrow.rb +65 -0
  8. data/lib/glimmer-dsl-opal/samples/hello/hello_c_combo.rb +67 -0
  9. data/lib/glimmer-dsl-opal/samples/hello/hello_c_tab.rb +172 -0
  10. data/lib/glimmer-dsl-opal/samples/hello/hello_layout.rb +241 -0
  11. data/lib/glimmer-dsl-opal/samples/hello/hello_tab.rb +10 -8
  12. data/lib/glimmer-dsl-opal/samples/hello/images/denmark.png +0 -0
  13. data/lib/glimmer-dsl-opal/samples/hello/images/finland.png +0 -0
  14. data/lib/glimmer-dsl-opal/samples/hello/images/france.png +0 -0
  15. data/lib/glimmer-dsl-opal/samples/hello/images/germany.png +0 -0
  16. data/lib/glimmer-dsl-opal/samples/hello/images/italy.png +0 -0
  17. data/lib/glimmer-dsl-opal/samples/hello/images/mexico.png +0 -0
  18. data/lib/glimmer-dsl-opal/samples/hello/images/netherlands.png +0 -0
  19. data/lib/glimmer-dsl-opal/samples/hello/images/norway.png +0 -0
  20. data/lib/glimmer-dsl-opal/samples/hello/images/usa.png +0 -0
  21. data/lib/glimmer/dsl/opal/menu_expression.rb +3 -0
  22. data/lib/glimmer/swt/arrow_proxy.rb +42 -0
  23. data/lib/glimmer/swt/button_proxy.rb +36 -1
  24. data/lib/glimmer/swt/c_combo_proxy.rb +51 -0
  25. data/lib/glimmer/swt/c_tab_folder_proxy.rb +43 -0
  26. data/lib/glimmer/swt/c_tab_item_proxy.rb +96 -0
  27. data/lib/glimmer/swt/combo_proxy.rb +3 -0
  28. data/lib/glimmer/swt/fill_layout_proxy.rb +9 -3
  29. data/lib/glimmer/swt/grid_layout_proxy.rb +33 -1
  30. data/lib/glimmer/swt/label_proxy.rb +2 -2
  31. data/lib/glimmer/swt/menu_proxy.rb +17 -1
  32. data/lib/glimmer/swt/row_layout_proxy.rb +33 -2
  33. data/lib/glimmer/swt/shell_proxy.rb +4 -0
  34. data/lib/glimmer/swt/tab_folder_proxy.rb +12 -10
  35. data/lib/glimmer/swt/tab_item_proxy.rb +52 -4
  36. data/lib/glimmer/swt/widget_proxy.rb +53 -12
  37. metadata +20 -2
@@ -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
@@ -0,0 +1,51 @@
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/combo_proxy'
24
+
25
+ module Glimmer
26
+ module SWT
27
+ class CComboProxy < ComboProxy
28
+ def post_add_content
29
+ `$(#{path}).selectmenu()`
30
+ c_combo_dom_element.css('width', 'initial')
31
+ end
32
+
33
+ def font=(value)
34
+ @font = value.is_a?(FontProxy) ? value : FontProxy.new(self, value)
35
+ c_combo_dom_element.css('font-family', @font.name) unless @font.nil?
36
+ c_combo_dom_element.css('font-style', 'italic') if @font&.style == :italic
37
+ c_combo_dom_element.css('font-weight', 'bold') if @font&.style == :bold
38
+ c_combo_dom_element.css('font-size', "#{@font.height}px") unless @font.nil?
39
+ end
40
+
41
+ def c_combo_path
42
+ "##{id}-button"
43
+ end
44
+
45
+ def c_combo_dom_element
46
+ Document.find(c_combo_path)
47
+ end
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,43 @@
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/tab_folder_proxy'
24
+
25
+ module Glimmer
26
+ module SWT
27
+ class CTabFolderProxy < TabFolderProxy
28
+ attr_reader :closeable_children
29
+
30
+ def initialize(parent, args, block)
31
+ @closeable_children = args.detect { |arg| SWTProxy[:close] == SWTProxy[arg] }
32
+ super(parent, args, block)
33
+ end
34
+
35
+ def post_initialize_child(child)
36
+ child.closeable = true if @closeable_children
37
+ super(child)
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,96 @@
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/tab_item_proxy'
23
+
24
+ module Glimmer
25
+ module SWT
26
+ class CTabItemProxy < TabItemProxy
27
+ attr_reader :selection_foreground
28
+ attr_accessor :closeable
29
+
30
+ def initialize(parent, args, block)
31
+ @closeable = args.detect { |arg| SWTProxy[:close] == SWTProxy[arg] }
32
+ super(parent, args, block)
33
+ # TODO attach listener if :close style is set
34
+ close_dom_element.on('click') { dispose }
35
+ end
36
+
37
+ def foreground=(value)
38
+ value = ColorProxy.new(value) if value.is_a?(String)
39
+ @foreground = value
40
+ tab_dom_element.css('color', foreground.to_css) unless foreground.nil?
41
+ end
42
+
43
+ def selection_foreground=(value)
44
+ value = ColorProxy.new(value) if value.is_a?(String)
45
+ @selection_foreground = value
46
+ if @selection_foreground && tab_dom_element.has_class?('selected')
47
+ @old_foreground = tab_dom_element.css('color')
48
+ tab_dom_element.css('color', @selection_foreground.to_css)
49
+ end
50
+ end
51
+
52
+ def font=(value)
53
+ @font = value.is_a?(FontProxy) ? value : FontProxy.new(self, value)
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)
57
+ tab_dom_element.css('font-size', "#{@font.height}px") unless @font.nil?
58
+ end
59
+
60
+ def show
61
+ super
62
+ if @selection_foreground
63
+ @old_foreground = tab_dom_element.css('color')
64
+ tab_dom_element.css('color', @selection_foreground.to_css)
65
+ end
66
+ end
67
+
68
+ def hide
69
+ super
70
+ if @old_foreground
71
+ tab_dom_element.css('color', @old_foreground)
72
+ @old_foreground = nil
73
+ end
74
+ end
75
+
76
+ def close_path
77
+ "#{tab_path} span.ui-icon-close"
78
+ end
79
+
80
+ def close_dom_element
81
+ Document.find(close_path)
82
+ end
83
+
84
+ def tab_dom
85
+ @tab_dom ||= html {
86
+ a(href: '#', id: tab_id, class: "tab") {
87
+ img {}
88
+ span { @text }
89
+ span(class: 'ui-icon ui-icon-close', role: 'presentation') { 'Remove Tab' } if @closeable
90
+ }
91
+ }.to_s
92
+ end
93
+
94
+ end
95
+ end
96
+ end
@@ -99,6 +99,9 @@ module Glimmer
99
99
  }
100
100
  }.to_s
101
101
  end
102
+
102
103
  end
104
+
103
105
  end
106
+
104
107
  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,7 +12,7 @@ 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
@@ -55,6 +55,38 @@ module Glimmer
55
55
  @parent.dom_element.css('padding-top', effective_margin_height)
56
56
  @parent.dom_element.css('padding-bottom', effective_margin_height)
57
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
+
58
90
 
59
91
  def initialize(parent, args)
60
92
  super(parent, args)
@@ -33,11 +33,11 @@ module Glimmer
33
33
 
34
34
  def text=(value)
35
35
  @text = value
36
- dom_element.html(html_text)
36
+ dom_element.html(html_text) # TODO deal with issue of handling lines and escaping at the same time
37
37
  end
38
38
 
39
39
  def html_text
40
- text&.gsub("\n", '<br />')
40
+ text && CGI.escape_html(text).gsub("\n", '<br />')
41
41
  end
42
42
 
43
43
  # def background_image=(*image_options)
@@ -218,6 +218,21 @@ module Glimmer
218
218
  end
219
219
  end
220
220
 
221
+ def visible=(value)
222
+ @visible = value
223
+ if @visible
224
+ parent.menu_requested = true
225
+ parent.dom_element.css('position', 'relative')
226
+ render
227
+ dom_element.css('position', 'absolute')
228
+ dom_element.css('left', parent.menu_x - parent.dom_element.offset.left)
229
+ dom_element.css('top', parent.menu_y - parent.dom_element.offset.top)
230
+ parent.menu_requested = false
231
+ else
232
+ close
233
+ end
234
+ end
235
+
221
236
  def render(custom_parent_dom_element: nil, brand_new: false)
222
237
  # TODO attach to top nav bar if parent is shell
223
238
  # TODO attach listener to parent to display on right click
@@ -226,7 +241,7 @@ module Glimmer
226
241
  if root_menu? && !bar?
227
242
  `$(#{path}).menu();`
228
243
  @close_event_handler = lambda do |event|
229
- close if event.target.parents('.ui-menu').empty?
244
+ close if event.target != parent.dom_element && event.target.parents('.ui-menu').empty?
230
245
  end
231
246
  Element['body'].on('click', &@close_event_handler)
232
247
  end
@@ -236,6 +251,7 @@ module Glimmer
236
251
  def close
237
252
  dom_element.remove
238
253
  Element['body'].off('click', &@close_event_handler)
254
+ @visible = false
239
255
  end
240
256
 
241
257
  def root_menu?