glimmer-dsl-libui 0.0.15 → 0.0.19

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.
data/examples/form.rb CHANGED
@@ -10,13 +10,11 @@ window('Form') { |w|
10
10
  vertical_box {
11
11
  form {
12
12
  @first_name_entry = entry {
13
- # stretchy true # Smart default option for appending to form
14
- label 'First Name'
13
+ label 'First Name' # label property is available when control is nested under form
15
14
  }
16
15
 
17
16
  @last_name_entry = entry {
18
- # stretchy true # Smart default option for appending to form
19
- label 'Last Name'
17
+ label 'Last Name' # label property is available when control is nested under form
20
18
  }
21
19
  }
22
20
 
data/examples/grid.rb CHANGED
@@ -8,8 +8,8 @@ window('Grid') {
8
8
  tab {
9
9
  tab_item('Spanning') {
10
10
  grid {
11
- 4.times { |left_value|
12
- 4.times { |top_value|
11
+ 4.times { |top_value|
12
+ 4.times { |left_value|
13
13
  label("(#{left_value}, #{top_value}) xspan1\nyspan1") {
14
14
  left left_value
15
15
  top top_value
Binary file
@@ -42,7 +42,7 @@ module Glimmer
42
42
 
43
43
  def destroy_child(child)
44
44
  ::LibUI.send("box_delete", @libui, children.index(child))
45
- ControlProxy.all_control_proxies.delete(child)
45
+ ControlProxy.control_proxies.delete(child)
46
46
  end
47
47
 
48
48
  private
@@ -0,0 +1,41 @@
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/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI button objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class ButtonProxy < ControlProxy
30
+ DEFAULT_TEXT = ''
31
+
32
+ private
33
+
34
+ def build_control
35
+ construction_args = @args.dup
36
+ construction_args[0] = DEFAULT_TEXT if construction_args.size == 0
37
+ @libui = ControlProxy.new_control(@keyword, construction_args)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
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/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI checkbox objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class CheckboxProxy < ControlProxy
30
+ DEFAULT_TEXT = ''
31
+
32
+ private
33
+
34
+ def build_control
35
+ construction_args = @args.dup
36
+ construction_args[0] = DEFAULT_TEXT if construction_args.size == 0
37
+ @libui = ControlProxy.new_control(@keyword, construction_args)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,55 @@
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/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Common logic for all column proxy objects
27
+ module Column
28
+ attr_reader :appended
29
+ alias appended? appended
30
+
31
+ def initialize(keyword, parent, args, &block)
32
+ @keyword = keyword
33
+ @parent_proxy = parent
34
+ @args = args
35
+ @block = block
36
+ @enabled = true
37
+ post_add_content if @block.nil?
38
+ end
39
+
40
+ def name
41
+ @args.first
42
+ end
43
+
44
+ private
45
+
46
+ def build_control
47
+ @appended = true
48
+ end
49
+
50
+ def next_column_index
51
+ @parent_proxy.columns.map(&:appended?).compact.count
52
+ end
53
+ end
54
+ end
55
+ end
@@ -33,7 +33,7 @@ module Glimmer
33
33
  end
34
34
 
35
35
  def create(keyword, parent, args, &block)
36
- widget_proxy_class(keyword).new(keyword, parent, args, &block).tap {|c| all_control_proxies << c}
36
+ widget_proxy_class(keyword).new(keyword, parent, args, &block).tap {|c| control_proxies << c}
37
37
  end
38
38
 
39
39
  def widget_proxy_class(keyword)
@@ -46,13 +46,13 @@ module Glimmer
46
46
  end
47
47
 
48
48
  # autosave all controls in this array to avoid garbage collection
49
- def all_control_proxies
50
- @@all_control_proxies = [] unless defined?(@@all_control_proxies)
51
- @@all_control_proxies
49
+ def control_proxies
50
+ @@control_proxies = [] unless defined?(@@control_proxies)
51
+ @@control_proxies
52
52
  end
53
53
 
54
54
  def main_window_proxy
55
- all_control_proxies.find {|c| c.is_a?(Glimmer::LibUI::WindowProxy)}
55
+ control_proxies.find {|c| c.is_a?(Glimmer::LibUI::WindowProxy)}
56
56
  end
57
57
 
58
58
  def integer_to_boolean(int)
@@ -64,7 +64,15 @@ module Glimmer
64
64
  end
65
65
 
66
66
  def menu_proxies
67
- all_control_proxies.select {|c| c.keyword == 'menu' }
67
+ control_proxies.select {|c| c.keyword == 'menu' }
68
+ end
69
+
70
+ def image_proxies
71
+ control_proxies.select {|c| c.keyword == 'image' }
72
+ end
73
+
74
+ def new_control(keyword, args)
75
+ ::LibUI.send("new_#{keyword}", *args)
68
76
  end
69
77
  end
70
78
 
@@ -216,7 +224,7 @@ module Glimmer
216
224
 
217
225
  def default_destroy
218
226
  send_to_libui('destroy')
219
- ControlProxy.all_control_proxies.delete(self)
227
+ ControlProxy.control_proxies.delete(self)
220
228
  end
221
229
 
222
230
  def enabled(value = nil)
@@ -254,7 +262,7 @@ module Glimmer
254
262
 
255
263
  def build_control
256
264
  @libui = if ::LibUI.respond_to?("new_#{keyword}")
257
- ::LibUI.send("new_#{@keyword}", *@args)
265
+ ControlProxy.new_control(@keyword, @args)
258
266
  elsif ::LibUI.respond_to?(keyword)
259
267
  @args[0] = @args.first.libui if @args.first.is_a?(ControlProxy)
260
268
  ::LibUI.send(@keyword, *@args)
@@ -39,7 +39,7 @@ module Glimmer
39
39
 
40
40
  def destroy_child(child)
41
41
  ::LibUI.send("form_delete", @libui, children.index(child))
42
- ControlProxy.all_control_proxies.delete(child)
42
+ ControlProxy.control_proxies.delete(child)
43
43
  end
44
44
 
45
45
  private
@@ -27,6 +27,8 @@ module Glimmer
27
27
  #
28
28
  # Follows the Proxy Design Pattern
29
29
  class GroupProxy < ControlProxy
30
+ DEFAULT_TITLE = ''
31
+
30
32
  def post_initialize_child(child)
31
33
  ::LibUI.group_set_child(@libui, child.libui)
32
34
  end
@@ -39,7 +41,10 @@ module Glimmer
39
41
  private
40
42
 
41
43
  def build_control
42
- super.tap do
44
+ construction_args = @args.dup
45
+ construction_args[0] = DEFAULT_TITLE if construction_args.size == 0
46
+ @libui = ControlProxy.new_control(@keyword, construction_args)
47
+ @libui.tap do
43
48
  self.margined = true
44
49
  end
45
50
  end
@@ -0,0 +1,41 @@
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/control_proxy'
23
+ require 'glimmer/libui/column'
24
+
25
+ module Glimmer
26
+ module LibUI
27
+ # Proxy for LibUI image column objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class ImageColumnProxy < ControlProxy
31
+ include Column
32
+
33
+ private
34
+
35
+ def build_control
36
+ @parent_proxy.append_image_column(name, next_column_index)
37
+ super
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,37 @@
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/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI image part objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class ImagePartProxy < ControlProxy
30
+ private
31
+
32
+ def build_control
33
+ @libui = @parent_proxy.append(*@args)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,41 @@
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/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI label objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class LabelProxy < ControlProxy
30
+ DEFAULT_TEXT = ''
31
+
32
+ private
33
+
34
+ def build_control
35
+ construction_args = @args.dup
36
+ construction_args[0] = DEFAULT_TEXT if construction_args.size == 0
37
+ @libui = ControlProxy.new_control(@keyword, construction_args)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
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/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI menu objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class MenuProxy < ControlProxy
30
+ DEFAULT_TEXT = ''
31
+
32
+ private
33
+
34
+ def build_control
35
+ construction_args = @args.dup
36
+ construction_args[0] = DEFAULT_TEXT if construction_args.size == 0
37
+ @libui = ControlProxy.new_control(@keyword, construction_args)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,138 @@
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/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI table objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class TableProxy < ControlProxy
30
+ attr_reader :model_handler, :model, :table_params, :columns
31
+
32
+ def initialize(keyword, parent, args, &block)
33
+ @keyword = keyword
34
+ @parent_proxy = parent
35
+ @args = args
36
+ @block = block
37
+ @enabled = true
38
+ @columns = []
39
+ @cell_rows = []
40
+ window_proxy.on_destroy do
41
+ # the following unless condition is an exceptional condition stumbled upon that fails freeing the table model
42
+ ::LibUI.free_table_model(@model) unless @destroyed && parent_proxy.is_a?(Glimmer::LibUI::Box)
43
+ end
44
+ end
45
+
46
+ def post_add_content
47
+ build_control
48
+ super
49
+ end
50
+
51
+ def post_initialize_child(child)
52
+ @columns << child
53
+ end
54
+
55
+ def destroy
56
+ super
57
+ @destroyed = true
58
+ end
59
+
60
+ def cell_rows(rows = nil)
61
+ if rows.nil?
62
+ @cell_rows
63
+ else
64
+ rows = rows.map {|row| row.map {|cell| cell.respond_to?(:libui) ? cell.libui : cell }}
65
+ @cell_rows = rows
66
+ end
67
+ end
68
+ alias cell_rows= cell_rows
69
+ alias set_cell_rows cell_rows
70
+
71
+ def editable(value = nil)
72
+ if value.nil?
73
+ @editable
74
+ else
75
+ @editable = !!value
76
+ end
77
+ end
78
+ alias editable= editable
79
+ alias set_editable editable
80
+ alias editable? editable
81
+
82
+ private
83
+
84
+ def build_control
85
+ @model_handler = ::LibUI::FFI::TableModelHandler.malloc
86
+ @model_handler.NumColumns = rbcallback(4) { @columns.count }
87
+ @model_handler.ColumnType = rbcallback(4) do
88
+ # Note: this assumes all columns are the same type
89
+ # TODO support different values per different columns
90
+ case @columns.first
91
+ when TextColumnProxy
92
+ 0
93
+ when ImageColumnProxy
94
+ 1
95
+ end
96
+ end
97
+ @model_handler.NumRows = rbcallback(4) { cell_rows.count }
98
+ @model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
99
+ case @columns[column]
100
+ when TextColumnProxy
101
+ ::LibUI.new_table_value_string((@cell_rows[row] && @cell_rows[row][column]).to_s)
102
+ when ImageColumnProxy
103
+ ::LibUI.new_table_value_image((@cell_rows[row] && @cell_rows[row][column]))
104
+ end
105
+ end
106
+ @model_handler.SetCellValue = rbcallback(0, [1, 1, 4, 4, 1]) do |_, _, row, column, val|
107
+ case @columns[column]
108
+ when TextColumnProxy
109
+ @cell_rows[row] ||= []
110
+ @cell_rows[row][column] = ::LibUI.table_value_string(val).to_s
111
+ end
112
+ end
113
+
114
+ @model = ::LibUI.new_table_model(@model_handler)
115
+
116
+ @table_params = ::LibUI::FFI::TableParams.malloc
117
+ @table_params.Model = @model
118
+ @table_params.RowBackgroundColorModelColumn = -1
119
+
120
+ @libui = ControlProxy.new_control(@keyword, [@table_params])
121
+ @libui.tap do
122
+ @columns.each {|column| column.send(:build_control) }
123
+ end
124
+ end
125
+
126
+ def rbcallback(*args, &block)
127
+ # TODO consider moving to a more general reusable location in the future (e.g. when used with `AreaProxy`)
128
+ # Protects BlockCaller objects from garbage collection.
129
+ @blockcaller ||= []
130
+ args << [0] if args.size == 1 # Argument types are ommited
131
+ blockcaller = Fiddle::Closure::BlockCaller.new(*args, &block)
132
+ @blockcaller << blockcaller
133
+ blockcaller
134
+ end
135
+
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,41 @@
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/control_proxy'
23
+ require 'glimmer/libui/column'
24
+
25
+ module Glimmer
26
+ module LibUI
27
+ # Proxy for LibUI text column objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class TextColumnProxy < ControlProxy
31
+ include Column
32
+
33
+ private
34
+
35
+ def build_control
36
+ @parent_proxy.append_text_column(name, next_column_index, @parent_proxy.editable? ? -2 : -1)
37
+ super
38
+ end
39
+ end
40
+ end
41
+ end
@@ -27,7 +27,7 @@ module Glimmer
27
27
  #
28
28
  # Follows the Proxy Design Pattern
29
29
  class WindowProxy < ControlProxy
30
- DEFAULT_TITLE = 'Glimmer'
30
+ DEFAULT_TITLE = ''
31
31
  DEFAULT_WIDTH = 150
32
32
  DEFAULT_HEIGHT = 150
33
33
  DEFAULT_HAS_MENUBAR = 1
@@ -40,6 +40,17 @@ module Glimmer
40
40
  ::LibUI.send("window_set_child", @libui, nil)
41
41
  super
42
42
  end
43
+
44
+ def destroy
45
+ super
46
+ ControlProxy.image_proxies.each { |image_proxy| ::LibUI.free_image(image_proxy.libui) }
47
+ @on_destroy_procs&.each { |on_destroy_proc| on_destroy_proc.call(self)}
48
+ end
49
+
50
+ def on_destroy(&block)
51
+ @on_destroy_procs ||= []
52
+ @on_destroy_procs << block
53
+ end
43
54
 
44
55
  def show
45
56
  super
@@ -79,7 +90,7 @@ module Glimmer
79
90
  construction_args[2] = DEFAULT_HEIGHT if construction_args.size == 2
80
91
  construction_args[3] = DEFAULT_HAS_MENUBAR if construction_args.size == 3
81
92
  construction_args[3] = ControlProxy.boolean_to_integer(construction_args[3]) if construction_args.size == 4 && (construction_args[3].is_a?(TrueClass) || construction_args[3].is_a?(FalseClass))
82
- @libui = ::LibUI.send("new_window", *construction_args)
93
+ @libui = ControlProxy.new_control(@keyword, construction_args)
83
94
  @libui.tap do
84
95
  handle_listener('on_closing') do
85
96
  destroy