glimmer-dsl-libui 0.0.14 → 0.0.18

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/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,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/libui/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Common logic for all column proxy objects
27
+ module Column
28
+ def initialize(keyword, parent, args, &block)
29
+ @keyword = keyword
30
+ @parent_proxy = parent
31
+ @args = args
32
+ @block = block
33
+ @enabled = true
34
+ post_add_content if @block.nil?
35
+ end
36
+
37
+ def name
38
+ @args.first
39
+ end
40
+ end
41
+ end
42
+ 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)
@@ -0,0 +1,54 @@
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
+ class FormProxy < ControlProxy
27
+ APPEND_PROPERTIES = %w[label stretchy]
28
+
29
+ def post_initialize_child(child)
30
+ child.label = '' if child.label.nil?
31
+ child.stretchy = true if child.stretchy.nil?
32
+ ::LibUI.form_append(@libui, child.label, child.libui, ControlProxy.boolean_to_integer(child.stretchy))
33
+ children << child
34
+ end
35
+
36
+ def children
37
+ @children ||= []
38
+ end
39
+
40
+ def destroy_child(child)
41
+ ::LibUI.send("form_delete", @libui, children.index(child))
42
+ ControlProxy.control_proxies.delete(child)
43
+ end
44
+
45
+ private
46
+
47
+ def build_control
48
+ super.tap do
49
+ self.padded = true
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -36,6 +36,11 @@ module Glimmer
36
36
  child.vexpand = false if child.vexpand.nil?
37
37
  child.valign = 0 if child.valign.nil?
38
38
  ::LibUI.grid_append(@libui, child.libui, child.left, child.top, child.xspan, child.yspan, ControlProxy.boolean_to_integer(child.hexpand), child.halign, ControlProxy.boolean_to_integer(child.vexpand), child.valign)
39
+ children << child
40
+ end
41
+
42
+ def children
43
+ @children ||= []
39
44
  end
40
45
 
41
46
  # Note that there is no proper destroy_child(child) method for GridProxy due to libui not offering any API for it (no grid_delete)
@@ -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,40 @@
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
+ @libui = @parent_proxy.append_image_column(name, @parent_proxy.columns.map(&:libui).compact.count)
37
+ end
38
+ end
39
+ end
40
+ 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,119 @@
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
+ private
72
+
73
+ def build_control
74
+ @model_handler = ::LibUI::FFI::TableModelHandler.malloc
75
+ @model_handler.NumColumns = rbcallback(4) { @columns.count }
76
+ @model_handler.ColumnType = rbcallback(4) do
77
+ # TODO support different values for different columns
78
+ case @columns.first
79
+ when TextColumnProxy
80
+ 0
81
+ when ImageColumnProxy
82
+ 1
83
+ end
84
+ end
85
+ @model_handler.NumRows = rbcallback(4) { cell_rows.count }
86
+ @model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
87
+ case @columns[column]
88
+ when TextColumnProxy
89
+ ::LibUI.new_table_value_string((@cell_rows[row] && @cell_rows[row][column]).to_s)
90
+ when ImageColumnProxy
91
+ ::LibUI.new_table_value_image((@cell_rows[row] && @cell_rows[row][column]))
92
+ end
93
+ end
94
+
95
+ @model = ::LibUI.new_table_model(@model_handler)
96
+
97
+ @table_params = ::LibUI::FFI::TableParams.malloc
98
+ @table_params.Model = @model
99
+ @table_params.RowBackgroundColorModelColumn = -1
100
+
101
+ @libui = ControlProxy.new_control(@keyword, [@table_params])
102
+ @libui.tap do
103
+ @columns.each {|column| column.send(:build_control) }
104
+ end
105
+ end
106
+
107
+ def rbcallback(*args, &block)
108
+ # TODO consider moving to a more general reusable location in the future (e.g. when used with `AreaProxy`)
109
+ # Protects BlockCaller objects from garbage collection.
110
+ @blockcaller ||= []
111
+ args << [0] if args.size == 1 # Argument types are ommited
112
+ blockcaller = Fiddle::Closure::BlockCaller.new(*args, &block)
113
+ @blockcaller << blockcaller
114
+ blockcaller
115
+ end
116
+
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,40 @@
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
+ @libui = @parent_proxy.append_text_column(name, @parent_proxy.columns.map(&:libui).compact.count, -1) # -1 for non-editable for now until editing is supported
37
+ end
38
+ end
39
+ end
40
+ 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