glimmer-dsl-libui 0.1.0 → 0.1.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.
@@ -19,37 +19,22 @@
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/libui/control_proxy'
22
+ require 'glimmer/libui/shape'
23
23
 
24
24
  module Glimmer
25
25
  module LibUI
26
- # Proxy for LibUI rectangle objects
27
- #
28
- # Follows the Proxy Design Pattern
29
- class RectangleProxy < ControlProxy
30
- def initialize(keyword, parent, args, &block)
31
- @keyword = keyword
32
- @parent_proxy = parent
33
- @args = args
34
- @block = block
35
- @enabled = true
36
- post_add_content if @block.nil?
37
- end
38
-
26
+ class Arc < Shape
27
+ parameters :x_center, :y_center, :radius, :start_angle, :sweep, :is_negative
28
+ parameter_defaults 0, 0, 0, 0, 360, false
29
+
39
30
  def draw(area_draw_params)
40
- ::LibUI.draw_path_add_rectangle(@parent_proxy.libui, *@args)
41
- end
42
-
43
- def destroy
44
- if @parent_proxy
45
- @parent_proxy.children.delete(self)
31
+ @args[5] ||= ControlProxy.boolean_to_integer(@args[5], allow_nil: false)
32
+ if parent.is_a?(Figure) && parent.x.nil? && parent.y.nil?
33
+ ::LibUI.draw_path_new_figure_with_arc(path_proxy.libui, *@args)
34
+ else
35
+ ::LibUI.draw_path_arc_to(path_proxy.libui, *@args)
46
36
  end
47
- end
48
-
49
- private
50
-
51
- def build_control
52
- # No Op
37
+ super
53
38
  end
54
39
  end
55
40
  end
@@ -46,6 +46,29 @@ module Glimmer
46
46
  @children ||= []
47
47
  end
48
48
 
49
+ def on_draw(&block)
50
+ @on_draw_procs ||= []
51
+ if block.nil?
52
+ @on_draw_procs
53
+ else
54
+ @on_draw_procs << block
55
+ block
56
+ end
57
+ end
58
+
59
+ def can_handle_listener?(listener_name)
60
+ listener_name == 'on_draw' || super
61
+ end
62
+
63
+ def handle_listener(listener_name, &listener)
64
+ case listener_name
65
+ when 'on_draw'
66
+ on_draw(&listener)
67
+ else
68
+ super
69
+ end
70
+ end
71
+
49
72
  private
50
73
 
51
74
  def build_control
@@ -56,13 +79,27 @@ module Glimmer
56
79
  def install_listeners
57
80
  @area_handler.Draw = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_draw_params|
58
81
  area_draw_params = ::LibUI::FFI::AreaDrawParams.new(area_draw_params)
59
- children.each {|child| child.draw(area_draw_params)}
82
+ area_draw_params = area_draw_params_hash(area_draw_params)
83
+ children.dup.each {|child| child.draw(area_draw_params)}
84
+ on_draw.each {|listener| listener.call(area_draw_params) }
60
85
  end
61
86
  @area_handler.MouseEvent = fiddle_closure_block_caller(0, [0]) {}
62
87
  @area_handler.MouseCrossed = fiddle_closure_block_caller(0, [0]) {}
63
88
  @area_handler.DragBroken = fiddle_closure_block_caller(0, [0]) {}
64
89
  @area_handler.KeyEvent = fiddle_closure_block_caller(0, [0]) {}
65
90
  end
91
+
92
+ def area_draw_params_hash(area_draw_params)
93
+ {
94
+ context: area_draw_params.Context,
95
+ area_width: area_draw_params.AreaWidth,
96
+ area_height: area_draw_params.AreaHeight,
97
+ clip_x: area_draw_params.ClipX,
98
+ clip_y: area_draw_params.ClipY,
99
+ clip_width: area_draw_params.ClipWidth,
100
+ clip_height: area_draw_params.ClipHeight,
101
+ }
102
+ end
66
103
  end
67
104
  end
68
105
  end
