glimmer-dsl-opal 0.27.0 → 0.28.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/README.md +71 -3
  4. data/VERSION +1 -1
  5. data/lib/glimmer/dsl/opal/dsl.rb +3 -0
  6. data/lib/glimmer/dsl/opal/image_expression.rb +64 -0
  7. data/lib/glimmer/dsl/opal/property_expression.rb +1 -2
  8. data/lib/glimmer/dsl/opal/shape_expression.rb +35 -6
  9. data/lib/glimmer/swt/canvas_proxy.rb +27 -0
  10. data/lib/glimmer/swt/composite_proxy.rb +0 -2
  11. data/lib/glimmer/swt/custom/shape/arc.rb +75 -0
  12. data/lib/glimmer/swt/custom/shape/image.rb +98 -0
  13. data/lib/glimmer/swt/custom/shape/line.rb +53 -0
  14. data/lib/glimmer/swt/custom/shape/oval.rb +58 -0
  15. data/lib/glimmer/swt/custom/shape/point.rb +53 -0
  16. data/lib/glimmer/swt/custom/shape/polygon.rb +53 -0
  17. data/lib/glimmer/swt/custom/shape/polyline.rb +53 -0
  18. data/lib/glimmer/swt/custom/shape/rectangle.rb +101 -0
  19. data/lib/glimmer/swt/custom/shape/text.rb +114 -0
  20. data/lib/glimmer/swt/custom/shape.rb +205 -0
  21. data/lib/glimmer/swt/image_proxy.rb +29 -0
  22. data/lib/glimmer/swt/menu_proxy.rb +1 -1
  23. data/lib/glimmer/swt/point.rb +2 -0
  24. data/lib/glimmer/swt/rectangle.rb +7 -0
  25. data/lib/glimmer/swt/widget_proxy.rb +15 -4
  26. data/lib/glimmer-dsl-opal/samples/elaborate/tetris/view/block.rb +44 -0
  27. data/lib/glimmer-dsl-opal/samples/elaborate/tetris.rb +4 -8
  28. data/lib/glimmer-dsl-opal/samples/elaborate/weather.rb +4 -3
  29. data/lib/glimmer-dsl-opal/samples/hello/hello_canvas.rb +106 -0
  30. data/lib/glimmer-dsl-opal/samples/hello/hello_text.rb +1 -1
  31. data/lib/glimmer-dsl-opal/samples/hello/images/scaffold_app.png +0 -0
  32. data/lib/glimmer-dsl-opal/vendor/two.min.js +24 -0
  33. data/lib/glimmer-dsl-opal.rb +1 -0
  34. metadata +19 -2
