glimmer-dsl-libui 0.1.1 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -0
- data/README.md +1215 -30
- data/VERSION +1 -1
- data/examples/area_gallery.rb +50 -0
- data/examples/area_gallery2.rb +111 -0
- data/examples/area_gallery3.rb +52 -0
- data/examples/area_gallery4.rb +113 -0
- data/examples/basic_area2.rb +1 -1
- data/examples/basic_table_progress_bar.rb +13 -3
- data/examples/basic_transform.rb +27 -0
- data/examples/dynamic_area.rb +1 -1
- data/examples/dynamic_area2.rb +97 -0
- data/examples/histogram.rb +119 -0
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/dsl/libui/control_expression.rb +1 -1
- data/lib/glimmer/dsl/libui/dsl.rb +1 -0
- data/lib/glimmer/dsl/libui/property_expression.rb +5 -1
- data/lib/glimmer/dsl/libui/shape_expression.rb +56 -0
- data/lib/glimmer/libui/{rectangle_proxy.rb → arc.rb} +11 -26
- data/lib/glimmer/libui/area_proxy.rb +21 -11
- data/lib/glimmer/libui/bezier.rb +36 -0
- data/lib/glimmer/libui/box.rb +1 -1
- data/lib/glimmer/libui/color_button_proxy.rb +67 -15
- data/lib/glimmer/libui/control_proxy.rb +10 -14
- data/lib/glimmer/libui/figure.rb +52 -0
- data/lib/glimmer/libui/form_proxy.rb +1 -1
- data/lib/glimmer/libui/grid_proxy.rb +1 -1
- data/lib/glimmer/libui/line.rb +36 -0
- data/lib/glimmer/libui/matrix_proxy.rb +145 -0
- data/lib/glimmer/libui/parent.rb +36 -0
- data/lib/glimmer/libui/path_proxy.rb +35 -18
- data/lib/glimmer/libui/rectangle.rb +36 -0
- data/lib/glimmer/libui/shape.rb +143 -0
- data/lib/glimmer/libui/square.rb +36 -0
- data/lib/glimmer/libui/transformable.rb +72 -0
- data/lib/glimmer/libui/window_proxy.rb +8 -1
- data/lib/glimmer/libui.rb +50 -0
- data/lib/glimmer-dsl-libui.rb +1 -0
- metadata +23 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window('Area Gallery', 400, 400) {
|
6
|
+
area {
|
7
|
+
path { # declarative stable path
|
8
|
+
square(0, 0, 100)
|
9
|
+
square(100, 100, 400)
|
10
|
+
|
11
|
+
fill r: 102, g: 102, b: 204
|
12
|
+
}
|
13
|
+
path { # declarative stable path
|
14
|
+
rectangle(0, 100, 100, 400)
|
15
|
+
rectangle(100, 0, 400, 100)
|
16
|
+
|
17
|
+
fill r: 204, g: 102, b: 204
|
18
|
+
}
|
19
|
+
path { # declarative stable path
|
20
|
+
figure(100, 100) {
|
21
|
+
line(100, 400)
|
22
|
+
line(400, 100)
|
23
|
+
line(400, 400)
|
24
|
+
|
25
|
+
closed true
|
26
|
+
}
|
27
|
+
|
28
|
+
fill r: 202, g: 102, b: 104, a: 0.5
|
29
|
+
stroke r: 0, g: 0, b: 0
|
30
|
+
}
|
31
|
+
path { # declarative stable path
|
32
|
+
figure(0, 0) {
|
33
|
+
bezier(200, 100, 100, 200, 400, 100)
|
34
|
+
bezier(300, 100, 100, 300, 100, 400)
|
35
|
+
bezier(100, 300, 300, 100, 400, 400)
|
36
|
+
|
37
|
+
closed true
|
38
|
+
}
|
39
|
+
|
40
|
+
fill r: 202, g: 102, b: 204, a: 0.5
|
41
|
+
stroke thickness: 2, r: 0, g: 0, b: 0
|
42
|
+
}
|
43
|
+
path { # declarative stable path
|
44
|
+
arc(200, 200, 90, 0, 360, false)
|
45
|
+
|
46
|
+
fill r: 202, g: 102, b: 204, a: 0.5
|
47
|
+
stroke thickness: 2, r: 0, g: 0, b: 0
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}.show
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window('Area Gallery', 400, 400) {
|
6
|
+
area {
|
7
|
+
path { # declarative stable path
|
8
|
+
square {
|
9
|
+
x 0
|
10
|
+
y 0
|
11
|
+
length 100
|
12
|
+
}
|
13
|
+
square {
|
14
|
+
x 100
|
15
|
+
y 100
|
16
|
+
length 400
|
17
|
+
}
|
18
|
+
|
19
|
+
fill r: 102, g: 102, b: 204
|
20
|
+
}
|
21
|
+
path { # declarative stable path
|
22
|
+
rectangle {
|
23
|
+
x 0
|
24
|
+
y 100
|
25
|
+
width 100
|
26
|
+
height 400
|
27
|
+
}
|
28
|
+
rectangle {
|
29
|
+
x 100
|
30
|
+
y 0
|
31
|
+
width 400
|
32
|
+
height 100
|
33
|
+
}
|
34
|
+
|
35
|
+
fill r: 204, g: 102, b: 204
|
36
|
+
}
|
37
|
+
path { # declarative stable path
|
38
|
+
figure {
|
39
|
+
x 100
|
40
|
+
y 100
|
41
|
+
|
42
|
+
line {
|
43
|
+
x 100
|
44
|
+
y 400
|
45
|
+
}
|
46
|
+
line {
|
47
|
+
x 400
|
48
|
+
y 100
|
49
|
+
}
|
50
|
+
line {
|
51
|
+
x 400
|
52
|
+
y 400
|
53
|
+
}
|
54
|
+
|
55
|
+
closed true
|
56
|
+
}
|
57
|
+
|
58
|
+
fill r: 202, g: 102, b: 104, a: 0.5
|
59
|
+
stroke r: 0, g: 0, b: 0
|
60
|
+
}
|
61
|
+
path { # declarative stable path
|
62
|
+
figure {
|
63
|
+
x 0
|
64
|
+
y 0
|
65
|
+
|
66
|
+
bezier {
|
67
|
+
c1_x 200
|
68
|
+
c1_y 100
|
69
|
+
c2_x 100
|
70
|
+
c2_y 200
|
71
|
+
end_x 400
|
72
|
+
end_y 100
|
73
|
+
}
|
74
|
+
bezier {
|
75
|
+
c1_x 300
|
76
|
+
c1_y 100
|
77
|
+
c2_x 100
|
78
|
+
c2_y 300
|
79
|
+
end_x 100
|
80
|
+
end_y 400
|
81
|
+
}
|
82
|
+
bezier {
|
83
|
+
c1_x 100
|
84
|
+
c1_y 300
|
85
|
+
c2_x 300
|
86
|
+
c2_y 100
|
87
|
+
end_x 400
|
88
|
+
end_y 400
|
89
|
+
}
|
90
|
+
|
91
|
+
closed true
|
92
|
+
}
|
93
|
+
|
94
|
+
fill r: 202, g: 102, b: 204, a: 0.5
|
95
|
+
stroke thickness: 2, r: 0, g: 0, b: 0
|
96
|
+
}
|
97
|
+
path { # declarative stable path
|
98
|
+
arc {
|
99
|
+
x_center 200
|
100
|
+
y_center 200
|
101
|
+
radius 90
|
102
|
+
start_angle 0
|
103
|
+
sweep 360
|
104
|
+
is_negative false
|
105
|
+
}
|
106
|
+
|
107
|
+
fill r: 202, g: 102, b: 204, a: 0.5
|
108
|
+
stroke thickness: 2, r: 0, g: 0, b: 0
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}.show
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window('Area Gallery', 400, 400) {
|
6
|
+
area {
|
7
|
+
on_draw do |area_draw_params|
|
8
|
+
path { # a dynamic path is added semi-declaratively inside on_draw block
|
9
|
+
square(0, 0, 100)
|
10
|
+
square(100, 100, 400)
|
11
|
+
|
12
|
+
fill r: 102, g: 102, b: 204
|
13
|
+
}
|
14
|
+
path { # a dynamic path is added semi-declaratively inside on_draw block
|
15
|
+
rectangle(0, 100, 100, 400)
|
16
|
+
rectangle(100, 0, 400, 100)
|
17
|
+
|
18
|
+
fill r: 204, g: 102, b: 204
|
19
|
+
}
|
20
|
+
path { # a dynamic path is added semi-declaratively inside on_draw block
|
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 { # a dynamic path is added semi-declaratively inside on_draw block
|
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 { # a dynamic path is added semi-declaratively inside on_draw block
|
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
|
+
end
|
51
|
+
}
|
52
|
+
}.show
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window('Area Gallery', 400, 400) {
|
6
|
+
area {
|
7
|
+
on_draw do |area_draw_params|
|
8
|
+
path { # a dynamic path is added semi-declaratively inside on_draw block
|
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 { # a dynamic path is added semi-declaratively inside on_draw block
|
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 { # a dynamic path is added semi-declaratively inside on_draw block
|
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 { # a dynamic path is added semi-declaratively inside on_draw block
|
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 { # a dynamic path is added semi-declaratively inside on_draw block
|
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
|
+
end
|
112
|
+
}
|
113
|
+
}.show
|
data/examples/basic_area2.rb
CHANGED
@@ -8,7 +8,7 @@ window('Basic Area', 400, 400) {
|
|
8
8
|
vertical_box {
|
9
9
|
area {
|
10
10
|
on_draw do |area_draw_params|
|
11
|
-
path
|
11
|
+
path { # a dynamic path is added semi-declaratively inside on_draw block
|
12
12
|
rectangle(0, 0, 400, 400)
|
13
13
|
|
14
14
|
fill r: 102, g: 102, b: 204, a: 1.0
|
@@ -12,13 +12,23 @@ data = [
|
|
12
12
|
['task 5', -1],
|
13
13
|
]
|
14
14
|
|
15
|
-
window('Task
|
16
|
-
|
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,27 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window('Basic Transform', 350, 350) {
|
6
|
+
area {
|
7
|
+
path {
|
8
|
+
square(0, 0, 350)
|
9
|
+
|
10
|
+
fill r: 255, g: 255, b: 0
|
11
|
+
}
|
12
|
+
40.times do |n|
|
13
|
+
path {
|
14
|
+
square(0, 0, 100)
|
15
|
+
|
16
|
+
fill r: [255 - n*5, 0].max, g: [n*5, 255].min, b: 0, a: 0.5
|
17
|
+
stroke color: 0, thickness: 2
|
18
|
+
transform {
|
19
|
+
skew 0.15, 0.15
|
20
|
+
translate 50, 50
|
21
|
+
rotate 100, 100, -9 * n
|
22
|
+
scale 1.1, 1.1
|
23
|
+
}
|
24
|
+
}
|
25
|
+
end
|
26
|
+
}
|
27
|
+
}.show
|
data/examples/dynamic_area.rb
CHANGED
@@ -88,7 +88,7 @@ window('Dynamic Area', 240, 600) {
|
|
88
88
|
|
89
89
|
@area = area {
|
90
90
|
on_draw do |area_draw_params|
|
91
|
-
path
|
91
|
+
path { # a dynamic path is added semi-declaratively inside on_draw block
|
92
92
|
rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value)
|
93
93
|
|
94
94
|
fill r: @red_spinbox.value, g: @green_spinbox.value, b: @blue_spinbox.value, a: @alpha_spinbox.value / 100.0
|
@@ -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
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# https://github.com/jamescook/libui-ruby/blob/master/example/histogram.rb
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
|
5
|
+
include Glimmer
|
6
|
+
|
7
|
+
X_OFF_LEFT = 20
|
8
|
+
Y_OFF_TOP = 20
|
9
|
+
X_OFF_RIGHT = 20
|
10
|
+
Y_OFF_BOTTOM = 20
|
11
|
+
POINT_RADIUS = 5
|
12
|
+
|
13
|
+
COLOR_BLUE = 0x1E90FF
|
14
|
+
|
15
|
+
def graph_size(area_width, area_height)
|
16
|
+
graph_width = area_width - X_OFF_LEFT - X_OFF_RIGHT
|
17
|
+
graph_height = area_height - Y_OFF_TOP - Y_OFF_BOTTOM
|
18
|
+
[graph_width, graph_height]
|
19
|
+
end
|
20
|
+
|
21
|
+
def point_locations(datapoints, width, height)
|
22
|
+
xincr = width / 9.0 # 10 - 1 to make the last point be at the end
|
23
|
+
yincr = height / 100.0
|
24
|
+
|
25
|
+
data = []
|
26
|
+
datapoints.each_with_index do |dp, i|
|
27
|
+
val = 100 - dp.value
|
28
|
+
data << [xincr * i, yincr * val]
|
29
|
+
i += 1
|
30
|
+
end
|
31
|
+
|
32
|
+
data
|
33
|
+
end
|
34
|
+
|
35
|
+
def graph_path(datapoints, width, height, should_extend, &block)
|
36
|
+
locations = point_locations(datapoints, width, height)
|
37
|
+
path {
|
38
|
+
first_location = locations[0] # x and y
|
39
|
+
figure(first_location[0], first_location[1]) {
|
40
|
+
locations.each do |loc|
|
41
|
+
line(loc[0], loc[1])
|
42
|
+
end
|
43
|
+
if should_extend
|
44
|
+
line(width, height)
|
45
|
+
line(0, height)
|
46
|
+
|
47
|
+
closed true
|
48
|
+
end
|
49
|
+
}
|
50
|
+
|
51
|
+
# now transform the coordinate space so (0, 0) is the top-left corner of the graph
|
52
|
+
transform {
|
53
|
+
translate X_OFF_LEFT, Y_OFF_TOP
|
54
|
+
}
|
55
|
+
|
56
|
+
block.call
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
window('histogram example', 640, 480) {
|
61
|
+
margined true
|
62
|
+
|
63
|
+
horizontal_box {
|
64
|
+
vertical_box {
|
65
|
+
stretchy false
|
66
|
+
|
67
|
+
@datapoints = 10.times.map do
|
68
|
+
spinbox(0, 100) { |datapoint|
|
69
|
+
stretchy false
|
70
|
+
value Random.new.rand(90)
|
71
|
+
|
72
|
+
on_changed do
|
73
|
+
@area.queue_redraw_all
|
74
|
+
end
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
@color_button = color_button {
|
79
|
+
stretchy false
|
80
|
+
color COLOR_BLUE
|
81
|
+
|
82
|
+
on_changed do
|
83
|
+
@area.queue_redraw_all
|
84
|
+
end
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
@area = area {
|
89
|
+
on_draw do |area_draw_params|
|
90
|
+
path {
|
91
|
+
rectangle(0, 0, area_draw_params[:area_width], area_draw_params[:area_height])
|
92
|
+
|
93
|
+
fill color: 0xFFFFFF
|
94
|
+
}
|
95
|
+
|
96
|
+
graph_width, graph_height = *graph_size(area_draw_params[:area_width], area_draw_params[:area_height])
|
97
|
+
|
98
|
+
path {
|
99
|
+
figure(X_OFF_LEFT, Y_OFF_TOP) {
|
100
|
+
line(X_OFF_LEFT, Y_OFF_TOP + graph_height)
|
101
|
+
line(X_OFF_LEFT + graph_width, Y_OFF_TOP + graph_height)
|
102
|
+
}
|
103
|
+
|
104
|
+
stroke color: 0x000000, thickness: 2, miter_limit: 10
|
105
|
+
}
|
106
|
+
|
107
|
+
# now create the fill for the graph below the graph line
|
108
|
+
graph_path(@datapoints, graph_width, graph_height, true) {
|
109
|
+
fill @color_button.color.merge(a: 0.5)
|
110
|
+
}
|
111
|
+
|
112
|
+
# now draw the histogram line
|
113
|
+
graph_path(@datapoints, graph_width, graph_height, false) {
|
114
|
+
stroke @color_button.color.merge(thickness: 2, miter_limit: 10)
|
115
|
+
}
|
116
|
+
end
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}.show
|
data/glimmer-dsl-libui.gemspec
CHANGED
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.
|
32
|
+
Glimmer::LibUI::ControlProxy.exists?(keyword)
|
33
33
|
end
|
34
34
|
|
35
35
|
def interpret(parent, keyword, *args, &block)
|
@@ -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
|
-
|
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
|