glimmer-dsl-opal 0.27.0 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 885895f5a47d453757426eb0b05e0b413972ef5b11f5c9045c8df92c4c1cd03d
4
- data.tar.gz: a33b454cd1229e8b6d640d31f55379875fdde969b3634ef85e524496b277117f
3
+ metadata.gz: 0f9cfe8a0d719c4ae80348ac72fd00f41190c31f405a2e38916f271ca35fab26
4
+ data.tar.gz: 0e44d82d8e35f15b35861195ec782cce25d0f2265b960cc65866212908a3a477
5
5
  SHA512:
6
- metadata.gz: dad2612713d1ebcc95cc08fc0bdaddbb45a9f07032af5e583da857adba54327752f853d8f28bfd76d545c7271e9be86e825d42d600c798775328864e8d651927
7
- data.tar.gz: 037c3e6f77c68a8edf343b3323b543f708adf5f41dffb03944148670ac46aa786cafbecb12675c24a5d4c5e3242ff2929886214d6ea43d9017de588ddc5db486
6
+ metadata.gz: 9f6321b66a2fbb55fb53f5d5d32031ef62afb8db46b0595161c6feaa41a0af01f12e44483c137c4ee06cced7633c0a6898f924f1ab46fc230d3d5c263762c8b8
7
+ data.tar.gz: 44add1a5d248c51c8876aefa4a48c26dba0fbe0a9acae9ad22eb22e0dd3785f3a5feeac2102dad98c0057bf030785bec97ef49b15a9a6b838ddc3d7016ae3646
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.28.0
4
+
5
+ - Initial support for Canvas Shape DSL keywords (no-databinding, nesting, or gradients yet):
6
+ - `line`
7
+ - `point`
8
+ - `oval`
9
+ - `polygon`
10
+ - `polyline`
11
+ - `rectangle`
12
+ - `string`
13
+ - `text`
14
+ - Minimal initial version of Hello, Canvas! sample
15
+
3
16
  ## 0.27.0
4
17
 
5
18
  - Hello, Text!
data/README.md CHANGED
@@ -145,7 +145,7 @@ Hello, Table! Game Booked
145
145
 
146
146
  NOTE: Glimmer DSL for Opal is an alpha project. Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
147
147
 