@@ -0,0 +1,98 @@
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/custom/shape'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/color_proxy'
26
+ require 'glimmer/swt/image_proxy'
27
+ # require 'glimmer/swt/transform_proxy'
28
+
29
+ module Glimmer
30
+ module SWT
31
+ module Custom
32
+ class Shape
33
+ class Image < Shape
34
+ def parameter_names
35
+ if image_whole_parameter_names.size == @args.size
36
+ @parameter_names = image_whole_parameter_names
37
+ elsif image_part_parameter_names.size == @args.size
38
+ @parameter_names = image_part_parameter_names
39
+ end
40
+ @parameter_names || image_whole_parameter_names
41
+ end
42
+
43
+ def possible_parameter_names
44
+ (image_whole_parameter_names + image_part_parameter_names).uniq
45
+ end
46
+
47
+ def image_part_parameter_names
48
+ [:image, :src_x, :src_y, :src_width, :src_height, :dest_x, :dest_y, :dest_width, :dest_height]
49
+ end
50
+
51
+ def image_whole_parameter_names
52
+ [:image, :x, :y]
53
+ end
54
+
55
+ def set_parameter_attribute(attribute_name, *args)
56
+ if @parameter_names.to_a.map(&:to_s).include?(attribute_name.to_s)
57
+ super(attribute_name, *args)
58
+ build_dom
59
+ reattach(dom_element)
60
+ return
61
+ end
62
+ ####TODO refactor and improve this method through meta-programming (and share across other shapes)
63
+ if image_whole_parameter_names.map(&:to_s).include?(attribute_name.to_s)
64
+ @parameter_names = image_whole_parameter_names
65
+ elsif image_part_parameter_names.map(&:to_s).include?(attribute_name.to_s)
66
+ @parameter_names = image_part_parameter_names
67
+ end
68
+ super(attribute_name, *args)
69
+ end
70
+
71
+ def reattach(old_element)
72
+ old_element.attr('href', Element[@dom].attr('href'))
73
+ old_element.attr('x', Element[@dom].attr('x'))
74
+ old_element.attr('y', Element[@dom].attr('y'))
75
+ old_element.attr('width', Element[@dom].attr('width'))
76
+ old_element.attr('height', Element[@dom].attr('height'))
77
+ end
78
+
79
+ def element
80
+ 'image'
81
+ end
82
+
83
+ def dom
84
+ shape_id = id
85
+ shape_class = name
86
+ href = @args[0].is_a?(Glimmer::SWT::ImageProxy) ? @args[0].file_path : @args[0]
87
+ width = @args[0].is_a?(Glimmer::SWT::ImageProxy) ? @args[0].width : nil
88
+ height = @args[0].is_a?(Glimmer::SWT::ImageProxy) ? @args[0].height : nil
89
+ @dom ||= xml {
90
+ image(id: shape_id, class: shape_class, href: href, x: @args[1], y: @args[2], width: width, height: height)
91
+ }.to_s
92
+ end
93
+
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,53 @@
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/custom/shape'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/color_proxy'
26
+ # require 'glimmer/swt/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Line < Shape
33
+ def parameter_names
34
+ [:x1, :y1, :x2, :y2]
35
+ end
36
+
37
+ def element
38
+ 'line'
39
+ end
40
+
41
+ def dom
42
+ shape_id = id
43
+ shape_class = name
44
+ @dom ||= xml {
45
+ line(id: shape_id, class: shape_class, x1: @args[0], y1: @args[1], x2: @args[2], y2: @args[3])
46
+ }.to_s
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,58 @@
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/custom/shape'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/color_proxy'
26
+ # require 'glimmer/swt/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Oval < Shape
33
+
34
+ def element
35
+ 'ellipse'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ x = @args[0]
42
+ y = @args[1]
43
+ width = @args[2]
44
+ height = @args[3]
45
+ rx = width / 2.0
46
+ ry = height / 2.0
47
+ cx = x + rx
48
+ cy = y + ry
49
+ @dom ||= xml {
50
+ ellipse(id: shape_id, class: shape_class, cx: cx, cy: cy, rx: rx, ry: ry)
51
+ }.to_s
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,53 @@
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/custom/shape'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/color_proxy'
26
+ # require 'glimmer/swt/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Point < Shape
33
+ def parameter_names
34
+ [:x, :y]
35
+ end
36
+
37
+ def element
38
+ 'rect'
39
+ end
40
+
41
+ def dom
42
+ shape_id = id
43
+ shape_class = name
44
+ @dom ||= xml {
45
+ rect(id: shape_id, class: shape_class, x: @args[0], y: @args[1], width: 1, height: 1)
46
+ }.to_s
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,53 @@
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/custom/shape'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/color_proxy'
26
+ # require 'glimmer/swt/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Polygon < Shape
33
+ def parameter_names
34
+ [:point_array]
35
+ end
36
+
37
+ def element
38
+ 'polygon'
39
+ end
40
+
41
+ def dom
42
+ shape_id = id
43
+ shape_class = name
44
+ @dom ||= xml {
45
+ polygon(id: shape_id, class: shape_class, points: @args.map(&:to_s).join(' '))
46
+ }.to_s
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,53 @@
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/custom/shape'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/color_proxy'
26
+ # require 'glimmer/swt/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Polyline < Shape
33
+ def parameter_names
34
+ [:point_array]
35
+ end
36
+
37
+ def element
38
+ 'polyline'
39
+ end
40
+
41
+ def dom
42
+ shape_id = id
43
+ shape_class = name
44
+ @dom ||= xml {
45
+ polyline(id: shape_id, class: shape_class, points: @args.map(&:to_s).join(' '))
46
+ }.to_s
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,101 @@
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/custom/shape'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/color_proxy'
26
+ # require 'glimmer/swt/transform_proxy'
27
+
28
+ module Glimmer
29
+ module SWT
30
+ module Custom
31
+ class Shape
32
+ class Rectangle < Shape
33
+
34
+ def parameter_names
35
+ if @parameter_names.nil?
36
+ if rectangle_parameter_names.size == @args.size
37
+ @parameter_names = rectangle_parameter_names
38
+ elsif rectangle_round_parameter_names.size == @args.size
39
+ @parameter_names = rectangle_round_parameter_names
40
+ elsif rectangle_gradient_parameter_names.size == @args.size
41
+ @parameter_names = rectangle_gradient_parameter_names
42
+ elsif rectangle_rectangle_parameter_names.size == @args.size
43
+ @parameter_names = rectangle_rectangle_parameter_names
44
+ end
45
+ end
46
+ @parameter_names || rectangle_parameter_names
47
+ end
48
+
49
+ def possible_parameter_names
50
+ # TODO refactor and improve this method through meta-programming (and share across other shapes)
51
+ (rectangle_round_parameter_names + rectangle_parameter_names + rectangle_gradient_parameter_names + rectangle_rectangle_parameter_names).uniq
52
+ end
53
+
54
+ def rectangle_round_parameter_names
55
+ [:x, :y, :width, :height, :arc_width, :arc_height]
56
+ end
57
+
58
+ def rectangle_gradient_parameter_names
59
+ [:x, :y, :width, :height, :vertical]
60
+ end
61
+
62
+ def rectangle_parameter_names
63
+ [:x, :y, :width, :height]
64
+ end
65
+
66
+ def rectangle_rectangle_parameter_names
67
+ # this receives a Rectangle object
68
+ [:rectangle]
69
+ end
70
+
71
+ def set_parameter_attribute(attribute_name, *args)
72
+ return super(attribute_name, *args) if @parameter_names.to_a.map(&:to_s).include?(attribute_name.to_s)
73
+ if rectangle_parameter_names.map(&:to_s).include?(attribute_name.to_s)
74
+ @parameter_names = rectangle_parameter_names
75
+ elsif rectangle_round_parameter_names.map(&:to_s).include?(attribute_name.to_s)
76
+ @parameter_names = rectangle_round_parameter_names
77
+ elsif rectangle_gradient_parameter_names.map(&:to_s).include?(attribute_name.to_s)
78
+ @parameter_names = rectangle_gradient_parameter_names
79
+ elsif rectangle_rectangle_parameter_names.map(&:to_s).include?(attribute_name.to_s)
80
+ @parameter_names = rectangle_rectangle_parameter_names
81
+ end
82
+ super(attribute_name, *args)
83
+ end
84
+
85
+ def element
86
+ 'rect'
87
+ end
88
+
89
+ def dom
90
+ shape_id = id
91
+ shape_class = name
92
+ @dom ||= xml {
93
+ rect(id: shape_id, class: shape_class, x: @args[0], y: @args[1], width: @args[2], height: @args[3], rx: @args[4].to_f/2.0, ry: @args[5].to_f/2.0)
94
+ }.to_s
95
+ end
96
+
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end