glimmer-dsl-libui 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/README.md +3859 -4006
  4. data/VERSION +1 -1
  5. data/bin/girb +0 -0
  6. data/examples/area_gallery.rb +19 -19
  7. data/examples/area_gallery2.rb +91 -89
  8. data/examples/area_gallery3.rb +19 -19
  9. data/examples/area_gallery4.rb +91 -89
  10. data/examples/basic_area.rb +1 -3
  11. data/examples/basic_area2.rb +1 -3
  12. data/examples/basic_area3.rb +17 -0
  13. data/examples/basic_area4.rb +19 -0
  14. data/examples/basic_scrolling_area.rb +79 -0
  15. data/examples/basic_transform.rb +3 -6
  16. data/examples/basic_transform2.rb +34 -0
  17. data/examples/color_the_circles.rb +1 -3
  18. data/examples/dynamic_area.rb +1 -3
  19. data/examples/dynamic_area2.rb +5 -7
  20. data/examples/form_table.rb +4 -0
  21. data/examples/grid.rb +4 -4
  22. data/examples/histogram.rb +4 -8
  23. data/examples/meta_example.rb +50 -10
  24. data/examples/midi_player.rb +2 -6
  25. data/examples/snake/model/game.rb +2 -2
  26. data/examples/snake.rb +9 -21
  27. data/examples/tetris.rb +15 -18
  28. data/examples/tic_tac_toe/board.rb +4 -2
  29. data/examples/tic_tac_toe.rb +4 -15
  30. data/examples/timer.rb +2 -6
  31. data/glimmer-dsl-libui.gemspec +0 -0
  32. data/lib/glimmer/dsl/libui/bind_expression.rb +36 -0
  33. data/lib/glimmer/dsl/libui/data_binding_expression.rb +47 -0
  34. data/lib/glimmer/dsl/libui/dsl.rb +3 -0
  35. data/lib/glimmer/dsl/libui/observe_expression.rb +35 -0
  36. data/lib/glimmer/dsl/libui/shape_expression.rb +6 -1
  37. data/lib/glimmer/dsl/libui/shine_data_binding_expression.rb +42 -0
  38. data/lib/glimmer/dsl/libui/string_expression.rb +4 -5
  39. data/lib/glimmer/libui/attributed_string.rb +19 -6
  40. data/lib/glimmer/libui/control_proxy/area_proxy/scrolling_area_proxy.rb +35 -0
  41. data/lib/glimmer/libui/control_proxy/window_proxy.rb +20 -0
  42. data/lib/glimmer/libui/shape.rb +50 -2
  43. metadata +15 -7
@@ -0,0 +1,35 @@
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/static_expression'
23
+ require 'glimmer/dsl/top_level_expression'
24
+ require 'glimmer/dsl/observe_expression'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module SWT
29
+ class ObserveExpression < StaticExpression
30
+ include TopLevelExpression
31
+ include Glimmer::DSL::ObserveExpression
32
+ end
33
+ end
34
+ end
35
+ end
@@ -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
 
@@ -0,0 +1,42 @@
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/data_binding/model_binding'
24
+ require 'glimmer/data_binding/shine'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module Libui
29
+ class ShineDataBindingExpression < Expression
30
+ def can_interpret?(parent, keyword, *args, &block)
31
+ args.size == 0 and
32
+ block.nil? and
33
+ parent.respond_to?(keyword, *args, &block)
34
+ end
35
+
36
+ def interpret(parent, keyword, *args, &block)
37
+ Glimmer::DataBinding::Shine.new(parent, keyword)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -19,7 +19,6 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- require 'glimmer/dsl/static_expression'
23
22
  require 'glimmer/dsl/parent_expression'
24
23
  require 'glimmer/libui/control_proxy/text_proxy'
25
24
  require 'glimmer/libui/attributed_string'
@@ -27,14 +26,14 @@ require 'glimmer/libui/attributed_string'
27
26
  module Glimmer
28
27
  module DSL
29
28
  module Libui
30
- class StringExpression < StaticExpression
29
+ class StringExpression < Expression
31
30
  include ParentExpression
32
31
 
33
32
  def can_interpret?(parent, keyword, *args, &block)
34
- super and
33
+ keyword == 'string' and
35
34
  (
36
35
  parent.is_a?(Glimmer::LibUI::ControlProxy::TextProxy) or
37
- parent.is_a?(Glimmer::LibUI::AttributedString)
36
+ (parent.is_a?(Glimmer::LibUI::AttributedString) and !args.empty?)
38
37
  )
39
38
  end
40
39
 
@@ -47,7 +46,7 @@ module Glimmer
47
46
  end
48
47
 
49
48
  def add_content(parent, keyword, *args, &block)
50
- parent.post_add_content
49
+ parent.post_add_content(block)
51
50
  end
52
51
  end
53
52
  end
@@ -27,7 +27,8 @@ require 'glimmer/libui/control_proxy/transformable'
27
27
  module Glimmer
28
28
  module LibUI
29
29
  class AttributedString
