glimmer-dsl-libui 0.3.2 → 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.
@@ -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
@@ -21,6 +21,9 @@
21
21
 
22
22
  require 'glimmer/dsl/expression'
23
23
  require 'glimmer/dsl/parent_expression'
24
+ require 'glimmer/libui/control_proxy/path_proxy'
25
+ require 'glimmer/libui/shape'
26
+ require 'glimmer/libui/control_proxy/area_proxy'
24
27
 
25
28
  module Glimmer
26
29
  module DSL
@@ -32,7 +35,9 @@ module Glimmer
32
35
  Glimmer::LibUI::Shape.exists?(keyword) and
33
36
  (
34
37
  parent.is_a?(Glimmer::LibUI::ControlProxy::PathProxy) or
35
- parent.is_a?(Glimmer::LibUI::Shape)
38
+ parent.is_a?(Glimmer::LibUI::Shape) or
39
+ parent.is_a?(Glimmer::LibUI::ControlProxy::AreaProxy) or
40
+ (parent.nil? && Glimmer::LibUI::ControlProxy::AreaProxy.current_area_draw_params)
36
41
  )
37
42
  end
38
43
 
@@ -73,12 +73,22 @@ module Glimmer
73
73
  @args = args
74
74
  @block = block
75
75
  set_parameter_defaults
76
+ build_control if implicit_path?
76
77
  post_add_content if @block.nil?
77
78
  end
78
79
 
79
80
  # Subclasses may override to perform post add_content work (normally must call super)
80
81
  def post_add_content
81
82
  @parent&.post_initialize_child(self)
83
+ @parent.post_add_content if implicit_path? && dynamic?
84
+ end
85
+
86
+ def post_initialize_child(child, add_child: true)
87
+ if child.is_a?(ControlProxy::MatrixProxy)
88
+ path_proxy.post_initialize_child(child, add_child: add_child)
89
+ else
90
+ super(child, add_child: add_child)
91
+ end
82
92
  end
83
93
 
84
94
  # Subclasses must override to perform draw work and call super afterwards to ensure calling destroy when semi-declarative in an on_draw method
@@ -105,6 +115,24 @@ module Glimmer
105
115
  def path_proxy
106
116
  find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(ControlProxy::PathProxy) }
107
117
  end
118
+
119
+ def fill(*args)
120
+ path_proxy.fill(*args)
121
+ end
122
+ alias fill= fill
123
+ alias set_fill fill
124
+
125
+ def stroke(*args)
126
+ path_proxy.stroke(*args)
127
+ end
128
+ alias stroke= stroke
129
+ alias set_stroke stroke
130
+
131
+ def transform(matrix = nil)
132
+ path_proxy.transform(matrix)
133
+ end
134
+ alias transform= transform
135
+ alias set_transform transform
108
136
 
109
137
  def respond_to?(method_name, *args, &block)
110
138
  self.class.parameters.include?(method_name.to_s.sub(/=$/, '').sub(/^set_/, '').to_sym) or
@@ -117,6 +145,7 @@ module Glimmer
117
145
  method_name = method_name.to_s
118
146
  parameter_index = self.class.parameters.index(method_name_parameter)
119
147
  if method_name.start_with?('set_') || method_name.end_with?('=') || !args.empty?
148
+ args = [args] if args.size > 1
120
149
  if args.first != @args[parameter_index]
121
150
  @args[parameter_index] = args.first
122
151
  request_auto_redraw
@@ -124,13 +153,27 @@ module Glimmer
124
153
  else
125
154
  @args[parameter_index]
126
155
  end
127
- else
156
+ else # TODO consider if there is a need to redirect anything to path proxy or delete this TODO
128
157
  super
129
158
  end
130
159
  end
131
160
 
132
161
  private
133
162
 
163
+ def build_control
164
+ block = Proc.new {} if dynamic?
165
+ @parent = Glimmer::LibUI::ControlProxy::PathProxy.new('path', @parent, [], &block)
166
+ end
167
+
168
+ # indicates if nested directly under area or on_draw event (having an implicit path not an explicit path parent)
169
+ def implicit_path?
170
+ @implicit_path ||= !!(@parent.is_a?(Glimmer::LibUI::ControlProxy::AreaProxy) || (@parent.nil? && Glimmer::LibUI::ControlProxy::AreaProxy.current_area_draw_params))
171
+ end
172
+
173
+ def dynamic?
174
+ ((@parent.nil? || (@parent.is_a?(ControlProxy::PathProxy) && @parent.parent_proxy.nil?)) && Glimmer::LibUI::ControlProxy::AreaProxy.current_area_draw_params)
175
+ end
176
+
134
177
  def set_parameter_defaults
135
178
  self.class.parameter_defaults.each_with_index do |default, i|
136
179
  @args[i] ||= default
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-16 00:00:00.000000000 Z
11
+ date: 2021-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.4.1
19
+ version: 2.5.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.4.1
26
+ version: 2.5.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: os
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -238,6 +238,7 @@ files:
238
238
  - examples/basic_table_image_text2.rb
239
239
  - examples/basic_table_progress_bar.rb
240
240
  - examples/basic_transform.rb
241
+ - examples/basic_transform2.rb
241
242
  - examples/basic_window.rb
242
243
  - examples/basic_window2.rb
243
244
  - examples/color_button.rb
@@ -394,7 +395,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
394
395
  - !ruby/object:Gem::Version
395
396
  version: '0'
396
397
  requirements: []
397
- rubygems_version: 3.2.22
398
+ rubygems_version: 3.2.31
398
399
  signing_key:
399
400
  specification_version: 4
400
401
  summary: Glimmer DSL for LibUI