148
- **Alpha Version** 0.27.0 only supports bare-minimum capabilities for the included [samples](https://github.com/AndyObtiva/glimmer-dsl-opal#samples) (originally written for [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt))
148
+ **Alpha Version** 0.28.0 only supports bare-minimum capabilities for the included [samples](https://github.com/AndyObtiva/glimmer-dsl-opal#samples) (originally written for [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt))
149
149
 
150
150
  Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
151
151
  - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
@@ -179,12 +179,14 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
179
179
  - [Hello, Radio!](#hello-radio)
180
180
  - [Hello, Radio Group!](#hello-radio-group)
181
181
  - [Hello, Group!](#hello-group)
182
+ - [Hello, Canvas!](#hello-canvas)
182
183
  - [Hello, C Combo!](#hello-c-combo)
183
184
  - [Hello, C Tab!](#hello-c-tab)
184
185
  - [Hello, Checkbox!](#hello-checkbox)
185
186
  - [Hello, Checkbox Group!](#hello-checkbox-group)
186
187
  - [Hello, Date Time!](#hello-date-time)
187
188
  - [Hello, Table!](#hello-table)
189
+ - [Hello, Text!](#hello-text)
188
190
  - [Hello, Button!](#hello-button)
189
191
  - [Hello, Arrow!](#hello-arrow)
190
192
  - [Hello, Message Box!](#hello-message-box)
@@ -269,7 +271,7 @@ gem 'opal', '1.0.5'
269
271
  gem 'opal-rails', '1.1.2'
270
272
  gem 'opal-async', '~> 1.4.0'
271
273
  gem 'opal-jquery', '~> 0.4.4'
272
- gem 'glimmer-dsl-opal', '~> 0.27.0'
274
+ gem 'glimmer-dsl-opal', '~> 0.28.0'
273
275
  gem 'glimmer-dsl-xml', '~> 1.2.0', require: false
274
276
  gem 'glimmer-dsl-css', '~> 1.2.0', require: false
275
277
 
@@ -392,6 +394,16 @@ Event loop:
392
394
  - `display`: featured in [Tic Tac Toe](#tic-tac-toe)
393
395
  - `async_exec`: featured in [Hello, Custom Widget!](#hello-custom-widget) / [Hello, Custom Shell!](#hello-custom-shell)
394
396
 
397
+ Canvas Shape DSL:
398
+ - `line`
399
+ - `point`
400
+ - `oval`
401
+ - `polygon`
402
+ - `polyline`
403
+ - `rectangle`
404
+ - `string`
405
+ - `text`
406
+
395
407
  ## Samples
396
408
 
397
409
  Follow the instructions below to try out [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) samples webified via [glimmer-dsl-opal](https://rubygems.org/gems/glimmer-dsl-opal)
@@ -1447,6 +1459,35 @@ You should see "Hello, Group!"
1447
1459
 
1448
1460
  ![Glimmer DSL for Opal Hello Group](images/glimmer-dsl-opal-hello-group.png)
1449
1461
 
1462
+ #### Hello, Canvas!
1463
+
1464
+ This is a minimal initial version of the [Hello, Canvas! sample included in Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_SAMPLES.md#hello-canvas).
1465
+
1466
+ It supports all shapes except `arc`, with no shape nesting, data-binding, or gradient support yet.
1467
+
1468
+ Add the following require statement to `app/assets/javascripts/application.rb`
1469
+
1470
+ ```ruby
1471
+ require 'glimmer-dsl-opal/samples/hello/hello_canvas'
1472
+ ```
1473
+
1474
+ Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
1475
+
1476
+ ![Glimmer DSL for SWT Hello Canvas](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-canvas.png)
1477
+
1478
+ Glimmer app on the web (using `glimmer-dsl-opal` gem):
1479
+
1480
+ Start the Rails server:
1481
+ ```
1482
+ rails s
1483
+ ```
1484
+
1485
+ Visit `http://localhost:3000`
1486
+
1487
+ You should see "Hello, Canvas!"
1488
+
1489
+ ![Glimmer DSL for Opal Hello Canvas](images/glimmer-dsl-opal-hello-canvas.png)
1490
+
1450
1491
  #### Hello, C Combo!
1451
1492
 
1452
1493
  This is the low level way of using `c_combo`
@@ -1733,6 +1774,31 @@ Hello, Table! Game Booked
1733
1774
 
1734
1775
  ![Glimmer DSL for Opal Hello Table](images/glimmer-dsl-opal-hello-table-game-booked.png)
1735
1776
 
1777
+ #### Hello, Text!
1778
+
1779
+ Add the following require statement to `app/assets/javascripts/application.rb`
1780
+
1781
+ ```ruby
1782
+ require 'glimmer-dsl-opal/samples/hello/hello_text'
1783
+ ```
1784
+
1785
+ Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
1786
+
1787
+ ![Glimmer DSL for SWT Hello Text](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-text.png)
1788
+
1789
+ Glimmer app on the web (using `glimmer-dsl-opal` gem):
1790
+
1791
+ Start the Rails server:
1792
+ ```
1793
+ rails s
1794
+ ```
1795
+
1796
+ Visit `http://localhost:3000`
1797
+
1798
+ You should see "Hello, Text!"
1799
+
1800
+ ![Glimmer DSL for Opal Hello Text](images/glimmer-dsl-opal-hello-text.png)
1801
+
1736
1802
  #### Hello, Button!
1737
1803
 
1738
1804
  Add the following require statement to `app/assets/javascripts/application.rb`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.27.0
1
+ 0.28.0
@@ -30,6 +30,7 @@ require 'glimmer/dsl/opal/menu_expression'
30
30
  require 'glimmer/dsl/opal/dialog_expression'
31
31
  require 'glimmer/dsl/opal/shape_expression'
32
32
  require 'glimmer/dsl/opal/shine_data_binding_expression'
33
+ require 'glimmer/dsl/opal/shape_expression'
33
34
 
34
35
  module Glimmer
35
36
  module DSL
@@ -1,5 +1,28 @@
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/dsl/expression'
2
23
  require 'glimmer/dsl/parent_expression'
24
+ require 'glimmer/swt/swt_proxy'
25
+ require 'glimmer/swt/custom/shape'
3
26
 
4
27
  module Glimmer
5
28
  module DSL
@@ -7,20 +30,25 @@ module Glimmer
7
30
  class ShapeExpression < Expression
8
31
  include ParentExpression
9
32
 
10
- INCLUDED_KEYWORDS = %w[rectangle polygon]
11
-
12
33
  def can_interpret?(parent, keyword, *args, &block)
13
- INCLUDED_KEYWORDS.include?(keyword)
34
+ (parent.is_a?(Glimmer::SWT::WidgetProxy) or parent.is_a?(Glimmer::SWT::Custom::Shape)) and
35
+ Glimmer::SWT::Custom::Shape.valid?(parent, keyword, args, &block) &&
36
+ (keyword != 'text' || args.size >= 3)
14
37
  end
15
-
38
+
16
39
  def interpret(parent, keyword, *args, &block)
17
- # TODO
40
+ Glimmer::SWT::Custom::Shape.create(parent, keyword, args, &block)
18
41
  end
19
42
 
20
43
  def add_content(parent, keyword, *args, &block)
21
- # TODO
44
+ super(parent, keyword, *args, &block)
45
+ parent.post_add_content
22
46
  end
47
+
23
48
  end
49
+
24
50
  end
51
+
25
52
  end
53
+
26
54
  end
@@ -0,0 +1,27 @@
1
+ require 'glimmer/swt/composite_proxy'
2
+
3
+ module Glimmer
4
+ module SWT
5
+ class CanvasProxy < CompositeProxy
6
+ def default_layout
7
+ nil
8
+ end
9
+
10
+ def element
11
+ 'svg'
12
+ end
13
+
14
+ def dom
15
+ canvas_id = id
16
+ canvas_class = name
17
+ # TODO in the future, calculate width and height from children automatically (just like Glimmer DSL for SWT)
18
+ @dom ||= html {
19
+ svg(id: canvas_id, class: canvas_class) {
20
+ 'Sorry, your browser does not support inline SVG.'
21
+ }
22
+ }.to_s
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -78,8 +78,6 @@ module Glimmer
78
78
 
79
79
  end
80
80
 
81
- CanvasProxy = CompositeProxy # TODO implement fully eventually
82
-
83
81
  end
84
82
 
85
83
  end
@@ -0,0 +1,50 @@
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
+
34
+ def element
35
+ 'line'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ @dom ||= xml {
42
+ line(id: shape_id, class: shape_class, x1: @args[0], y1: @args[1], x2: @args[2], y2: @args[3])
43
+ }.to_s
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ 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,50 @@
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
+
34
+ def element
35
+ 'rect'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ @dom ||= xml {
42
+ rect(id: shape_id, class: shape_class, x: @args[0], y: @args[1], width: 1, height: 1)
43
+ }.to_s
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
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
+
34
+ def element
35
+ 'polygon'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ @dom ||= xml {
42
+ polygon(id: shape_id, class: shape_class, points: @args.map(&:to_s).join(' '))
43
+ }.to_s
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
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
+
34
+ def element
35
+ 'polyline'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ @dom ||= xml {
42
+ polyline(id: shape_id, class: shape_class, points: @args.map(&:to_s).join(' '))
43
+ }.to_s
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
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 element
35
+ 'rect'
36
+ end
37
+
38
+ def dom
39
+ shape_id = id
40
+ shape_class = name
41
+ @dom ||= xml {
42
+ rect(id: shape_id, class: shape_class, x: @args[0], y: @args[1], width: @args[2], height: @args[3], rx: @args[4], ry: @args[5])
43
+ }.to_s
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,64 @@
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 Text < Shape
33
+
34
+ def background=(value)
35
+ # TODO override background= to fill a rectangle containing text, matching its size
36
+ # For now, disable background when foreground is not set
37
+ super(value) unless foreground.nil?
38
+ end
39
+
40
+ def foreground=(value)
41
+ super(value)
42
+ self.background = value
43
+ end
44
+
45
+ def element
46
+ 'text'
47
+ end
48
+
49
+ def dom
50
+ shape_id = id
51
+ shape_class = name
52
+ @dom ||= xml {
53
+ tag(:_name => 'text', id: shape_id, class: shape_class, x: @args[1], y: @args[2]) {
54
+ @args[0]
55
+ }
56
+ }.to_s
57
+ end
58
+
59
+ end
60
+ String = Text
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,109 @@
1
+ # Copyright (c) 2007-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/property_owner'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/color_proxy'
26
+ require 'glimmer/swt/font_proxy'
27
+ # require 'glimmer/swt/transform_proxy'
28
+ require 'glimmer/swt/point'
29
+ require 'glimmer/swt/rectangle'
30
+
31
+ module Glimmer
32
+ module SWT
33
+ module Custom
34
+ # Represents a shape (graphics) to be drawn on a control/widget/canvas/display
35
+ # That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
36
+ class Shape < WidgetProxy
37
+ include PropertyOwner
38
+
39
+ class << self
40
+ def create(parent, keyword, args, &property_block)
41
+ potential_shape_class_name = keyword.to_s.camelcase(:upper).to_sym
42
+ if constants.include?(potential_shape_class_name)
43
+ const_get(potential_shape_class_name).new(parent, args, &property_block)
44
+ else
45
+ new(parent, args, &property_block)
46
+ end
47
+ end
48
+
49
+ def valid?(parent, keyword, args, &block)
50
+ return true if keyword.to_s == 'shape'
51
+ keywords.include?(keyword.to_s)
52
+ end
53
+
54
+ def keywords
55
+ constants.select do |constant|
56
+ constant_value = const_get(constant)
57
+ constant_value.respond_to?(:ancestors) && constant_value.ancestors.include?(Glimmer::SWT::Custom::Shape)
58
+ end.map {|constant| constant.to_s.underscore}
59
+ end
60
+
61
+ end
62
+
63
+ def background=(value)
64
+ value = ColorProxy.new(value) if value.is_a?(String)
65
+ @background = value
66
+ dom_element.css('fill', background.to_css) unless background.nil?
67
+ end
68
+
69
+ def foreground=(value)
70
+ value = ColorProxy.new(value) if value.is_a?(String)
71
+ @foreground = value
72
+ dom_element.css('stroke', foreground.to_css) unless foreground.nil?
73
+ dom_element.css('fill', 'transparent') if background.nil?
74
+ end
75
+
76
+ def attach(the_parent_dom_element)
77
+ the_parent_dom_element.html("#{the_parent_dom_element.html()}\n#{@dom}")
78
+ end
79
+
80
+ def element
81
+ 'g'
82
+ end
83
+
84
+ def dom
85
+ shape_id = id
86
+ shape_class = name
87
+ @dom ||= xml {
88
+ g(id: shape_id, class: shape_class) {
89
+ }
90
+ }.to_s
91
+ end
92
+
93
+ # TODO implement shape_at_location potentially with document.elementFromPoint(x, y);
94
+
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
101
+ end
102
+
103
+ require 'glimmer/swt/custom/shape/line'
104
+ require 'glimmer/swt/custom/shape/oval'
105
+ require 'glimmer/swt/custom/shape/point'
106
+ require 'glimmer/swt/custom/shape/polygon'
107
+ require 'glimmer/swt/custom/shape/polyline'
108
+ require 'glimmer/swt/custom/shape/rectangle'
109
+ require 'glimmer/swt/custom/shape/text'
@@ -1,5 +1,7 @@
1
1
  module Glimmer
2
2
  module SWT
3
+ # emulating org.eclipse.swt.graphics.Point
3
4
  Point = Struct.new(:x, :y)
5
+ # TODO alias as org.eclipse.swt.graphics.Point
4
6
  end
5
7
  end
@@ -0,0 +1,7 @@
1
+ module Glimmer
2
+ module SWT
3
+ # emulating org.eclipse.swt.graphics.Rectangle
4
+ Rectangle = Struct.new(:x, :y, :width, :height)
5
+ # TODO alias as org.eclipse.swt.graphics.Rectangle
6
+ end
7
+ end
@@ -30,7 +30,7 @@ module Glimmer
30
30
  class WidgetProxy
31
31
  include Glimmer
32
32
  include PropertyOwner
33
-
33
+
34
34
  Event = Struct.new(:widget, keyword_init: true)
35
35
 
36
36
  JS_KEY_CODE_TO_SWT_KEY_CODE_MAP = {
@@ -331,9 +331,10 @@ module Glimmer
331
331
  brand_new = @dom.nil? || old_element.empty? || brand_new
332
332
  build_dom(layout: !custom_parent_dom_element) # TODO handle custom parent layout by passing parent instead of parent dom element
333
333
  if brand_new
334
- the_parent_dom_element.append(@dom) # TODO make a method attach to allow subclasses to override if needed
334
+ # TODO make a method attach to allow subclasses to override if needed
335
+ attach(the_parent_dom_element)
335
336
  else
336
- old_element.replace_with(@dom)
337
+ reattach(old_element)
337
338
  end
338
339
  observation_requests&.each do |keyword, event_listener_set|
339
340
  event_listener_set.each do |event_listener|
@@ -347,6 +348,14 @@ module Glimmer
347
348
  content_on_render_blocks.each { |content_block| content(&content_block) } unless skip_content_on_render_blocks?
348
349
  end
349
350
  alias redraw render
351
+
352
+ def attach(the_parent_dom_element)
353
+ the_parent_dom_element.append(@dom)
354
+ end
355
+
356
+ def reattach(old_element)
357
+ old_element.replace_with(@dom)
358
+ end
350
359
 
351
360
  def content_on_render_blocks
352
361
  @content_on_render_blocks ||= []
@@ -367,7 +376,7 @@ module Glimmer
367
376
  def build_dom(layout: true)
368
377
  # TODO consider passing parent element instead and having table item include a table cell widget only for opal
369
378
  @dom = nil
370
- @dom = dom
379
+ @dom = dom # TODO unify how to build dom for most widgets based on element, id, and name (class)
371
380
  @dom = @parent.get_layout.dom(@dom) if @parent.respond_to?(:layout) && @parent.get_layout
372
381
  @dom
373
382
  end
@@ -1143,6 +1152,7 @@ require 'glimmer/swt/combo_proxy'
1143
1152
  require 'glimmer/swt/c_combo_proxy'
1144
1153
  require 'glimmer/swt/checkbox_proxy'
1145
1154
  require 'glimmer/swt/composite_proxy'
1155
+ require 'glimmer/swt/canvas_proxy'
1146
1156
  require 'glimmer/swt/date_time_proxy'
1147
1157
  require 'glimmer/swt/group_proxy'
1148
1158
  require 'glimmer/swt/label_proxy'
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2007-2021 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
@@ -25,11 +25,7 @@ require_relative 'tetris/view/playfield'
25
25
  require_relative 'tetris/view/score_lane'
26
26
  require_relative 'tetris/view/high_score_dialog'
27
27
  require_relative 'tetris/view/tetris_menu_bar'
28
- class Event
29
- def location
30
- `#@native.location`
31
- end
32
- end
28
+
33
29
  class Tetris
34
30
  include Glimmer::UI::CustomShell
35
31
 
@@ -147,7 +143,7 @@ class Tetris
147
143
  def show_about_dialog
148
144
  message_box {
149
145
  text 'Glimmer Tetris'
150
- message "Glimmer Tetris\n\nGlimmer DSL for SWT Sample\n\nUse arrow keys for movement\nand right/left alt/shift keys for rotation\nAlternatively:\nLeft is A\nRight is D\nDown is S\nUp is W\nRotate Left is Q\nRotate Right is E\n\n for Left, Down, Right, Up\n\nCopyright (c) 2007-2021 Andy Maleh"
146
+ message "Glimmer Tetris\n\nGlimmer DSL for SWT Sample\n\nUse arrow keys for movement\nand right/left alt/shift keys for rotation\nAlternatively:\nLeft is A\nRight is D\nDown is S\nUp is W\nRotate Left is Q\nRotate Right is E\n\nCopyright (c) 2007-2021 Andy Maleh"
151
147
  }.open
152
148
  end
153
149
  end
@@ -0,0 +1,83 @@
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 HelloCanvas
23
+ include Glimmer::UI::CustomShell
24
+
25
+ body {
26
+ shell {
27
+ text 'Hello, Canvas!'
28
+ minimum_size 320, 400
29
+
30
+ canvas {
31
+ background :yellow
32
+
33
+ rectangle(0, 0, 220, 400) {
34
+ background rgb(255, 0, 0)
35
+ }
36
+ rectangle(50, 20, 300, 150, 30, 50) {
37
+ background :magenta
38
+ }
39
+ rectangle(50, 20, 300, 150, 30, 50) {
40
+ foreground :yellow
41
+ }
42
+ rectangle(205, 50, 86, 97) {
43
+ foreground :yellow
44
+ }
45
+ rectangle(67, 75, 128, 38) {
46
+ background :yellow
47
+ }
48
+ rectangle(150, 200, 100, 70) {
49
+ background :dark_magenta
50
+ }
51
+ rectangle(50, 200, 30, 70) {
52
+ background :magenta
53
+ }
54
+ oval(110, 310, 100, 100) {
55
+ background :yellow
56
+ }
57
+ text('Picasso', 67, 103) {
58
+ foreground :dark_magenta
59
+ font name: 'Courier', height: 30
60
+ }
61
+ polygon(250, 210, 260, 170, 270, 210, 290, 230) {
62
+ background :dark_yellow
63
+ }
64
+ polyline(250, 110, 260, 70, 270, 110, 290, 130, 250, 110) {
65
+ foreground :black
66
+ }
67
+ 3.times do |n|
68
+ line(250, 120 + n*10, 270 + n*10, 80 + n*10) {
69
+ foreground :yellow
70
+ }
71
+ end
72
+ 10.times do |n|
73
+ point(220 + n*5, 100 + n*5) {
74
+ foreground :yellow
75
+ }
76
+ end
77
+ }
78
+ }
79
+ }
80
+ end
81
+
82
+ HelloCanvas.launch
83
+
@@ -97,7 +97,7 @@ class HelloText
97
97
  }
98
98
  text(:read_only, :border) {
99
99
  layout_data :fill, :center, true, false
100
- text <=> [self, :read_only]
100
+ text <= [self, :read_only]
101
101
  }
102
102
 
103
103
  label {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-opal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.0
4
+ version: 0.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-27 00:00:00.000000000 Z
11
+ date: 2021-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -300,6 +300,7 @@ files:
300
300
  - lib/glimmer-dsl-opal/samples/hello/hello_button.rb
301
301
  - lib/glimmer-dsl-opal/samples/hello/hello_c_combo.rb
302
302
  - lib/glimmer-dsl-opal/samples/hello/hello_c_tab.rb
303
+ - lib/glimmer-dsl-opal/samples/hello/hello_canvas.rb
303
304
  - lib/glimmer-dsl-opal/samples/hello/hello_checkbox.rb
304
305
  - lib/glimmer-dsl-opal/samples/hello/hello_checkbox_group.rb
305
306
  - lib/glimmer-dsl-opal/samples/hello/hello_combo.rb
@@ -407,6 +408,7 @@ files:
407
408
  - lib/glimmer/swt/c_combo_proxy.rb
408
409
  - lib/glimmer/swt/c_tab_folder_proxy.rb
409
410
  - lib/glimmer/swt/c_tab_item_proxy.rb
411
+ - lib/glimmer/swt/canvas_proxy.rb
410
412
  - lib/glimmer/swt/checkbox_proxy.rb
411
413
  - lib/glimmer/swt/color_proxy.rb
412
414
  - lib/glimmer/swt/combo_proxy.rb
@@ -414,6 +416,14 @@ files:
414
416
  - lib/glimmer/swt/control_editor.rb
415
417
  - lib/glimmer/swt/custom/checkbox_group.rb
416
418
  - lib/glimmer/swt/custom/radio_group.rb
419
+ - lib/glimmer/swt/custom/shape.rb
420
+ - lib/glimmer/swt/custom/shape/line.rb
421
+ - lib/glimmer/swt/custom/shape/oval.rb
422
+ - lib/glimmer/swt/custom/shape/point.rb
423
+ - lib/glimmer/swt/custom/shape/polygon.rb
424
+ - lib/glimmer/swt/custom/shape/polyline.rb
425
+ - lib/glimmer/swt/custom/shape/rectangle.rb
426
+ - lib/glimmer/swt/custom/shape/text.rb
417
427
  - lib/glimmer/swt/date_time_proxy.rb
418
428
  - lib/glimmer/swt/dialog_proxy.rb
419
429
  - lib/glimmer/swt/display_proxy.rb
@@ -437,6 +447,7 @@ files:
437
447
  - lib/glimmer/swt/progress_bar_proxy.rb
438
448
  - lib/glimmer/swt/property_owner.rb
439
449
  - lib/glimmer/swt/radio_proxy.rb
450
+ - lib/glimmer/swt/rectangle.rb
440
451
  - lib/glimmer/swt/row_layout_proxy.rb
441
452
  - lib/glimmer/swt/scale_proxy.rb
442
453
  - lib/glimmer/swt/scrolled_composite_proxy.rb