glimmer-dsl-opal 0.16.2 → 0.19.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -1
  3. data/README.md +106 -4
  4. data/VERSION +1 -1
  5. data/lib/glimmer-dsl-opal/samples/hello/hello_arrow.rb +65 -0
  6. data/lib/glimmer-dsl-opal/samples/hello/hello_c_combo.rb +67 -0
  7. data/lib/glimmer-dsl-opal/samples/hello/hello_c_tab.rb +172 -0
  8. data/lib/glimmer-dsl-opal/samples/hello/hello_tab.rb +10 -8
  9. data/lib/glimmer-dsl-opal/samples/hello/images/denmark.png +0 -0
  10. data/lib/glimmer-dsl-opal/samples/hello/images/finland.png +0 -0
  11. data/lib/glimmer-dsl-opal/samples/hello/images/france.png +0 -0
  12. data/lib/glimmer-dsl-opal/samples/hello/images/germany.png +0 -0
  13. data/lib/glimmer-dsl-opal/samples/hello/images/italy.png +0 -0
  14. data/lib/glimmer-dsl-opal/samples/hello/images/mexico.png +0 -0
  15. data/lib/glimmer-dsl-opal/samples/hello/images/netherlands.png +0 -0
  16. data/lib/glimmer-dsl-opal/samples/hello/images/norway.png +0 -0
  17. data/lib/glimmer-dsl-opal/samples/hello/images/usa.png +0 -0
  18. data/lib/glimmer/dsl/opal/menu_expression.rb +3 -0
  19. data/lib/glimmer/swt/arrow_proxy.rb +42 -0
  20. data/lib/glimmer/swt/button_proxy.rb +36 -1
  21. data/lib/glimmer/swt/c_combo_proxy.rb +51 -0
  22. data/lib/glimmer/swt/c_tab_folder_proxy.rb +43 -0
  23. data/lib/glimmer/swt/c_tab_item_proxy.rb +96 -0
  24. data/lib/glimmer/swt/combo_proxy.rb +3 -0
  25. data/lib/glimmer/swt/menu_proxy.rb +17 -1
  26. data/lib/glimmer/swt/shell_proxy.rb +4 -0
  27. data/lib/glimmer/swt/tab_folder_proxy.rb +12 -10
  28. data/lib/glimmer/swt/tab_item_proxy.rb +52 -4
  29. data/lib/glimmer/swt/widget_proxy.rb +55 -14
  30. metadata +18 -2
@@ -1,5 +1,5 @@
1
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
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -20,15 +20,16 @@
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  class HelloTab
23
- include Glimmer
23
+ include Glimmer::UI::CustomShell
24
24
 
25
- def launch
25
+ body {
26
26
  shell {
27
27
  text 'Hello, Tab!'
28
28
 
29
29
  tab_folder {
30
30
  tab_item {
31
31
  text 'English'
32
+ tool_tip_text 'English Greeting'
32
33
 
33
34
  label {
34
35
  text 'Hello, World!'
@@ -37,14 +38,15 @@ class HelloTab
37
38
 
38
39
  tab_item {
39
40
  text 'French'
41
+ tool_tip_text 'French Greeting'
40
42
 
41
43
  label {
42
44
  text 'Bonjour, Univers!'
43
45
  }
44
46
  }
45
47
  }
46
- }.open
47
- end
48
+ }
49
+ }
48
50
  end
49
51
 
50
- HelloTab.new.launch
52
+ HelloTab.launch
@@ -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
@@ -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?
@@ -76,6 +76,10 @@ module Glimmer
76
76
  DisplayProxy.instance.shells << self
77
77
  end
78
78
 
79
+ def post_add_content
80
+ `$( document ).tooltip()`
81
+ end
82
+
79
83
  def element
80
84
  'div'
81
85
  end
@@ -26,8 +26,8 @@ module Glimmer
26
26
  class TabFolderProxy < WidgetProxy
27
27
  STYLE = <<~CSS
28
28
  .tabs .tab.selected {
29
- background: rgb(80, 116, 211);
30
- color: white;
29
+ background: white;
30
+ color: black;
31
31
  }
32
32
  .tabs .tab {
33
33
  background-color: inherit;
@@ -38,6 +38,14 @@ module Glimmer
38
38
  padding: 14px 16px;
39
39
  transition: 0.3s;
40
40
  font-size: 17px;
41
+ text-decoration: none;
42
+ }
43
+ .tabs .tab:hover {
44
+ color: black
45
+ }
46
+ .tabs .tab > * {
47
+ display: inline-block;
48
+ vertical-align: middle;
41
49
  }
42
50
  .tabs {
43
51
  overflow: hidden;
@@ -46,16 +54,10 @@ module Glimmer
46
54
  }
47
55
  CSS
48
56
 
49
- attr_reader :tabs
50
-
51
- def initialize(parent, args, block)
52
- super(parent, args, block)
53
- @tabs = []
54
- end
55
-
56
57
  def post_initialize_child(child)
57
58
  unless @children.include?(child)
58
59
  @children << child
60
+ child.closeable = true if @closeable_children
59
61
  tabs_dom_element.append(child.tab_dom)
60
62
  child.render
61
63
  end
@@ -85,7 +87,7 @@ module Glimmer
85
87
  tab_folder_id = id
86
88
  tab_folder_id_style = css
87
89
  @dom ||= html {
88
- div(id: tab_folder_id, style: tab_folder_id_style, class: 'tab-folder') {
90
+ div(id: tab_folder_id, style: tab_folder_id_style, class: name) {
89
91
  div(id: tabs_id, class: 'tabs')
90
92
  }
91
93
  }.to_s