glimmer-dsl-libui 0.2.24 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -0
  3. data/README.md +1153 -921
  4. data/VERSION +1 -1
  5. data/examples/area_gallery.rb +19 -19
  6. data/examples/area_gallery2.rb +91 -89
  7. data/examples/area_gallery3.rb +19 -19
  8. data/examples/area_gallery4.rb +91 -89
  9. data/examples/basic_image.rb +19 -0
  10. data/examples/basic_image2.rb +13 -0
  11. data/examples/basic_image3.rb +23 -0
  12. data/examples/basic_image4.rb +17 -0
  13. data/examples/basic_image5.rb +75 -0
  14. data/examples/basic_table_color.rb +1 -11
  15. data/examples/basic_table_color2.rb +39 -0
  16. data/examples/basic_table_image.rb +2 -14
  17. data/examples/basic_table_image2.rb +44 -0
  18. data/examples/basic_table_image_text.rb +2 -13
  19. data/examples/basic_table_image_text2.rb +44 -0
  20. data/examples/basic_transform.rb +3 -6
  21. data/examples/basic_transform2.rb +34 -0
  22. data/examples/color_the_circles.rb +1 -3
  23. data/examples/dynamic_area.rb +1 -3
  24. data/examples/dynamic_area2.rb +5 -7
  25. data/examples/form_table.rb +4 -0
  26. data/examples/grid.rb +4 -4
  27. data/examples/histogram.rb +4 -8
  28. data/examples/meta_example.rb +50 -10
  29. data/examples/snake.rb +1 -3
  30. data/examples/tetris.rb +15 -18
  31. data/examples/tic_tac_toe/board.rb +4 -2
  32. data/examples/tic_tac_toe.rb +1 -3
  33. data/glimmer-dsl-libui.gemspec +0 -0
  34. data/lib/glimmer/dsl/libui/control_expression.rb +1 -1
  35. data/lib/glimmer/dsl/libui/shape_expression.rb +6 -1
  36. data/lib/glimmer/libui/control_proxy/area_proxy.rb +1 -0
  37. data/lib/glimmer/libui/control_proxy/column.rb +2 -2
  38. data/lib/glimmer/libui/control_proxy/image_part_proxy.rb +0 -1
  39. data/lib/glimmer/libui/control_proxy/image_proxy.rb +159 -12
  40. data/lib/glimmer/libui/control_proxy/table_proxy.rb +15 -2
  41. data/lib/glimmer/libui/control_proxy/window_proxy.rb +1 -1
  42. data/lib/glimmer/libui/control_proxy.rb +7 -7
  43. data/lib/glimmer/libui/image_path_renderer.rb +30 -0
  44. data/lib/glimmer/libui/shape.rb +44 -1
  45. metadata +29 -19
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is the manual way of rendering an image unto an area control.
4
+ # It could come in handy in special situations.
5
+ # Otherwise, it is recommended to simply utilize the `image` control that
6
+ # can be nested under area or area on_draw listener to automate all this work.
7
+
8
+ require 'glimmer-dsl-libui'
9
+ require 'chunky_png'
10
+
11
+ include Glimmer
12
+
13
+ puts 'Parsing image...'; $stdout.flush
14
+
15
+ f = File.open(File.expand_path('../icons/glimmer.png', __dir__))
16
+ canvas = ChunkyPNG::Canvas.from_io(f)
17
+ f.close
18
+ canvas.resample_nearest_neighbor!(96, 96)
19
+ data = canvas.to_rgba_stream
20
+ width = canvas.width
21
+ height = canvas.height
22
+ puts "Image width: #{width}"
23
+ puts "Image height: #{height}"
24
+
25
+ puts 'Parsing colors...'; $stdout.flush
26
+
27
+ color_maps = height.times.map do |y|
28
+ width.times.map do |x|
29
+ r = data[(y*width + x)*4].ord
30
+ g = data[(y*width + x)*4 + 1].ord
31
+ b = data[(y*width + x)*4 + 2].ord
32
+ a = data[(y*width + x)*4 + 3].ord
33
+ {x: x, y: y, color: {r: r, g: g, b: b, a: a}}
34
+ end
35
+ end.flatten
36
+ puts "#{color_maps.size} pixels to render..."; $stdout.flush
37
+
38
+ puts 'Parsing shapes...'; $stdout.flush
39
+
40
+ shape_maps = []
41
+ original_color_maps = color_maps.dup
42
+ indexed_original_color_maps = Hash[original_color_maps.each_with_index.to_a]
43
+ color_maps.each do |color_map|
44
+ index = indexed_original_color_maps[color_map]
45
+ @rectangle_start_x ||= color_map[:x]
46
+ @rectangle_width ||= 1
47
+ if color_map[:x] < width - 1 && color_map[:color] == original_color_maps[index + 1][:color]
48
+ @rectangle_width += 1
49
+ else
50
+ if color_map[:x] > 0 && color_map[:color] == original_color_maps[index - 1][:color]
51
+ shape_maps << {x: @rectangle_start_x, y: color_map[:y], width: @rectangle_width, height: 1, color: color_map[:color]}
52
+ else
53
+ shape_maps << {x: color_map[:x], y: color_map[:y], width: 1, height: 1, color: color_map[:color]}
54
+ end
55
+ @rectangle_width = 1
56
+ @rectangle_start_x = color_map[:x] == width - 1 ? 0 : color_map[:x] + 1
57
+ end
58
+ end
59
+ puts "#{shape_maps.size} shapes to render..."; $stdout.flush
60
+
61
+ puts 'Rendering image...'; $stdout.flush
62
+
63
+ window('Basic Image', 96, 96) {
64
+ area {
65
+ on_draw do |area_draw_params|
66
+ shape_maps.each do |shape_map|
67
+ path {
68
+ rectangle(shape_map[:x], shape_map[:y], shape_map[:width], shape_map[:height])
69
+
70
+ fill shape_map[:color]
71
+ }
72
+ end
73
+ end
74
+ }
75
+ }.show
@@ -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
- 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
- }
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
- $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
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
@@ -4,17 +4,14 @@ include Glimmer
4
4
 