30
- attr_reader :block, :keyword, :parent_proxy, :args
30
+ attr_reader :keyword, :parent_proxy, :args
31
+ attr_accessor :block
31
32
 
32
33
  def initialize(keyword, parent_proxy, args, &block)
33
34
  @keyword = keyword
@@ -115,10 +116,14 @@ module Glimmer
115
116
  alias open_type_features= open_type_features
116
117
  alias set_open_type_features open_type_features
117
118
 
118
- def post_add_content
119
- block_result = @block&.call
120
- @string = block_result if block_result.is_a?(String)
121
- @parent_proxy&.post_initialize_child(self)
119
+ def post_add_content(block = nil)
120
+ block ||= @block
121
+ block_result = block&.call
122
+ unless @content_added
123
+ @string = block_result if block_result.is_a?(String)
124
+ @parent_proxy&.post_initialize_child(self)
125
+ @content_added = true
126
+ end
122
127
  end
123
128
 
124
129
  def post_initialize_child(child)
@@ -185,12 +190,20 @@ module Glimmer
185
190
  end
186
191
 
187
192
  def redraw
188
- area_proxy&.queue_redraw_all
193
+ area_proxy&.redraw
194
+ end
195
+
196
+ def request_auto_redraw
197
+ area_proxy&.request_auto_redraw
189
198
  end
190
199
 
191
200
  def area_proxy
192
201
  @parent_proxy.parent_proxy
193
202
  end
203
+
204
+ def content(&block)
205
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::StringExpression.new, @keyword, &block)
206
+ end
194
207
  end
195
208
  end
196
209
  end
@@ -31,8 +31,43 @@ module Glimmer
31
31
  class ScrollingAreaProxy < AreaProxy
32
32
  def build_control
33
33
  @area_handler = ::LibUI::FFI::AreaHandler.malloc
34
+ @args[0] ||= Glimmer::LibUI::ControlProxy.main_window_proxy.width
35
+ @args[1] ||= Glimmer::LibUI::ControlProxy.main_window_proxy.height
34
36
  @libui = ::LibUI.new_scrolling_area(@area_handler, *@args)
35
37
  end
38
+
39
+ def width(value = nil)
40
+ if value.nil?
41
+ @args[0]
42
+ else
43
+ @args[0] = value
44
+ set_size(width, height)
45
+ end
46
+ end
47
+ alias width= width
48
+ alias set_width width
49
+
50
+ def height(value = nil)
51
+ if value.nil?
52
+ @args[1]
53
+ else
54
+ @args[1] = value
55
+ set_size(width, height)
56
+ end
57
+ end
58
+ alias height= height
59
+ alias set_height height
60
+
61
+ def set_size(width, height)
62
+ @args[0] = width
63
+ @args[1] = height
64
+ super(width, height)
65
+ end
66
+
67
+ def scroll_to(scroll_x, scroll_y, scroll_width = nil, scroll_height = nil)
68
+ scroll_width, scroll_height = Glimmer::LibUI::ControlProxy.main_window_proxy.content_size
69
+ super(scroll_x, scroll_y, scroll_width, scroll_height)
70
+ end
36
71
  end
37
72
  end
38
73
  end
@@ -113,6 +113,26 @@ module Glimmer
113
113
  alias content_size= content_size
114
114
  alias set_content_size content_size
115
115
 
116
+ def width(value = nil)
117
+ if value.nil?
118
+ content_size.first
119
+ else
120
+ set_content_size(value, height)
121
+ end
122
+ end
123
+ alias width= width
124
+ alias set_width width
125
+
126
+ def height(value = nil)
127
+ if value.nil?
128
+ content_size.last
129
+ else
130
+ set_content_size(width, value)
131
+ end
132
+ end
133
+ alias height= height
134
+ alias set_height height
135
+
116
136
  def resizable(value = nil)
117
137
  if value.nil?
118
138
  @resizable = true if @resizable.nil?
@@ -73,12 +73,27 @@ 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
92
+ end
93
+
94
+ def content(&block)
95
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::ShapeExpression.new, @keyword, &block)
96
+ request_auto_redraw
82
97
  end
83
98
 
84
99
  # Subclasses must override to perform draw work and call super afterwards to ensure calling destroy when semi-declarative in an on_draw method
@@ -87,7 +102,7 @@ module Glimmer
87
102
  end
88
103
 
89
104
  def redraw
90
- area_proxy&.auto_redraw
105
+ area_proxy&.redraw
91
106
  end
92
107
 
93
108
  def request_auto_redraw
@@ -105,6 +120,24 @@ module Glimmer
105
120
  def path_proxy
106
121
  find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(ControlProxy::PathProxy) }
107
122
  end
123
+
124
+ def fill(*args)
125
+ path_proxy.fill(*args)
126
+ end
127
+ alias fill= fill
128
+ alias set_fill fill
129
+
130
+ def stroke(*args)
131
+ path_proxy.stroke(*args)
132
+ end
133
+ alias stroke= stroke
134
+ alias set_stroke stroke
135
+
136
+ def transform(matrix = nil)
137
+ path_proxy.transform(matrix)
138
+ end
139
+ alias transform= transform
140
+ alias set_transform transform
108
141
 
