glimmer-dsl-libui 0.1.0 → 0.1.4

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.4
@@ -0,0 +1,52 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ include Glimmer
4
+
5
+ window('Area Gallery', 400, 400) {
6
+ vertical_box {
7
+ area {
8
+ path { # declarative stable path
9
+ square(0, 0, 100)
10
+ square(100, 100, 400)
11
+
12
+ fill r: 102, g: 102, b: 204
13
+ }
14
+ path { # declarative stable path
15
+ rectangle(0, 100, 100, 400)
16
+ rectangle(100, 0, 400, 100)
17
+
18
+ fill r: 204, g: 102, b: 204
19
+ }
20
+ path { # declarative stable path
21
+ figure(100, 100) {
22
+ line(100, 400)
23
+ line(400, 100)
24
+ line(400, 400)
25
+
26
+ closed true
27
+ }
28
+
29
+ fill r: 202, g: 102, b: 104, a: 0.5
30
+ stroke r: 0, g: 0, b: 0
31
+ }
32
+ path { # declarative stable path
33
+ figure(0, 0) {
34
+ bezier(200, 100, 100, 200, 400, 100)
35
+ bezier(300, 100, 100, 300, 100, 400)
36
+ bezier(100, 300, 300, 100, 400, 400)
37
+
38
+ closed true
39
+ }
40
+
41
+ fill r: 202, g: 102, b: 204, a: 0.5
42
+ stroke thickness: 2, r: 0, g: 0, b: 0
43
+ }
44
+ path { # declarative stable path
45
+ arc(200, 200, 90, 0, 360, false)
46
+
47
+ fill r: 202, g: 102, b: 204, a: 0.5
48
+ stroke thickness: 2, r: 0, g: 0, b: 0
49
+ }
50
+ }
51
+ }
52
+ }.show
@@ -0,0 +1,113 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ include Glimmer
4
+
5
+ window('Area Gallery', 400, 400) {
6
+ vertical_box {
7
+ area {
8
+ path { # declarative stable path
9
+ square {
10
+ x 0
11
+ y 0
12
+ length 100
13
+ }
14
+ square {
15
+ x 100
16
+ y 100
17
+ length 400
18
+ }
19
+
20
+ fill r: 102, g: 102, b: 204
21
+ }
22
+ path { # declarative stable path
23
+ rectangle {
24
+ x 0
25
+ y 100
26
+ width 100
27
+ height 400
28
+ }
29
+ rectangle {
30
+ x 100
31
+ y 0
32
+ width 400
33
+ height 100
34
+ }
35
+
36
+ fill r: 204, g: 102, b: 204
37
+ }
38
+ path { # declarative stable path
39
+ figure {
40
+ x 100
41
+ y 100
42
+
43
+ line {
44
+ x 100
45
+ y 400
46
+ }
47
+ line {
48
+ x 400
49
+ y 100
50
+ }
51
+ line {
52
+ x 400
53
+ y 400
54
+ }
55
+
56
+ closed true
57
+ }
58
+
59
+ fill r: 202, g: 102, b: 104, a: 0.5
60
+ stroke r: 0, g: 0, b: 0
61
+ }
62
+ path { # declarative stable path
63
+ figure {
64
+ x 0
65
+ y 0
66
+
67
+ bezier {
68
+ c1_x 200
69
+ c1_y 100
70
+ c2_x 100
71
+ c2_y 200
72
+ end_x 400
73
+ end_y 100
74
+ }
75
+ bezier {
76
+ c1_x 300
77
+ c1_y 100
78
+ c2_x 100
79
+ c2_y 300
80
+ end_x 100
81
+ end_y 400
82
+ }
83
+ bezier {
84
+ c1_x 100
85
+ c1_y 300
86
+ c2_x 300
87
+ c2_y 100
88
+ end_x 400
89
+ end_y 400
90
+ }
91
+
92
+ closed true
93
+ }
94
+
95
+ fill r: 202, g: 102, b: 204, a: 0.5
96
+ stroke thickness: 2, r: 0, g: 0, b: 0
97
+ }
98
+ path { # declarative stable path
99
+ arc {
100
+ x_center 200
101
+ y_center 200
102
+ radius 90
103
+ start_angle 0
104
+ sweep 360
105
+ is_negative false
106
+ }
107
+
108
+ fill r: 202, g: 102, b: 204, a: 0.5
109
+ stroke thickness: 2, r: 0, g: 0, b: 0
110
+ }
111
+ }
112
+ }
113
+ }.show
@@ -0,0 +1,54 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ include Glimmer
4
+
5
+ window('Area Gallery', 400, 400) {
6
+ vertical_box {
7
+ area {
8
+ on_draw do |area_draw_params|
9
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
10
+ square(0, 0, 100)
11
+ square(100, 100, 400)
12
+
13
+ fill r: 102, g: 102, b: 204
14
+ }
15
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
16
+ rectangle(0, 100, 100, 400)
17
+ rectangle(100, 0, 400, 100)
18
+
19
+ fill r: 204, g: 102, b: 204
20
+ }
21
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
22
+ figure(100, 100) {
23
+ line(100, 400)
24
+ line(400, 100)
25
+ line(400, 400)
26
+
27
+ closed true
28
+ }
29
+
30
+ fill r: 202, g: 102, b: 104, a: 0.5
31
+ stroke r: 0, g: 0, b: 0
32
+ }
33
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
34
+ figure(0, 0) {
35
+ bezier(200, 100, 100, 200, 400, 100)
36
+ bezier(300, 100, 100, 300, 100, 400)
37
+ bezier(100, 300, 300, 100, 400, 400)
38
+
39
+ closed true
40
+ }
41
+
42
+ fill r: 202, g: 102, b: 204, a: 0.5
43
+ stroke thickness: 2, r: 0, g: 0, b: 0
44
+ }
45
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
46
+ arc(200, 200, 90, 0, 360, false)
47
+
48
+ fill r: 202, g: 102, b: 204, a: 0.5
49
+ stroke thickness: 2, r: 0, g: 0, b: 0
50
+ }
51
+ end
52
+ }
53
+ }
54
+ }.show
@@ -0,0 +1,115 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ include Glimmer
4
+
5
+ window('Area Gallery', 400, 400) {
6
+ vertical_box {
7
+ area {
8
+ on_draw do |area_draw_params|
9
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
10
+ square {
11
+ x 0
12
+ y 0
13
+ length 100
14
+ }
15
+ square {
16
+ x 100
17
+ y 100
18
+ length 400
19
+ }
20
+
21
+ fill r: 102, g: 102, b: 204
22
+ }
23
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
24
+ rectangle {
25
+ x 0
26
+ y 100
27
+ width 100
28
+ height 400
29
+ }
30
+ rectangle {
31
+ x 100
32
+ y 0
33
+ width 400
34
+ height 100
35
+ }
36
+
37
+ fill r: 204, g: 102, b: 204
38
+ }
39
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
40
+ figure {
41
+ x 100
42
+ y 100
43
+
44
+ line {
45
+ x 100
46
+ y 400
47
+ }
48
+ line {
49
+ x 400
50
+ y 100
51
+ }
52
+ line {
53
+ x 400
54
+ y 400
55
+ }
56
+
57
+ closed true
58
+ }
59
+
60
+ fill r: 202, g: 102, b: 104, a: 0.5
61
+ stroke r: 0, g: 0, b: 0
62
+ }
63
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
64
+ figure {
65
+ x 0
66
+ y 0
67
+
68
+ bezier {
69
+ c1_x 200
70
+ c1_y 100
71
+ c2_x 100
72
+ c2_y 200
73
+ end_x 400
74
+ end_y 100
75
+ }
76
+ bezier {
77
+ c1_x 300
78
+ c1_y 100
79
+ c2_x 100
80
+ c2_y 300
81
+ end_x 100
82
+ end_y 400
83
+ }
84
+ bezier {
85
+ c1_x 100
86
+ c1_y 300
87
+ c2_x 300
88
+ c2_y 100
89
+ end_x 400
90
+ end_y 400
91
+ }
92
+
93
+ closed true
94
+ }
95
+
96
+ fill r: 202, g: 102, b: 204, a: 0.5
97
+ stroke thickness: 2, r: 0, g: 0, b: 0
98
+ }
99
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
100
+ arc {
101
+ x_center 200
102
+ y_center 200
103
+ radius 90
104
+ start_angle 0
105
+ sweep 360
106
+ is_negative false
107
+ }
108
+
109
+ fill r: 202, g: 102, b: 204, a: 0.5
110
+ stroke thickness: 2, r: 0, g: 0, b: 0
111
+ }
112
+ end
113
+ }
114
+ }
115
+ }.show
@@ -0,0 +1,19 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ include Glimmer
4
+
5
+ window('Basic Area', 400, 400) {
6
+ margined true
7
+
8
+ vertical_box {
9
+ area {
10
+ on_draw do |area_draw_params|
11
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
12
+ rectangle(0, 0, 400, 400)
13
+
14
+ fill r: 102, g: 102, b: 204, a: 1.0
15
+ }
16
+ end
17
+ }
18
+ }
19
+ }.show
@@ -12,13 +12,23 @@ data = [
12
12
  ['task 5', -1],
13
13
  ]
