glimmer-dsl-libui 0.3.0 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -0
- data/README.md +1229 -1210
- data/VERSION +1 -1
- data/examples/area_gallery.rb +28 -28
- data/examples/area_gallery2.rb +113 -110
- data/examples/area_gallery3.rb +28 -28
- data/examples/area_gallery4.rb +112 -110
- data/examples/basic_area.rb +1 -3
- data/examples/basic_area2.rb +1 -3
- data/examples/basic_area3.rb +17 -0
- data/examples/basic_area4.rb +19 -0
- data/examples/basic_scrolling_area.rb +79 -0
- data/examples/basic_table_color.rb +1 -11
- data/examples/basic_table_color2.rb +39 -0
- data/examples/basic_table_image.rb +2 -14
- data/examples/basic_table_image2.rb +44 -0
- data/examples/basic_table_image_text.rb +2 -13
- data/examples/basic_table_image_text2.rb +44 -0
- data/examples/basic_transform.rb +3 -6
- data/examples/basic_transform2.rb +34 -0
- data/examples/color_the_circles.rb +1 -3
- data/examples/dynamic_area.rb +1 -3
- data/examples/dynamic_area2.rb +5 -7
- data/examples/form_table.rb +4 -0
- data/examples/grid.rb +4 -4
- data/examples/histogram.rb +4 -8
- data/examples/meta_example.rb +50 -10
- data/examples/snake.rb +1 -3
- data/examples/tetris.rb +15 -18
- data/examples/tic_tac_toe/board.rb +4 -2
- data/examples/tic_tac_toe.rb +1 -3
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/dsl/libui/shape_expression.rb +6 -1
- data/lib/glimmer/libui/control_proxy/area_proxy/scrolling_area_proxy.rb +35 -0
- data/lib/glimmer/libui/control_proxy/area_proxy.rb +1 -0
- data/lib/glimmer/libui/control_proxy/column.rb +2 -2
- data/lib/glimmer/libui/control_proxy/image_proxy.rb +42 -35
- data/lib/glimmer/libui/control_proxy/table_proxy.rb +15 -2
- data/lib/glimmer/libui/control_proxy/window_proxy.rb +20 -0
- data/lib/glimmer/libui/shape.rb +49 -1
- metadata +12 -19
@@ -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 { # dynamic path, 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
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
class BasicScrollingArea
|
4
|
+
include Glimmer
|
5
|
+
|
6
|
+
SCROLLING_AREA_WIDTH = 800
|
7
|
+
SCROLLING_AREA_HEIGHT = 400
|
8
|
+
SCROLLING_AREA_PADDING_X = 20
|
9
|
+
SCROLLING_AREA_PADDING_Y = 20
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@x = SCROLLING_AREA_PADDING_X
|
13
|
+
@y = SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y
|
14
|
+
create_gui
|
15
|
+
Glimmer::LibUI.timer(0.01) do
|
16
|
+
@x += SCROLLING_AREA_PADDING_X
|
17
|
+
@y = [[@y + rand(SCROLLING_AREA_PADDING_Y*4)*(rand(2) == 0 ? -1 : 1), SCROLLING_AREA_PADDING_Y].max, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y].min
|
18
|
+
@graph.content { # re-open @graph's content and add a line
|
19
|
+
line(@x, @y)
|
20
|
+
}
|
21
|
+
# if there is a need to enlarge scrolling area, call `@scrolling_area.set_size(new_width, new_height)`
|
22
|
+
# Note that `#scroll_to` does not seem to work on Linux, but normal scrolling does.
|
23
|
+
@scrolling_area.scroll_to(@x - (SCROLLING_AREA_WIDTH/2), @y) # 3rd and 4th arguments for width and height are assumed as those of main window by default if not supplied
|
24
|
+
# return false to stop timer once @x exceeds scrolling area width - padding
|
25
|
+
false if @x >= (SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*2)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def launch
|
30
|
+
@main_window.show
|
31
|
+
end
|
32
|
+
|
33
|
+
def x_axis
|
34
|
+
polyline(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y, SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*2, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
|
35
|
+
stroke :black, thickness: 3
|
36
|
+
}
|
37
|
+
|
38
|
+
((SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*4) / SCROLLING_AREA_PADDING_X).times do |x_multiplier|
|
39
|
+
x = x_multiplier*SCROLLING_AREA_PADDING_X + SCROLLING_AREA_PADDING_X*2
|
40
|
+
y = SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y
|
41
|
+
|
42
|
+
polyline(x, y, x, y + SCROLLING_AREA_PADDING_Y/2) {
|
43
|
+
stroke :black, thickness: 2
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def y_axis
|
49
|
+
polyline(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_PADDING_Y, SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
|
50
|
+
stroke :black, thickness: 3
|
51
|
+
}
|
52
|
+
|
53
|
+
((SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y*3) / SCROLLING_AREA_PADDING_Y).times do |y_multiplier|
|
54
|
+
x = SCROLLING_AREA_PADDING_X
|
55
|
+
y = y_multiplier*SCROLLING_AREA_PADDING_Y + SCROLLING_AREA_PADDING_Y*2
|
56
|
+
|
57
|
+
polyline(x, y, x - SCROLLING_AREA_PADDING_X/2, y) {
|
58
|
+
stroke :black, thickness: 2
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_gui
|
64
|
+
@main_window = window('Basic Scrolling Area', SCROLLING_AREA_WIDTH / 2, SCROLLING_AREA_HEIGHT) {
|
65
|
+
resizable false
|
66
|
+
|
67
|
+
@scrolling_area = scrolling_area(SCROLLING_AREA_WIDTH, SCROLLING_AREA_HEIGHT) { # double width of window enables horizontal scrolling
|
68
|
+
x_axis
|
69
|
+
y_axis
|
70
|
+
|
71
|
+
@graph = figure(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
|
72
|
+
stroke :blue, thickness: 2
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
BasicScrollingArea.new.launch
|
@@ -1,20 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'glimmer-dsl-libui'
|
4
|
-
require 'chunky_png'
|
5
4
|
|
6
5
|
include Glimmer
|
7
6
|
|
8
|
-
|
9
|
-
canvas = ChunkyPNG::Canvas.from_io(f)
|
10
|
-
f.close
|
11
|
-
canvas.resample_nearest_neighbor!(24, 24)
|
12
|
-
data = canvas.to_rgba_stream
|
13
|
-
width = canvas.width
|
14
|
-
height = canvas.height
|
15
|
-
img = image {
|
16
|
-
image_part(data, width, height, width * 4)
|
17
|
-
}
|
7
|
+
img = image(File.expand_path('../icons/glimmer.png', __dir__), 24, 24)
|
18
8
|
|
19
9
|
data = [
|
20
10
|
[['cat', :red] , ['meow', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], {r: 255, g: 120, b: 0, a: 0.5}],
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
require 'chunky_png'
|
5
|
+
|
6
|
+
include Glimmer
|
7
|
+
|
8
|
+
f = File.open(File.expand_path('../icons/glimmer.png', __dir__))
|
9
|
+
canvas = ChunkyPNG::Canvas.from_io(f)
|
10
|
+
f.close
|
11
|
+
canvas.resample_nearest_neighbor!(24, 24)
|
12
|
+
data = canvas.to_rgba_stream
|
13
|
+
width = canvas.width
|
14
|
+
height = canvas.height
|
15
|
+
img = image {
|
16
|
+
image_part(data, width, height, width * 4)
|
17
|
+
}
|
18
|
+
|
19
|
+
data = [
|
20
|
+
[['cat', :red] , ['meow', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], {r: 255, g: 120, b: 0, a: 0.5}],
|
21
|
+
[['dog', :yellow] , ['woof', {r: 240, g: 32, b: 32}] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], :skyblue],
|
22
|
+
[['chicken', :beige], ['cock-a-doodle-doo', :blue] , [false, 'mammal', :red] , [img, 'Glimmer', :beige], {r: 5, g: 120, b: 110}],
|
23
|
+
[['horse', :purple] , ['neigh', {r: 240, g: 32, b: 32}], [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], '13a1fb'],
|
24
|
+
[['cow', :gray] , ['moo', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :brown], 0x12ff02]
|
25
|
+
]
|
26
|
+
|
27
|
+
window('Animals', 500, 200) {
|
28
|
+
horizontal_box {
|
29
|
+
table {
|
30
|
+
text_color_column('Animal')
|
31
|
+
text_color_column('Sound')
|
32
|
+
checkbox_text_color_column('Description')
|
33
|
+
image_text_color_column('GUI')
|
34
|
+
background_color_column('Mammal')
|
35
|
+
|
36
|
+
cell_rows data
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}.show
|
@@ -4,8 +4,6 @@
|
|
4
4
|
# This example displays images that can be freely downloaded from the Studio Ghibli website.
|
5
5
|
|
6
6
|
require 'glimmer-dsl-libui'
|
7
|
-
require 'chunky_png'
|
8
|
-
require 'open-uri'
|
9
7
|
|
10
8
|
include Glimmer
|
11
9
|
|
@@ -13,18 +11,8 @@ IMAGE_ROWS = []
|
|
13
11
|
|
14
12
|
50.times do |i|
|
15
13
|
url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
|
16
|
-
puts "Processing Image: #{url}"
|
17
|
-
|
18
|
-
f = URI.open(url)
|
19
|
-
canvas = ChunkyPNG::Canvas.from_io(f)
|
20
|
-
f.close
|
21
|
-
data = canvas.to_rgba_stream
|
22
|
-
width = canvas.width
|
23
|
-
height = canvas.height
|
24
|
-
img = image {
|
25
|
-
image_part(data, width, height, width * 4)
|
26
|
-
}
|
27
|
-
IMAGE_ROWS << [img] # array of one column cell
|
14
|
+
puts "Processing Image: #{url}"; $stdout.flush # for Windows
|
15
|
+
IMAGE_ROWS << [image(url)] # array of one column cell
|
28
16
|
rescue StandardError => e
|
29
17
|
warn url, e.message
|
30
18
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# NOTE:
|
4
|
+
# This example displays images that can be freely downloaded from the Studio Ghibli website.
|
5
|
+
|
6
|
+
require 'glimmer-dsl-libui'
|
7
|
+
require 'chunky_png'
|
8
|
+
require 'open-uri'
|
9
|
+
|
10
|
+
include Glimmer
|
11
|
+
|
12
|
+
IMAGE_ROWS = []
|
13
|
+
|
14
|
+
50.times do |i|
|
15
|
+
url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
|
16
|
+
puts "Processing Image: #{url}"
|
17
|
+
$stdout.flush # for Windows
|
18
|
+
f = URI.open(url)
|
19
|
+
canvas = ChunkyPNG::Canvas.from_io(f)
|
20
|
+
f.close
|
21
|
+
data = canvas.to_rgba_stream
|
22
|
+
width = canvas.width
|
23
|
+
height = canvas.height
|
24
|
+
img = image {
|
25
|
+
image_part(data, width, height, width * 4)
|
26
|
+
}
|
27
|
+
IMAGE_ROWS << [img] # array of one column cell
|
28
|
+
rescue StandardError => e
|
29
|
+
warn url, e.message
|
30
|
+
end
|
31
|
+
|
32
|
+
window('The Red Turtle', 310, 350, false) {
|
33
|
+
horizontal_box {
|
34
|
+
table {
|
35
|
+
image_column('www.ghibli.jp/works/red-turtle')
|
36
|
+
|
37
|
+
cell_rows IMAGE_ROWS
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
on_closing do
|
42
|
+
puts 'Bye Bye'
|
43
|
+
end
|
44
|
+
}.show
|
@@ -4,8 +4,6 @@
|
|
4
4
|
# This example displays images that can be freely downloaded from the Studio Ghibli website.
|
5
5
|
|
6
6
|
require 'glimmer-dsl-libui'
|
7
|
-
require 'chunky_png'
|
8
|
-
require 'open-uri'
|
9
7
|
|
10
8
|
include Glimmer
|
11
9
|
|
@@ -13,18 +11,9 @@ IMAGE_ROWS = []
|
|
13
11
|
|
14
12
|
5.times do |i|
|
15
13
|
url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
|
16
|
-
puts "Processing Image: #{url}"
|
17
|
-
$stdout.flush # for Windows
|
18
|
-
f = URI.open(url)
|
19
|
-
canvas = ChunkyPNG::Canvas.from_io(f)
|
20
|
-
f.close
|
21
|
-
data = canvas.to_rgba_stream
|
22
|
-
width = canvas.width
|
23
|
-
height = canvas.height
|
24
|
-
img = image {
|
25
|
-
image_part(data, width, height, width * 4)
|
26
|
-
}
|
14
|
+
puts "Processing Image: #{url}"; $stdout.flush # for Windows
|
27
15
|
text = url.sub('https://www.ghibli.jp/gallery/thumb-redturtle', '').sub('.png', '')
|
16
|
+
img = image(url)
|
28
17
|
IMAGE_ROWS << [[img, text], [img, text]] # cell values are dual-element arrays
|
29
18
|
rescue StandardError => e
|
30
19
|
warn url, e.message
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# NOTE:
|
4
|
+
# This example displays images that can be freely downloaded from the Studio Ghibli website.
|
5
|
+
|
6
|
+
require 'glimmer-dsl-libui'
|
7
|
+
require 'chunky_png'
|
8
|
+
require 'open-uri'
|
9
|
+
|
10
|
+
include Glimmer
|
11
|
+
|
12
|
+
IMAGE_ROWS = []
|
13
|
+
|
14
|
+
5.times do |i|
|
15
|
+
url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
|
16
|
+
puts "Processing Image: #{url}"
|
17
|
+
$stdout.flush # for Windows
|
18
|
+
f = URI.open(url)
|
19
|
+
canvas = ChunkyPNG::Canvas.from_io(f)
|
20
|
+
f.close
|
21
|
+
data = canvas.to_rgba_stream
|
22
|
+
width = canvas.width
|
23
|
+
height = canvas.height
|
24
|
+
img = image {
|
25
|
+
image_part(data, width, height, width * 4)
|
26
|
+
}
|
27
|
+
text = url.sub('https://www.ghibli.jp/gallery/thumb-redturtle', '').sub('.png', '')
|
28
|
+
IMAGE_ROWS << [[img, text], [img, text]] # cell values are dual-element arrays
|
29
|
+
rescue StandardError => e
|
30
|
+
warn url, e.message
|
31
|
+
end
|
32
|
+
|
33
|
+
window('The Red Turtle', 670, 350) {
|
34
|
+
horizontal_box {
|
35
|
+
table {
|
36
|
+
image_text_column('image/number')
|
37
|
+
image_text_column('image/number (editable)') {
|
38
|
+
editable true
|
39
|
+
}
|
40
|
+
|
41
|
+
cell_rows IMAGE_ROWS
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}.show
|
data/examples/basic_transform.rb
CHANGED
@@ -4,17 +4,14 @@ include Glimmer
|
|
4
4
|
|
5
5
|
window('Basic Transform', 350, 350) {
|
6
6
|
area {
|
7
|
-
|
8
|
-
square(0, 0, 350)
|
9
|
-
|
7
|
+
square(0, 0, 350) {
|
10
8
|
fill r: 255, g: 255, b: 0
|
11
9
|
}
|
12
10
|
40.times do |n|
|
13
|
-
|
14
|
-
square(0, 0, 100)
|
15
|
-
|
11
|
+
square(0, 0, 100) {
|
16
12
|
fill r: [255 - n*5, 0].max, g: [n*5, 255].min, b: 0, a: 0.5
|
17
13
|
stroke :black, thickness: 2
|
14
|
+
|
18
15
|
transform {
|
19
16
|
unless OS.windows?
|
20
17
|
skew 0.15, 0.15
|
@@ -0,0 +1,34 @@
|
|
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 :black, thickness: 2
|
18
|
+
|
19
|
+
transform {
|
20
|
+
unless OS.windows?
|
21
|
+
skew 0.15, 0.15
|
22
|
+
translate 50, 50
|
23
|
+
end
|
24
|
+
rotate 100, 100, -9 * n
|
25
|
+
scale 1.1, 1.1
|
26
|
+
if OS.windows?
|
27
|
+
skew 0.15, 0.15
|
28
|
+
translate 50, 50
|
29
|
+
end
|
30
|
+
}
|
31
|
+
}
|
32
|
+
end
|
33
|
+
}
|
34
|
+
}.show
|
@@ -201,9 +201,7 @@ class ColorTheCircles
|
|
201
201
|
}
|
202
202
|
|
203
203
|
@circles_data.each do |circle_data|
|
204
|
-
|
205
|
-
circle_data[:circle] = circle(*circle_data[:args])
|
206
|
-
|
204
|
+
circle_data[:circle] = circle(*circle_data[:args]) {
|
207
205
|
fill circle_data[:fill]
|
208
206
|
stroke circle_data[:stroke]
|
209
207
|
}
|
data/examples/dynamic_area.rb
CHANGED
@@ -88,9 +88,7 @@ window('Dynamic Area', 240, 600) {
|
|
88
88
|
|
89
89
|
@area = area {
|
90
90
|
on_draw do |area_draw_params|
|
91
|
-
|
92
|
-
rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value)
|
93
|
-
|
91
|
+
rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value) { # a dynamic path is added semi-declaratively inside on_draw block
|
94
92
|
fill r: @red_spinbox.value, g: @green_spinbox.value, b: @blue_spinbox.value, a: @alpha_spinbox.value / 100.0
|
95
93
|
}
|
96
94
|
end
|
data/examples/dynamic_area2.rb
CHANGED
@@ -54,7 +54,7 @@ window('Dynamic Area', 240, 600) {
|
|
54
54
|
value 102
|
55
55
|
|
56
56
|
on_changed do
|
57
|
-
@
|
57
|
+
@rectangle.fill[:r] = @red_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
|
58
58
|
end
|
59
59
|
}
|
60
60
|
|
@@ -63,7 +63,7 @@ window('Dynamic Area', 240, 600) {
|
|
63
63
|
value 102
|
64
64
|
|
65
65
|
on_changed do
|
66
|
-
@
|
66
|
+
@rectangle.fill[:g] = @green_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
|
67
67
|
end
|
68
68
|
}
|
69
69
|
|
@@ -72,7 +72,7 @@ window('Dynamic Area', 240, 600) {
|
|
72
72
|
value 204
|
73
73
|
|
74
74
|
on_changed do
|
75
|
-
@
|
75
|
+
@rectangle.fill[:b] = @blue_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
|
76
76
|
end
|
77
77
|
}
|
78
78
|
|
@@ -81,15 +81,13 @@ window('Dynamic Area', 240, 600) {
|
|
81
81
|
value 100
|
82
82
|
|
83
83
|
on_changed do
|
84
|
-
@
|
84
|
+
@rectangle.fill[:a] = @alpha_spinbox.value / 100.0 # updating hash properties automatically triggers area.queue_redraw_all
|
85
85
|
end
|
86
86
|
}
|
87
87
|
}
|
88
88
|
|
89
89
|
area {
|
90
|
-
@
|
91
|
-
@rectangle = rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value)
|
92
|
-
|
90
|
+
@rectangle = rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value) { # stable path
|
93
91
|
fill r: @red_spinbox.value, g: @green_spinbox.value, b: @blue_spinbox.value, a: @alpha_spinbox.value / 100.0
|
94
92
|
}
|
95
93
|
}
|
data/examples/form_table.rb
CHANGED
@@ -22,15 +22,19 @@ window('Contacts', 600, 600) { |w|
|
|
22
22
|
@name_entry = entry {
|
23
23
|
label 'Name'
|
24
24
|
}
|
25
|
+
|
25
26
|
@email_entry = entry {
|
26
27
|
label 'Email'
|
27
28
|
}
|
29
|
+
|
28
30
|
@phone_entry = entry {
|
29
31
|
label 'Phone'
|
30
32
|
}
|
33
|
+
|
31
34
|
@city_entry = entry {
|
32
35
|
label 'City'
|
33
36
|
}
|
37
|
+
|
34
38
|
@state_entry = entry {
|
35
39
|
label 'State'
|
36
40
|
}
|
data/examples/grid.rb
CHANGED
@@ -8,16 +8,16 @@ window('Grid') {
|
|
8
8
|
tab {
|
9
9
|
tab_item('Span') {
|
10
10
|
grid {
|
11
|
-
4.times
|
12
|
-
4.times
|
11
|
+
4.times do |top_value|
|
12
|
+
4.times do |left_value|
|
13
13
|
label("(#{left_value}, #{top_value}) xspan1\nyspan1") {
|
14
14
|
left left_value
|
15
15
|
top top_value
|
16
16
|
hexpand true
|
17
17
|
vexpand true
|
18
18
|
}
|
19
|
-
|
20
|
-
|
19
|
+
end
|
20
|
+
end
|
21
21
|
label("(0, 4) xspan2\nyspan1 more text fits horizontally") {
|
22
22
|
left 0
|
23
23
|
top 4
|
data/examples/histogram.rb
CHANGED
@@ -79,19 +79,15 @@ window('histogram example', 640, 480) {
|
|
79
79
|
|
80
80
|
@area = area {
|
81
81
|
on_draw do |area_draw_params|
|
82
|
-
|
83
|
-
rectangle(0, 0, area_draw_params[:area_width], area_draw_params[:area_height])
|
84
|
-
|
82
|
+
rectangle(0, 0, area_draw_params[:area_width], area_draw_params[:area_height]) {
|
85
83
|
fill 0xFFFFFF
|
86
84
|
}
|
87
85
|
|
88
86
|
graph_width, graph_height = *graph_size(area_draw_params[:area_width], area_draw_params[:area_height])
|
89
87
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
line(X_OFF_LEFT + graph_width, Y_OFF_TOP + graph_height)
|
94
|
-
}
|
88
|
+
figure(X_OFF_LEFT, Y_OFF_TOP) {
|
89
|
+
line(X_OFF_LEFT, Y_OFF_TOP + graph_height)
|
90
|
+
line(X_OFF_LEFT + graph_width, Y_OFF_TOP + graph_height)
|
95
91
|
|
96
92
|
stroke 0x000000, thickness: 2, miter_limit: 10
|
97
93
|
}
|
data/examples/meta_example.rb
CHANGED
@@ -5,8 +5,10 @@ require 'fileutils'
|
|
5
5
|
class MetaExample
|
6
6
|
include Glimmer
|
7
7
|
|
8
|
+
ADDITIONAL_BASIC_EXAMPLES = ['Color Button', 'Font Button', 'Form', 'Date Time Picker', 'Simple Notepad']
|
9
|
+
|
8
10
|
def initialize
|
9
|
-
@selected_example_index =
|
11
|
+
@selected_example_index = examples_with_versions.index(basic_examples_with_versions.first)
|
10
12
|
end
|
11
13
|
|
12
14
|
def examples
|
@@ -25,6 +27,14 @@ class MetaExample
|
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
30
|
+
def basic_examples_with_versions
|
31
|
+
examples_with_versions.select {|example| example.start_with?('Basic') || ADDITIONAL_BASIC_EXAMPLES.include?(example) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def advanced_examples_with_versions
|
35
|
+
examples_with_versions - basic_examples_with_versions
|
36
|
+
end
|
37
|
+
|
28
38
|
def file_path_for(example)
|
29
39
|
File.join(File.expand_path('.', __dir__), "#{example.underscore}.rb")
|
30
40
|
end
|
@@ -66,17 +76,47 @@ class MetaExample
|
|
66
76
|
vertical_box {
|
67
77
|
stretchy false
|
68
78
|
|
69
|
-
|
79
|
+
tab {
|
70
80
|
stretchy false
|
71
|
-
items examples_with_versions
|
72
|
-
selected @selected_example_index
|
73
81
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
82
|
+
tab_item('Basic') {
|
83
|
+
vertical_box {
|
84
|
+
@basic_example_radio_buttons = radio_buttons {
|
85
|
+
stretchy false
|
86
|
+
items basic_examples_with_versions
|
87
|
+
selected basic_examples_with_versions.index(examples_with_versions[@selected_example_index])
|
88
|
+
|
89
|
+
on_selected do
|
90
|
+
@selected_example_index = examples_with_versions.index(basic_examples_with_versions[@basic_example_radio_buttons.selected])
|
91
|
+
example = selected_example
|
92
|
+
@code_entry.text = File.read(file_path_for(example))
|
93
|
+
@version_spinbox.value = 1
|
94
|
+
end
|
95
|
+
}
|
96
|
+
|
97
|
+
label # filler
|
98
|
+
label # filler
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
tab_item('Advanced') {
|
103
|
+
vertical_box {
|
104
|
+
@advanced_example_radio_buttons = radio_buttons {
|
105
|
+
stretchy false
|
106
|
+
items advanced_examples_with_versions
|
107
|
+
|
108
|
+
on_selected do
|
109
|
+
@selected_example_index = examples_with_versions.index(advanced_examples_with_versions[@advanced_example_radio_buttons.selected])
|
110
|
+
example = selected_example
|
111
|
+
@code_entry.text = File.read(file_path_for(example))
|
112
|
+
@version_spinbox.value = 1
|
113
|
+
end
|
114
|
+
}
|
115
|
+
|
116
|
+
label # filler
|
117
|
+
label # filler
|
118
|
+
}
|
119
|
+
}
|
80
120
|
}
|
81
121
|
|
82
122
|
horizontal_box {
|
data/examples/snake.rb
CHANGED
data/examples/tetris.rb
CHANGED
@@ -203,34 +203,31 @@ class Tetris
|
|
203
203
|
bevel_pixel_size = 0.16 * block_size.to_f
|
204
204
|
color = Glimmer::LibUI.interpret_color(Model::Block::COLOR_CLEAR)
|
205
205
|
area {
|
206
|
-
block[:background_square] =
|
207
|
-
square(0, 0, block_size)
|
208
|
-
|
206
|
+
block[:background_square] = square(0, 0, block_size) {
|
209
207
|
fill color
|
210
208
|
}
|
211
|
-
|
212
|
-
|
213
|
-
|
209
|
+
|
210
|
+
block[:top_bevel_edge] = polygon {
|
211
|
+
point_array 0, 0, block_size, 0, block_size - bevel_pixel_size, bevel_pixel_size, bevel_pixel_size, bevel_pixel_size
|
214
212
|
fill r: color[:r] + 4*BEVEL_CONSTANT, g: color[:g] + 4*BEVEL_CONSTANT, b: color[:b] + 4*BEVEL_CONSTANT
|
215
213
|
}
|
216
|
-
|
217
|
-
|
218
|
-
|
214
|
+
|
215
|
+
block[:right_bevel_edge] = polygon {
|
216
|
+
point_array block_size, 0, block_size - bevel_pixel_size, bevel_pixel_size, block_size - bevel_pixel_size, block_size - bevel_pixel_size, block_size, block_size
|
219
217
|
fill r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT
|
220
218
|
}
|
221
|
-
|
222
|
-
|
223
|
-
|
219
|
+
|
220
|
+
block[:bottom_bevel_edge] = polygon {
|
221
|
+
point_array block_size, block_size, 0, block_size, bevel_pixel_size, block_size - bevel_pixel_size, block_size - bevel_pixel_size, block_size - bevel_pixel_size
|
224
222
|
fill r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT
|
225
223
|
}
|
226
|
-
|
227
|
-
|
228
|
-
|
224
|
+
|
225
|
+
block[:left_bevel_edge] = polygon {
|
226
|
+
point_array 0, 0, 0, block_size, bevel_pixel_size, block_size - bevel_pixel_size, bevel_pixel_size, bevel_pixel_size
|
229
227
|
fill r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT
|
230
228
|
}
|
231
|
-
|
232
|
-
|
233
|
-
|
229
|
+
|
230
|
+
block[:border_square] = square(0, 0, block_size) {
|
234
231
|
stroke COLOR_GRAY
|
235
232
|
}
|
236
233
|
|
@@ -38,8 +38,10 @@ class TicTacToe
|
|
38
38
|
|
39
39
|
#row and column numbers are 1-based
|
40
40
|
def mark(row, column)
|
41
|
-
self[row, column].
|
42
|
-
|
41
|
+
if self[row, column].empty
|
42
|
+
self[row, column].mark(current_sign)
|
43
|
+
game_over? #updates winning sign
|
44
|
+
end
|
43
45
|
end
|
44
46
|
|
45
47
|
def current_sign
|