109
142
  def respond_to?(method_name, *args, &block)
110
143
  self.class.parameters.include?(method_name.to_s.sub(/=$/, '').sub(/^set_/, '').to_sym) or
@@ -117,6 +150,7 @@ module Glimmer
117
150
  method_name = method_name.to_s
118
151
  parameter_index = self.class.parameters.index(method_name_parameter)
119
152
  if method_name.start_with?('set_') || method_name.end_with?('=') || !args.empty?
153
+ args = [args] if args.size > 1
120
154
  if args.first != @args[parameter_index]
121
155
  @args[parameter_index] = args.first
122
156
  request_auto_redraw
@@ -124,13 +158,27 @@ module Glimmer
124
158
  else
125
159
  @args[parameter_index]
126
160
  end
127
- else
161
+ else # TODO consider if there is a need to redirect anything to path proxy or delete this TODO
128
162
  super
129
163
  end
130
164
  end
131
165
 
132
166
  private
133
167
 
168
+ def build_control
169
+ block = Proc.new {} if dynamic?
170
+ @parent = Glimmer::LibUI::ControlProxy::PathProxy.new('path', @parent, [], &block)
171
+ end
172
+
173
+ # indicates if nested directly under area or on_draw event (having an implicit path not an explicit path parent)
174
+ def implicit_path?
175
+ @implicit_path ||= !!(@parent.is_a?(Glimmer::LibUI::ControlProxy::AreaProxy) || (@parent.nil? && Glimmer::LibUI::ControlProxy::AreaProxy.current_area_draw_params))
176
+ end
177
+
178
+ def dynamic?
179
+ ((@parent.nil? || (@parent.is_a?(ControlProxy::PathProxy) && @parent.parent_proxy.nil?)) && Glimmer::LibUI::ControlProxy::AreaProxy.current_area_draw_params)
180
+ end
181
+
134
182
  def set_parameter_defaults
135
183
  self.class.parameter_defaults.each_with_index do |default, i|
136
184
  @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.4.0
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-26 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
@@ -64,14 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: 0.0.12
67
+ version: 0.0.13
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 0.0.12
74
+ version: 0.0.13
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: chunky_png
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -217,6 +217,8 @@ files:
217
217
  - examples/area_gallery4.rb
218
218
  - examples/basic_area.rb
219
219
  - examples/basic_area2.rb
220
+ - examples/basic_area3.rb
221
+ - examples/basic_area4.rb
220
222
  - examples/basic_button.rb
221
223
  - examples/basic_draw_text.rb
222
224
  - examples/basic_draw_text2.rb
@@ -226,6 +228,7 @@ files:
226
228
  - examples/basic_image3.rb
227
229
  - examples/basic_image4.rb
228
230
  - examples/basic_image5.rb
231
+ - examples/basic_scrolling_area.rb
229
232
  - examples/basic_table.rb
230
233
  - examples/basic_table_button.rb
231
234
  - examples/basic_table_checkbox.rb
@@ -238,6 +241,7 @@ files:
238
241
  - examples/basic_table_image_text2.rb
239
242
  - examples/basic_table_progress_bar.rb
240
243
  - examples/basic_transform.rb
244
+ - examples/basic_transform2.rb
241
245
  - examples/basic_window.rb
242
246
  - examples/basic_window2.rb
243
247
  - examples/color_button.rb
@@ -279,14 +283,18 @@ files:
279
283
  - glimmer-dsl-libui.gemspec
280
284
  - icons/glimmer.png
281
285
  - lib/glimmer-dsl-libui.rb
286
+ - lib/glimmer/dsl/libui/bind_expression.rb
282
287
  - lib/glimmer/dsl/libui/control_expression.rb
288
+ - lib/glimmer/dsl/libui/data_binding_expression.rb
283
289
  - lib/glimmer/dsl/libui/dsl.rb
284
290
  - lib/glimmer/dsl/libui/file_expression.rb
285
291
  - lib/glimmer/dsl/libui/listener_expression.rb
292
+ - lib/glimmer/dsl/libui/observe_expression.rb
286
293
  - lib/glimmer/dsl/libui/open_file_expression.rb
287
294
  - lib/glimmer/dsl/libui/property_expression.rb
288
295
  - lib/glimmer/dsl/libui/save_file_expression.rb
289
296
  - lib/glimmer/dsl/libui/shape_expression.rb
297
+ - lib/glimmer/dsl/libui/shine_data_binding_expression.rb
290
298
  - lib/glimmer/dsl/libui/string_expression.rb
291
299
  - lib/glimmer/dsl/libui/tab_item_expression.rb
292
300
  - lib/glimmer/fiddle_consumer.rb
@@ -394,7 +402,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
394
402
  - !ruby/object:Gem::Version
395
403
  version: '0'
396
404
  requirements: []
397
- rubygems_version: 3.2.22
405
+ rubygems_version: 3.2.31
398
406
  signing_key:
399
407
  specification_version: 4
400
408
  summary: Glimmer DSL for LibUI