14
14
 
15
- window('Task progress', 300, 200) {
16
- horizontal_box {
15
+ window('Task Progress', 300, 200) {
16
+ vertical_box {
17
17
  table {
18
18
  text_column('Task')
19
19
  progress_bar_column('Progress')
20
20
 
21
- cell_rows data
21
+ cell_rows data # implicit data-binding
22
+ }
23
+
24
+ button('Mark All As Done') {
25
+ stretchy false
26
+
27
+ on_clicked do
28
+ data.each_with_index do |row_data, row|
29
+ data[row] = [row_data[0], 100] # automatically updates table due to implicit data-binding
30
+ end
31
+ end
22
32
  }
23
33
  }
24
34
  }.show
@@ -0,0 +1,99 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ include Glimmer
4
+
5
+ window('Dynamic Area', 240, 600) {
6
+ margined true
7
+
8
+ vertical_box {
9
+ label('Rectangle Properties') {
10
+ stretchy false
11
+ }
12
+
13
+ form {
14
+ stretchy false
15
+
16
+ @x_spinbox = spinbox(0, 1000) {
17
+ label 'x'
18
+ value 25
19
+
20
+ on_changed do
21
+ @area.queue_redraw_all
22
+ end
23
+ }
24
+
25
+ @y_spinbox = spinbox(0, 1000) {
26
+ label 'y'
27
+ value 25
28
+
29
+ on_changed do
30
+ @area.queue_redraw_all
31
+ end
32
+ }
33
+
34
+ @width_spinbox = spinbox(0, 1000) {
35
+ label 'width'
36
+ value 150
37
+
38
+ on_changed do
39
+ @area.queue_redraw_all
40
+ end
41
+ }
42
+
43
+ @height_spinbox = spinbox(0, 1000) {
44
+ label 'height'
45
+ value 150
46
+
47
+ on_changed do
48
+ @area.queue_redraw_all
49
+ end
50
+ }
51
+
52
+ @red_spinbox = spinbox(0, 255) {
53
+ label 'red'
54
+ value 102
55
+
56
+ on_changed do
57
+ @area.queue_redraw_all
58
+ end
59
+ }
60
+
61
+ @green_spinbox = spinbox(0, 255) {
62
+ label 'green'
63
+ value 102
64
+
65
+ on_changed do
66
+ @area.queue_redraw_all
67
+ end
68
+ }
69
+
70
+ @blue_spinbox = spinbox(0, 255) {
71
+ label 'blue'
72
+ value 204
73
+
74
+ on_changed do
75
+ @area.queue_redraw_all
76
+ end
77
+ }
78
+
79
+ @alpha_spinbox = spinbox(0, 100) {
80
+ label 'alpha'
81
+ value 100
82
+
83
+ on_changed do
84
+ @area.queue_redraw_all
85
+ end
86
+ }
87
+ }
88
+
89
+ @area = area {
90
+ on_draw do |area_draw_params|
91
+ path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
92
+ rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value)
93
+
94
+ fill r: @red_spinbox.value, g: @green_spinbox.value, b: @blue_spinbox.value, a: @alpha_spinbox.value / 100.0
95
+ }
96
+ end
97
+ }
98
+ }
99
+ }.show
@@ -0,0 +1,97 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ include Glimmer
4
+
5
+ window('Dynamic Area', 240, 600) {
6
+ margined true
7
+
8
+ vertical_box {
9
+ label('Rectangle Properties') {
10
+ stretchy false
11
+ }
12
+
13
+ form {
14
+ stretchy false
15
+
16
+ @x_spinbox = spinbox(0, 1000) {
17
+ label 'x'
18
+ value 25
19
+
20
+ on_changed do
21
+ @rectangle.x = @x_spinbox.value # updating properties automatically triggers area.queue_redraw_all
22
+ end
23
+ }
24
+
25
+ @y_spinbox = spinbox(0, 1000) {
26
+ label 'y'
27
+ value 25
28
+
29
+ on_changed do
30
+ @rectangle.y = @y_spinbox.value # updating properties automatically triggers area.queue_redraw_all
31
+ end
32
+ }
33
+
34
+ @width_spinbox = spinbox(0, 1000) {
35
+ label 'width'
36
+ value 150
37
+
38
+ on_changed do
39
+ @rectangle.width = @width_spinbox.value # updating properties automatically triggers area.queue_redraw_all
40
+ end
41
+ }
42
+
43
+ @height_spinbox = spinbox(0, 1000) {
44
+ label 'height'
45
+ value 150
46
+
47
+ on_changed do
48
+ @rectangle.height = @height_spinbox.value # updating properties automatically triggers area.queue_redraw_all
49
+ end
50
+ }
51
+
52
+ @red_spinbox = spinbox(0, 255) {
53
+ label 'red'
54
+ value 102
55
+
56
+ on_changed do
57
+ @path.fill[:r] = @red_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
58
+ end
59
+ }
60
+
61
+ @green_spinbox = spinbox(0, 255) {
62
+ label 'green'
63
+ value 102
64
+
65
+ on_changed do
66
+ @path.fill[:g] = @green_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
67
+ end
68
+ }
69
+
70
+ @blue_spinbox = spinbox(0, 255) {
71
+ label 'blue'
72
+ value 204
73
+
74
+ on_changed do
75
+ @path.fill[:b] = @blue_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
76
+ end
77
+ }
78
+
79
+ @alpha_spinbox = spinbox(0, 100) {
80
+ label 'alpha'
81
+ value 100
82
+
83
+ on_changed do
84
+ @path.fill[:a] = @alpha_spinbox.value / 100.0 # updating hash properties automatically triggers area.queue_redraw_all
85
+ end
86
+ }
87
+ }
88
+
89
+ area {
90
+ @path = path { # stable path
91
+ @rectangle = rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value)
92
+
93
+ fill r: @red_spinbox.value, g: @green_spinbox.value, b: @blue_spinbox.value, a: @alpha_spinbox.value / 100.0
94
+ }
95
+ }
96
+ }
97
+ }.show
Binary file
@@ -29,7 +29,7 @@ module Glimmer
29
29
  include ParentExpression