@@ -0,0 +1,36 @@
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/libui/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Bezier < Shape
27
+ parameters :c1_x, :c1_y, :c2_x, :c2_y, :end_x, :end_y
28
+ parameter_defaults 0, 0, 0, 0, 0, 0
29
+
30
+ def draw(area_draw_params)
31
+ ::LibUI.draw_path_bezier_to(path_proxy.libui, *@args)
32
+ super
33
+ end
34
+ end
35
+ end
36
+ end
@@ -35,7 +35,12 @@ module Glimmer
35
35
  def on_clicked(&block)
36
36
  # TODO consider generalizing into custom listeners and moving to ControlProxy
37
37
  @on_clicked_procs ||= []
38
- @on_clicked_procs << block
38
+ if block.nil?
39
+ @on_clicked_procs
40
+ else
41
+ @on_clicked_procs << block
42
+ block
43
+ end
39
44
  end
40
45
 
41
46
  def can_handle_listener?(listener_name)
@@ -26,7 +26,7 @@ module Glimmer
26
26
  # Follows the Proxy Design Pattern
27
27
  class ControlProxy
28
28
  class << self
29
- def control_exists?(keyword)
29
+ def exists?(keyword)
30
30
  ::LibUI.respond_to?("new_#{keyword}") ||
31
31
  ::LibUI.respond_to?(keyword) ||
32
32
  Glimmer::LibUI.constants.include?("#{keyword.camelcase(:upper)}Proxy".to_sym)
@@ -55,12 +55,12 @@ module Glimmer
55
55
  control_proxies.find {|c| c.is_a?(Glimmer::LibUI::WindowProxy)}
56
56
  end
57
57
 
58
- def integer_to_boolean(int)
59
- int.nil? ? nil : int == 1
58
+ def integer_to_boolean(int, allow_nil: true)
59
+ int.nil? ? (allow_nil ? nil : false) : int == 1
60
60
  end
61
61
 
62
- def boolean_to_integer(bool)
63
- bool.nil? ? nil : (bool ? 1 : 0)
62
+ def boolean_to_integer(bool, allow_nil: true)
63
+ bool.nil? ? (allow_nil ? nil : 0) : (bool ? 1 : 0)
64
64
  end
65
65
 
66
66
  def menu_proxies
@@ -92,7 +92,7 @@ module Glimmer
92
92
  ]
93
93
 
94
94
  # libui returns the contained LibUI object
95
- attr_reader :parent_proxy, :libui, :args, :keyword
95
+ attr_reader :parent_proxy, :libui, :args, :keyword, :block
96
96
 
97
97
  def initialize(keyword, parent, args, &block)
98
98
  @keyword = keyword
@@ -258,6 +258,10 @@ module Glimmer
258
258
  alias set_visible visible
259
259
  alias visible= visible
260
260
 
261
+ def content(&block)
262
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::ControlExpression.new, @keyword, &block)
263
+ end
264
+
261
265
  private
262
266
 
263
267
  def build_control
@@ -0,0 +1,52 @@
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/libui/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Represents a figure consisting of shapes (nested under path)
27
+ # Can optionally have `closed true` property (connecting last point to first point automatically)
28
+ class Figure < Shape
29
+ parameters :x, :y
30
+ parameter_defaults nil, nil
31
+
32
+ def draw(area_draw_params)
33
+ ::LibUI.draw_path_new_figure(path_proxy.libui, *@args) unless @args.compact.empty? # TODO if args empty then wait till there is an arc child and it starts the figure
34
+ children.dup.each {|child| child.draw(area_draw_params)}
35
+ ::LibUI.draw_path_close_figure(path_proxy.libui) if closed?
36
+ super
37
+ end
38
+
39
+ def closed(value = nil)
40
+ if value.nil?
41
+ @closed
42
+ else
43
+ @closed = value
44
+ area_proxy&.queue_redraw_all
45
+ end
46
+ end
47
+ alias closed= closed
48
+ alias set_closed closed
49
+ alias closed? closed
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,36 @@
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/libui/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Line < Shape
27
+ parameters :x, :y
28
+ parameter_defaults 0, 0
29
+
30
+ def draw(area_draw_params)
31
+ ::LibUI.draw_path_line_to(path_proxy.libui, *@args)
32
+ super
33
+ end
34
+ end
35
+ end
36
+ end
@@ -42,16 +42,24 @@ module Glimmer
42
42
  children << child