5
5
  window('Basic Transform', 350, 350) {
6
6
  area {
7
- path {
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
- path {
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
- path {
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
  }
@@ -88,9 +88,7 @@ window('Dynamic Area', 240, 600) {
88
88
 
89
89
  @area = area {
90
90
  on_draw do |area_draw_params|
91
- path { # 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
-
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
@@ -54,7 +54,7 @@ window('Dynamic Area', 240, 600) {
54
54
  value 102
55
55
 
56
56
  on_changed do
57
- @path.fill[:r] = @red_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
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
- @path.fill[:g] = @green_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
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
- @path.fill[:b] = @blue_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
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
- @path.fill[:a] = @alpha_spinbox.value / 100.0 # updating hash properties automatically triggers area.queue_redraw_all
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
- @path = path { # stable path
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
  }
@@ -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 { |top_value|
12
- 4.times { |left_value|
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
@@ -79,19 +79,15 @@ window('histogram example', 640, 480) {
79
79
 
80
80
  @area = area {
81
81
  on_draw do |area_draw_params|
82
- path {
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
- path {
91
- figure(X_OFF_LEFT, Y_OFF_TOP) {
92
- line(X_OFF_LEFT, Y_OFF_TOP + graph_height)
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
  }
@@ -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 = 0
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
- @example_radio_buttons = radio_buttons {
79
+ tab {
70
80
  stretchy false
71
- items examples_with_versions
72
- selected @selected_example_index
73
81
 
74
- on_selected do
75
- @selected_example_index = @example_radio_buttons.selected
76
- example = selected_example
77
- @code_entry.text = File.read(file_path_for(example))
78
- @version_spinbox.value = 1
79
- end
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
@@ -61,9 +61,7 @@ class Snake
61
61
 
62
62
  @game.width.times do |column|
63
63
  area {
64
- @cell_grid.last << path {
65
- square(0, 0, CELL_SIZE)
66
-
64
+ @cell_grid.last << square(0, 0, CELL_SIZE) {
67
65
  fill Presenter::Cell::COLOR_CLEAR
68
66
  }
69
67
 
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] = path {
207
- square(0, 0, block_size)
208
-
206
+ block[:background_square] = square(0, 0, block_size) {
209
207
  fill color
210
208
  }
211
- block[:top_bevel_edge] = path {
212
- polygon(0, 0, block_size, 0, block_size - bevel_pixel_size, bevel_pixel_size, bevel_pixel_size, bevel_pixel_size)
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
- block[:right_bevel_edge] = path {
217
- polygon(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)
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
- block[:bottom_bevel_edge] = path {
222
- polygon(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)
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
- block[:left_bevel_edge] = path {
227
- polygon(0, 0, 0, block_size, bevel_pixel_size, block_size - bevel_pixel_size, bevel_pixel_size, bevel_pixel_size)
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
- block[:border_square] = path {
232
- square(0, 0, block_size)
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].mark(current_sign)
42
- game_over? #updates winning sign
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
@@ -45,9 +45,7 @@ class TicTacToe
45
45
 
46
46
  3.times.map do |column|
47
47
  area {
48
- path {
49
- square(0, 0, 60)
50
-
48
+ square(0, 0, 60) {
51
49
  stroke :black, thickness: 2
52
50
  }
53
51
  text(23, 19) {
Binary file
@@ -40,7 +40,7 @@ module Glimmer
40
40
 
41
41
  def add_content(parent, keyword, *args, &block)
42
42
  super
43
- parent.post_add_content
43
+ parent&.post_add_content
44
44
  end
45
45
  end
46
46
  end