30
30
 
31
31
  def can_interpret?(parent, keyword, *args, &block)
32
- Glimmer::LibUI::ControlProxy.control_exists?(keyword)
32
+ Glimmer::LibUI::ControlProxy.exists?(keyword)
33
33
  end
34
34
 
35
35
  def interpret(parent, keyword, *args, &block)
@@ -39,6 +39,7 @@ module Glimmer
39
39
  listener
40
40
  property
41
41
  control
42
+ shape
42
43
  ]
43
44
  )
44
45
  end
@@ -21,13 +21,17 @@
21
21
 
22
22
  require 'glimmer/dsl/expression'
23
23
  require 'glimmer/libui/control_proxy'
24
+ require 'glimmer/libui/shape'
24
25
 
25
26
  module Glimmer
26
27
  module DSL
27
28
  module Libui
28
29
  class PropertyExpression < Expression
29
30
  def can_interpret?(parent, keyword, *args, &block)
30
- parent.is_a?(Glimmer::LibUI::ControlProxy) and
31
+ (
32
+ parent.is_a?(Glimmer::LibUI::ControlProxy) or
33
+ parent.is_a?(Glimmer::LibUI::Shape)
34
+ ) and
31
35
  block.nil? and
32
36
  parent.respond_to?(keyword, *args)
33
37
  end
@@ -0,0 +1,56 @@
1
+ # Copyright (c) 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/dsl/expression'
23
+ require 'glimmer/dsl/parent_expression'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module Libui
28
+ class ShapeExpression < Expression
29
+ include ParentExpression
30
+
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ Glimmer::LibUI::Shape.exists?(keyword) and
33
+ (
34
+ parent.is_a?(Glimmer::LibUI::PathProxy) or
35
+ parent.is_a?(Glimmer::LibUI::Shape)
36
+ )
37
+ end
38
+
39
+ def interpret(parent, keyword, *args, &block)
40
+ Glimmer::LibUI::Shape.create(keyword, parent, args, &block)
41
+ end
42
+
43
+ def add_content(parent, keyword, *args, &block)
44
+ super
45
+ parent.post_add_content
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ # TODO Consider moving all shapes underneath Shape namespace
54
+ require 'glimmer/libui/path_proxy'
55
+ require 'glimmer/libui/shape'
56
+ Dir[File.expand_path('../../libui/*.rb', __dir__)].each {|f| require f}