43
43
  end
44
44
 
45
+ def post_add_content
46
+ super
47
+ if @parent_proxy.nil? && area_draw_params
48
+ draw(area_draw_params)
49
+ destroy
50
+ end
51
+ end
52
+
45
53
  def children
46
54
  @children ||= []
47
55
  end
48
56
 
49
57
  def draw(area_draw_params)
50
58
  build_control
51
- children.each {|child| child.draw(area_draw_params)}
59
+ children.dup.each {|child| child.draw(area_draw_params)}
52
60
  ::LibUI.draw_path_end(@libui)
53
- ::LibUI.draw_fill(area_draw_params.Context, @libui, fill_draw_brush.to_ptr) unless fill.empty?
54
- ::LibUI.draw_stroke(area_draw_params.Context, @libui, stroke_draw_brush, draw_stroke_params) unless stroke.empty?
61
+ ::LibUI.draw_fill(area_draw_params[:context], @libui, fill_draw_brush.to_ptr) unless fill.empty?
62
+ ::LibUI.draw_stroke(area_draw_params[:context], @libui, stroke_draw_brush, draw_stroke_params) unless stroke.empty?
55
63
  ::LibUI.draw_free_path(@libui)
56
64
  end
57
65
 
@@ -64,6 +72,14 @@ module Glimmer
64
72
  @fill ||= {}
65
73
  else
66
74
  @fill = args
75
+ @fill[:a] = 1.0 if @fill[:a].nil?
76
+ @parent_proxy&.queue_redraw_all
77
+ end
78
+ @fill.tap do
79
+ @fill_observer ||= Glimmer::DataBinding::Observer.proc do
80
+ @parent_proxy&.queue_redraw_all
81
+ end
82
+ @fill_observer.observe(@fill)
67
83
  end
68
84
  end
69
85
  alias fill= fill
@@ -80,6 +96,14 @@ module Glimmer
80
96
  @stroke ||= {}
81
97
  else
82
98
  @stroke = args
99
+ @stroke[:a] = 1.0 if @stroke[:a].nil?
100
+ @parent_proxy&.queue_redraw_all
101
+ end
102
+ @stroke.tap do
103
+ @stroke_observer ||= Glimmer::DataBinding::Observer.proc do
104
+ @parent_proxy&.queue_redraw_all
105
+ end
106
+ @stroke_observer.observe(@stroke)
83
107
  end
84
108
  end
85
109
  alias stroke= stroke
@@ -103,13 +127,17 @@ module Glimmer
103
127
  @draw_stroke_params.DashPhase = @stroke[:dash_phase] || 0
104
128
  @draw_stroke_params
105
129
  end
130
+
131
+ # returns area_draw_params if built inside on_draw listener (not needed if declared outside)
132
+ def area_draw_params
133
+ @args[0] if @parent_proxy.nil?
134
+ end
106
135
 
107
136
  def destroy
108
- if @parent_proxy
109
- @parent_proxy.children.delete(self)
110
- end
137
+ @parent_proxy.children.delete(self) unless @parent_proxy.nil?
138
+ ControlProxy.control_proxies.delete(self)
111
139
  end
112
-
140
+
113
141
  private
114
142
 
115
143
  def build_control
@@ -0,0 +1,36 @@
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/libui/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Rectangle < Shape
27
+ parameters :x, :y, :width, :height
28
+ parameter_defaults 0, 0, 0, 0
29
+
30
+ def draw(area_draw_params)
31
+ ::LibUI.draw_path_add_rectangle(path_proxy.libui, *@args)
32
+ super
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,144 @@
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
+ module Glimmer
23
+ module LibUI
24
+ # Represents LibUI lightweight shape objects nested under path (e.g. line, rectangle, arc, bezier)
25
+ class Shape
26
+ class << self
27
+ def exists?(keyword)
28
+ Glimmer::LibUI.constants.include?(constant_symbol(keyword)) and
29
+ shape_class(keyword).respond_to?(:ancestors) and
30
+ shape_class(keyword).ancestors.include?(Shape)
31
+ end
32
+
33
+ def create(keyword, parent, args, &block)
34
+ shape_class(keyword).new(keyword, parent, args, &block)
35
+ end
36
+
37
+ def shape_class(keyword)
38
+ Glimmer::LibUI.const_get(constant_symbol(keyword))
39
+ end
40
+
41
+ def parameters(*params)
42
+ if params.empty?
43
+ @parameters
44
+ else
45
+ @parameters = params
46
+ end
47
+ end
48
+
49
+ def parameter_defaults(*defaults)
50
+ if defaults.empty?
51
+ @parameter_defaults
52
+ else
53
+ @parameter_defaults = defaults
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def constant_symbol(keyword)
60
+ "#{keyword.camelcase(:upper)}".to_sym
61
+ end
62
+ end
63
+
64
+ attr_reader :parent, :args, :keyword, :block
65
+
66
+ def initialize(keyword, parent, args, &block)
67
+ @keyword = keyword
68
+ @parent = parent
69
+ @args = args
70
+ @block = block
71
+ set_parameter_defaults
72
+ post_add_content if @block.nil?
73
+ end
74
+
75
+ # Subclasses may override to perform post add_content work (normally must call super)
76
+ def post_add_content
77
+ @parent&.post_initialize_child(self)
78
+ end
79
+
80
+ # Subclasses may override to perform post initialization work on an added child (normally must call super)
81
+ def post_initialize_child(child)
82
+ children << child
83
+ end
84
+
85
+ def children
86
+ @children ||= []
87
+ end
88
+
89
+ # Subclasses must override to perform draw work and call super afterwards to ensure calling destroy when semi-declarative in an on_draw method
90
+ def draw(area_draw_params)
91
+ destroy if area_proxy.nil?
92
+ end
93
+
94
+ def destroy
95
+ @parent.children.delete(self)
96
+ end
97
+
98
+ def area_proxy
99
+ find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(AreaProxy) }
100
+ end
101
+
102
+ def path_proxy
103
+ find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(PathProxy) }
104
+ end
105
+
106
+ def respond_to?(method_name, *args, &block)
107
+ self.class.parameters.include?(method_name.to_s.sub(/=$/, '').sub(/^set_/, '').to_sym) or
108
+ super(method_name, true)
109
+ end
110
+
111
+ def method_missing(method_name, *args, &block)
112
+ method_name_parameter = method_name.to_s.sub(/=$/, '').sub(/^set_/, '').to_sym
113
+ if self.class.parameters.include?(method_name_parameter)
114
+ method_name = method_name.to_s
115
+ parameter_index = self.class.parameters.index(method_name_parameter)
116
+ if method_name.start_with?('set_') || method_name.end_with?('=') || !args.empty?
117
+ @args[parameter_index] = args.first
118
+ area_proxy&.queue_redraw_all
119
+ else
120
+ @args[parameter_index]
121
+ end
122
+ else
123
+ super
124
+ end
125
+ end
126
+
127
+ private
128
+
129
+ def set_parameter_defaults
130
+ self.class.parameter_defaults.each_with_index do |default, i|
131
+ @args[i] ||= default
132
+ end
133
+ end
134
+
135
+ def find_parent_in_ancestors(&condition)
136
+ found = self
137
+ until condition.call(found)
138
+ found = found.respond_to?(:parent_proxy) ? found.parent_proxy : found.parent
139
+ end
140
+ found
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,36 @@
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/libui/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Square < Shape
27
+ parameters :x, :y, :length
28
+ parameter_defaults 0, 0, 0
29
+
30
+ def draw(area_draw_params)
31
+ ::LibUI.draw_path_add_rectangle(path_proxy.libui, *@args, length)
32
+ super
33
+ end
34
+ end
35
+ end
36
+ end
@@ -48,8 +48,14 @@ module Glimmer
48
48
  end
49
49
 
50
50
  def on_destroy(&block)
51
+ # TODO look into a way to generalize this logic for multiple listeners
51
52
  @on_destroy_procs ||= []
52
- @on_destroy_procs << block
53
+ if block.nil?
54
+ @on_destroy_procs
55
+ else
56
+ @on_destroy_procs << block
57
+ block
58
+ end
53
59
  end
54
60
 
55
61
  def show