glimmer-dsl-libui 0.1.2 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +55 -0
  3. data/README.md +1127 -65
  4. data/VERSION +1 -1
  5. data/examples/area_gallery.rb +50 -0
  6. data/examples/area_gallery2.rb +111 -0
  7. data/examples/area_gallery3.rb +52 -0
  8. data/examples/area_gallery4.rb +113 -0
  9. data/examples/basic_area2.rb +1 -1
  10. data/examples/basic_button.rb +2 -2
  11. data/examples/basic_entry.rb +2 -2
  12. data/examples/basic_table_progress_bar.rb +13 -3
  13. data/examples/basic_transform.rb +27 -0
  14. data/examples/control_gallery.rb +3 -3
  15. data/examples/dynamic_area.rb +1 -1
  16. data/examples/form.rb +2 -2
  17. data/examples/histogram.rb +118 -0
  18. data/examples/meta_example.rb +71 -20
  19. data/examples/midi_player.rb +8 -10
  20. data/glimmer-dsl-libui.gemspec +0 -0
  21. data/lib/glimmer/dsl/libui/control_expression.rb +1 -3
  22. data/lib/glimmer/dsl/libui/dsl.rb +1 -0
  23. data/lib/glimmer/dsl/libui/file_expression.rb +5 -1
  24. data/lib/glimmer/dsl/libui/property_expression.rb +5 -1
  25. data/lib/glimmer/{libui/box.rb → dsl/libui/shape_expression.rb} +26 -29
  26. data/lib/glimmer/dsl/libui/tab_item_expression.rb +2 -2
  27. data/lib/glimmer/libui/control_proxy/area_proxy.rb +117 -0
  28. data/lib/glimmer/libui/{menu_item_proxy.rb → control_proxy/box/horizontal_box_proxy.rb} +9 -12
  29. data/lib/glimmer/libui/{vertical_box_proxy.rb → control_proxy/box/vertical_box_proxy.rb} +10 -6
  30. data/lib/glimmer/libui/control_proxy/box.rb +61 -0
  31. data/lib/glimmer/libui/{button_proxy.rb → control_proxy/button_proxy.rb} +14 -12
  32. data/lib/glimmer/libui/{checkbox_proxy.rb → control_proxy/checkbox_proxy.rb} +14 -12
  33. data/lib/glimmer/libui/control_proxy/color_button_proxy.rb +118 -0
  34. data/lib/glimmer/libui/control_proxy/column/button_column_proxy.rb +76 -0
  35. data/lib/glimmer/libui/control_proxy/column/checkbox_column_proxy.rb +46 -0
  36. data/lib/glimmer/libui/control_proxy/column/checkbox_text_column_proxy.rb +80 -0
  37. data/lib/glimmer/libui/{radio_buttons_proxy.rb → control_proxy/column/image_column_proxy.rb} +14 -13
  38. data/lib/glimmer/libui/control_proxy/column/image_text_column_proxy.rb +48 -0
  39. data/lib/glimmer/libui/{progress_bar_column_proxy.rb → control_proxy/column/progress_bar_column_proxy.rb} +14 -10
  40. data/lib/glimmer/libui/control_proxy/column/text_column_proxy.rb +46 -0
  41. data/lib/glimmer/libui/control_proxy/column.rb +55 -0
  42. data/lib/glimmer/libui/{checkbox_column_proxy.rb → control_proxy/combobox_proxy.rb} +16 -13
  43. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy/date_picker_proxy.rb +43 -0
  44. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy/time_picker_proxy.rb +43 -0
  45. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy.rb +72 -0
  46. data/lib/glimmer/libui/control_proxy/dual_column.rb +40 -0
  47. data/lib/glimmer/libui/control_proxy/editable_column.rb +46 -0
  48. data/lib/glimmer/libui/control_proxy/editable_combobox_proxy.rb +45 -0
  49. data/lib/glimmer/libui/{dual_column.rb → control_proxy/enableable_column.rb} +18 -10
  50. data/lib/glimmer/libui/control_proxy/font_button_proxy.rb +70 -0
  51. data/lib/glimmer/libui/{form_proxy.rb → control_proxy/form_proxy.rb} +26 -24
  52. data/lib/glimmer/libui/{grid_proxy.rb → control_proxy/grid_proxy.rb} +29 -27
  53. data/lib/glimmer/libui/{group_proxy.rb → control_proxy/group_proxy.rb} +24 -22
  54. data/lib/glimmer/libui/{image_part_proxy.rb → control_proxy/image_part_proxy.rb} +20 -18
  55. data/lib/glimmer/libui/{image_proxy.rb → control_proxy/image_proxy.rb} +32 -30
  56. data/lib/glimmer/libui/{combobox_proxy.rb → control_proxy/label_proxy.rb} +13 -13
  57. data/lib/glimmer/libui/control_proxy/matrix_proxy.rb +147 -0
  58. data/lib/glimmer/libui/{editable_column.rb → control_proxy/menu_item_proxy/about_menu_item_proxy.rb} +13 -16
  59. data/lib/glimmer/libui/control_proxy/menu_item_proxy/check_menu_item_proxy.rb +41 -0
  60. data/lib/glimmer/libui/{preferences_menu_item_proxy.rb → control_proxy/menu_item_proxy/preferences_menu_item_proxy.rb} +11 -9
  61. data/lib/glimmer/libui/control_proxy/menu_item_proxy/quit_menu_item_proxy.rb +66 -0
  62. data/lib/glimmer/libui/control_proxy/menu_item_proxy/separator_menu_item_proxy.rb +41 -0
  63. data/lib/glimmer/libui/control_proxy/menu_item_proxy.rb +45 -0
  64. data/lib/glimmer/libui/{editable_combobox_proxy.rb → control_proxy/menu_proxy.rb} +13 -13
  65. data/lib/glimmer/libui/{horizontal_box_proxy.rb → control_proxy/message_box/msg_box_error_proxy.rb} +9 -6
  66. data/lib/glimmer/libui/{multiline_entry_proxy.rb → control_proxy/message_box/msg_box_proxy.rb} +8 -6
  67. data/lib/glimmer/libui/{check_menu_item_proxy.rb → control_proxy/message_box.rb} +11 -10
  68. data/lib/glimmer/libui/control_proxy/multiline_entry_proxy/non_wrapping_multiline_entry_proxy.rb +34 -0
  69. data/lib/glimmer/libui/{image_column_proxy.rb → control_proxy/multiline_entry_proxy.rb} +10 -11
  70. data/lib/glimmer/libui/control_proxy/path_proxy.rb +169 -0
  71. data/lib/glimmer/libui/control_proxy/radio_buttons_proxy.rb +45 -0
  72. data/lib/glimmer/libui/{button_column_proxy.rb → control_proxy/tab_item_proxy.rb} +37 -40
  73. data/lib/glimmer/libui/control_proxy/table_proxy.rb +182 -0
  74. data/lib/glimmer/libui/control_proxy/transformable.rb +74 -0
  75. data/lib/glimmer/libui/control_proxy/window_proxy.rb +128 -0
  76. data/lib/glimmer/libui/control_proxy.rb +41 -22
  77. data/lib/glimmer/libui/{enableable_column.rb → parent.rb} +7 -15
  78. data/lib/glimmer/libui/shape/arc.rb +43 -0
  79. data/lib/glimmer/libui/{date_picker_proxy.rb → shape/bezier.rb} +8 -9
  80. data/lib/glimmer/libui/{quit_menu_item_proxy.rb → shape/figure.rb} +24 -32
  81. data/lib/glimmer/libui/{non_wrapping_multiline_entry_proxy.rb → shape/line.rb} +11 -5
  82. data/lib/glimmer/libui/{time_picker_proxy.rb → shape/rectangle.rb} +8 -9
  83. data/lib/glimmer/libui/{about_menu_item_proxy.rb → shape/square.rb} +9 -8
  84. data/lib/glimmer/libui/shape.rb +145 -0
  85. data/lib/glimmer/libui.rb +92 -0
  86. data/lib/glimmer-dsl-libui.rb +2 -0
  87. metadata +82 -48
  88. data/lib/glimmer/libui/area_proxy.rb +0 -105
  89. data/lib/glimmer/libui/checkbox_text_column_proxy.rb +0 -76
  90. data/lib/glimmer/libui/color_button_proxy.rb +0 -64
  91. data/lib/glimmer/libui/column.rb +0 -51
  92. data/lib/glimmer/libui/date_time_picker_proxy.rb +0 -68
  93. data/lib/glimmer/libui/font_button_proxy.rb +0 -68
  94. data/lib/glimmer/libui/image_text_column_proxy.rb +0 -44
  95. data/lib/glimmer/libui/label_proxy.rb +0 -41
  96. data/lib/glimmer/libui/menu_proxy.rb +0 -41
  97. data/lib/glimmer/libui/path_proxy.rb +0 -167
  98. data/lib/glimmer/libui/rectangle_proxy.rb +0 -100
  99. data/lib/glimmer/libui/separator_menu_item_proxy.rb +0 -37
  100. data/lib/glimmer/libui/tab_item_proxy.rb +0 -67
  101. data/lib/glimmer/libui/table_proxy.rb +0 -180
  102. data/lib/glimmer/libui/text_column_proxy.rb +0 -42
  103. data/lib/glimmer/libui/window_proxy.rb +0 -119
@@ -1,41 +0,0 @@
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
@@ -1,41 +0,0 @@
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
@@ -1,167 +0,0 @@
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 path objects
27
- #
28
- # Follows the Proxy Design Pattern
29
- class PathProxy < ControlProxy
30
- # TODO support mode without parent proxy
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 post_initialize_child(child)
41
- super
42
- children << child
43
- end
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
-
53
- def children
54
- @children ||= []
55
- end
56
-
57
- def draw(area_draw_params)
58
- build_control
59
- children.each {|child| child.draw(area_draw_params)}
60
- ::LibUI.draw_path_end(@libui)
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?
63
- ::LibUI.draw_free_path(@libui)
64
- end
65
-
66
- def draw_fill_mode
67
- @args[0].is_a?(Integer) ? @args[0] : @args[0].to_s == 'alternate' ? 1 : 0
68
- end
69
-
70
- def fill(args = nil)
71
- if args.nil?
72
- @fill ||= {}
73
- else
74
- @fill = args
75
- @parent_proxy&.queue_redraw_all
76
- end
77
- @fill.tap do
78
- @fill_observer ||= Glimmer::DataBinding::Observer.proc do
79
- @parent_proxy&.queue_redraw_all
80
- end
81
- @fill_observer.observe(@fill)
82
- end
83
- end
84
- alias fill= fill
85
- alias set_fill fill
86
-
87
- def fill_draw_brush
88
- @fill_draw_brush ||= ::LibUI::FFI::DrawBrush.malloc
89
- init_draw_brush(@fill_draw_brush, @fill)
90
- @fill_draw_brush
91
- end
92
-
93
- def stroke(args = nil)
94
- if args.nil?
95
- @stroke ||= {}
96
- else
97
- @stroke = args
98
- @parent_proxy&.queue_redraw_all
99
- end
100
- @stroke.tap do
101
- @stroke_observer ||= Glimmer::DataBinding::Observer.proc do
102
- @parent_proxy&.queue_redraw_all
103
- end
104
- @stroke_observer.observe(@stroke)
105
- end
106
- end
107
- alias stroke= stroke
108
- alias set_stroke stroke
109
-
110
- def stroke_draw_brush
111
- @stroke_draw_brush ||= ::LibUI::FFI::DrawBrush.malloc
112
- init_draw_brush(@stroke_draw_brush, @stroke)
113
- @stroke_draw_brush
114
- end
115
-
116
- def draw_stroke_params
117
- @draw_stroke_params ||= ::LibUI::FFI::DrawStrokeParams.malloc
118
- @draw_stroke_params.Cap = @stroke[:cap] || 0 # flat
119
- @draw_stroke_params.Join = @stroke[:join] || 0 # miter
120
- @draw_stroke_params.Thickness = @stroke[:thickness] || 1
121
- @draw_stroke_params.MiterLimit = @stroke[:miter_limit] || 10 # DEFAULT_MITER_LIMIT
122
- @draw_stroke_params_dashes ||= Fiddle::Pointer.malloc(8)
123
- @draw_stroke_params.Dashes = @draw_stroke_params_dashes
124
- @draw_stroke_params.NumDashes = @stroke[:num_dashes] || 0 # TODO reimplement this line correctly (perhaps no need to pass num dashes, yet dashes themselves and use their count here)
125
- @draw_stroke_params.DashPhase = @stroke[:dash_phase] || 0
126
- @draw_stroke_params
127
- end
128
-
129
- # returns area_draw_params if built inside on_draw listener (not needed if declared outside)
130
- def area_draw_params
131
- @args[0] if @parent_proxy.nil?
132
- end
133
-
134
- def destroy
135
- @parent_proxy.children.delete(self) unless @parent_proxy.nil?
136
- ControlProxy.control_proxies.delete(self)
137
- end
138
-
139
- private
140
-
141
- def build_control
142
- @libui = ::LibUI.draw_new_path(draw_fill_mode)
143
- end
144
-
145
- def init_draw_brush(draw_brush, draw_brush_args)
146
- case draw_brush_args[:type]
147
- when Integer
148
- draw_brush.Type = draw_brush_args[:type]
149
- when :solid, 'solid'
150
- draw_brush.Type = 0
151
- when :linear_gradient, 'linear_gradient'
152
- draw_brush.Type = 1
153
- when :radial_gradient, 'radial_gradient'
154
- draw_brush.Type = 2
155
- when :image, 'image'
156
- draw_brush.Type = 3
157
- else
158
- draw_brush.Type = 0
159
- end
160
- draw_brush.R = (draw_brush_args[:r] || draw_brush_args[:red]).to_f / 255.0
161
- draw_brush.G = (draw_brush_args[:g] || draw_brush_args[:green]).to_f / 255.0
162
- draw_brush.B = (draw_brush_args[:b] || draw_brush_args[:blue]).to_f / 255.0
163
- draw_brush.A = (draw_brush_args[:a] || draw_brush_args[:alpha])
164
- end
165
- end
166
- end
167
- end
@@ -1,100 +0,0 @@
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 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
-
39
- def draw(area_draw_params)
40
- ::LibUI.draw_path_add_rectangle(@parent_proxy.libui, *@args)
41
- destroy if @parent_proxy.parent_proxy.nil?
42
- end
43
-
44
- def destroy
45
- @parent_proxy.children.delete(self) unless @parent_proxy.nil?
46
- ControlProxy.control_proxies.delete(self)
47
- end
48
-
49
- def x(value = nil)
50
- if value.nil?
51
- @args[0]
52
- else
53
- @args[0] = value
54
- @parent_proxy.parent_proxy&.queue_redraw_all
55
- end
56
- end
57
- alias x= x
58
- alias set_x x
59
-
60
- def y(value = nil)
61
- if value.nil?
62
- @args[1]
63
- else
64
- @args[1] = value
65
- @parent_proxy.parent_proxy&.queue_redraw_all
66
- end
67
- end
68
- alias y= y
69
- alias set_y y
70
-
71
- def width(value = nil)
72
- if value.nil?
73
- @args[2]
74
- else
75
- @args[2] = value
76
- @parent_proxy.parent_proxy&.queue_redraw_all
77
- end
78
- end
79
- alias width= width
80
- alias set_width width
81
-
82
- def height(value = nil)
83
- if value.nil?
84
- @args[3]
85
- else
86
- @args[3] = value
87
- @parent_proxy.parent_proxy&.queue_redraw_all
88
- end
89
- end
90
- alias height= height
91
- alias set_height height
92
-
93
- private
94
-
95
- def build_control
96
- # No Op
97
- end
98
- end
99
- end
100
- end
@@ -1,37 +0,0 @@
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/menu_item_proxy'
23
-
24
- module Glimmer
25
- module LibUI
26
- # Proxy for LibUI separator menu item object
27
- #
28
- # Follows the Proxy Design Pattern
29
- class SeparatorMenuItemProxy < MenuItemProxy
30
- private
31
-
32
- def build_control
33
- @libui = @parent_proxy.append_separator(*@args)
34
- end
35
- end
36
- end
37
- end
@@ -1,67 +0,0 @@
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/horizontal_box_proxy'
24
-
25
- module Glimmer
26
- module LibUI
27
- # Proxy for LibUI tab item objects
28
- #
29
- # Follows the Proxy Design Pattern
30
- class TabItemProxy < ControlProxy
31
- attr_reader :index
32
-
33
- def initialize(keyword, parent, args, &block)
34
- @keyword = keyword
35
- @parent_proxy = parent
36
- @args = args
37
- @block = block
38
- @enabled = 1
39
- @index = @parent_proxy.num_pages
40
- @content = @block&.call
41
- build_control
42
- end
43
-
44
- def name
45
- @args.first
46
- end
47
-
48
- def margined(value = nil)
49
- if value.nil?
50
- @parent_proxy.margined(@index)
51
- else
52
- @parent_proxy.margined(@index, value)
53
- end
54
- end
55
- alias set_margined margined
56
- alias margined= margined
57
- alias margined? margined
58
-
59
- private
60
-
61
- def build_control
62
- @content = HorizontalBoxProxy.new('horizontal_box', @libui, []) if @content.nil?
63
- @libui = @parent_proxy.append(name, @content.libui)
64
- end
65
- end
66
- end
67
- end
@@ -1,180 +0,0 @@
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/data_binding/observer'
24
- require 'glimmer/fiddle_consumer'
25
-
26
- using ArrayIncludeMethods
27
-
28
- module Glimmer
29
- module LibUI
30
- # Proxy for LibUI table objects
31
- #
32
- # Follows the Proxy Design Pattern
33
- class TableProxy < ControlProxy
34
- include Glimmer::FiddleConsumer
35
-
36
- attr_reader :model_handler, :model, :table_params, :columns
37
-
38
- def initialize(keyword, parent, args, &block)
39
- @keyword = keyword
40
- @parent_proxy = parent
41
- @args = args
42
- @block = block
43
- @enabled = true
44
- @columns = []
45
- @cell_rows = []
46
- window_proxy.on_destroy do
47
- # the following unless condition is an exceptional condition stumbled upon that fails freeing the table model
48
- ::LibUI.free_table_model(@model) unless @destroyed && parent_proxy.is_a?(Glimmer::LibUI::Box)
49
- end
50
- end
51
-
52
- def post_add_content
53
- build_control
54
- super
55
- end
56
-
57
- def post_initialize_child(child)
58
- @columns << child
59
- # add an extra complementary nil column if it is a dual column (i.e. ImageTextColumnProxy or CheckboxTextColumnProxy
60
- @columns << nil if child.is_a?(DualColumn)
61
- end
62
-
63
- def destroy
64
- super
65
- @destroyed = true
66
- end
67
-
68
- def cell_rows(rows = nil)
69
- if rows.nil?
70
- @cell_rows
71
- else
72
- @cell_rows = rows
73
- @cell_rows.tap do
74
- @last_cell_rows = @cell_rows.clone
75
- Glimmer::DataBinding::Observer.proc do
76
- if @cell_rows.size < @last_cell_rows.size && @last_cell_rows.include_all?(*@cell_rows)
77
- @last_cell_rows.array_diff_indexes(@cell_rows).reverse.each do |row|
78
- ::LibUI.table_model_row_deleted(model, row)
79
- end
80
- elsif @cell_rows.size > @last_cell_rows.size && @cell_rows.include_all?(*@last_cell_rows)
81
- @cell_rows.array_diff_indexes(@last_cell_rows).each do |row|
82
- ::LibUI.table_model_row_inserted(model, row)
83
- end
84
- else
85
- @cell_rows.each_with_index do |new_row_data, row|
86
- ::LibUI.table_model_row_changed(model, row) if new_row_data != @last_cell_rows[row]
87
- end
88
- end
89
- @last_cell_rows = @cell_rows.clone
90
- end.observe(self, :cell_rows)
91
- end
92
- end
93
- end
94
- alias cell_rows= cell_rows
95
- alias set_cell_rows cell_rows
96
-
97
- def expanded_cell_rows
98
- cell_rows.map do |row|
99
- row.flatten(1)
100
- end
101
- end
102
-
103
- def editable(value = nil)
104
- if value.nil?
105
- @editable
106
- else
107
- @editable = !!value
108
- end
109
- end
110
- alias editable= editable
111
- alias set_editable editable
112
- alias editable? editable
113
-
114
- private
115
-
116
- def build_control
117
- @model_handler = ::LibUI::FFI::TableModelHandler.malloc
118
- @model_handler.NumColumns = fiddle_closure_block_caller(4) { @columns.map {|c| c.is_a?(DualColumn) ? 2 : 1}.sum }
119
- @model_handler.ColumnType = fiddle_closure_block_caller(4, [1, 1, 4]) do |_, _, column|
120
- case @columns[column]
121
- when TextColumnProxy, ButtonColumnProxy, NilClass
122
- 0
123
- when ImageColumnProxy, ImageTextColumnProxy
124
- 1
125
- when CheckboxColumnProxy, CheckboxTextColumnProxy, ProgressBarColumnProxy
126
- 2
127
- end
128
- end
129
- @model_handler.NumRows = fiddle_closure_block_caller(4) { cell_rows.count }
130
- @model_handler.CellValue = fiddle_closure_block_caller(1, [1, 1, 4, 4]) do |_, _, row, column|
131
- the_cell_rows = expanded_cell_rows
132
- case @columns[column]
133
- when TextColumnProxy, ButtonColumnProxy, NilClass
134
- ::LibUI.new_table_value_string((expanded_cell_rows[row] && expanded_cell_rows[row][column]).to_s)
135
- when ImageColumnProxy, ImageTextColumnProxy
136
- ::LibUI.new_table_value_image((expanded_cell_rows[row] && (expanded_cell_rows[row][column].respond_to?(:libui) ? expanded_cell_rows[row][column].libui : expanded_cell_rows[row][column])))
137
- when CheckboxColumnProxy, CheckboxTextColumnProxy
138
- ::LibUI.new_table_value_int((expanded_cell_rows[row] && (expanded_cell_rows[row][column] == 1 || expanded_cell_rows[row][column].to_s.strip.downcase == 'true' ? 1 : 0)))
139
- when ProgressBarColumnProxy
140
- ::LibUI.new_table_value_int((expanded_cell_rows[row] && (expanded_cell_rows[row][column].to_i)))
141
- end
142
- end
143
- @model_handler.SetCellValue = fiddle_closure_block_caller(0, [1, 1, 4, 4, 1]) do |_, _, row, column, val|
144
- case @columns[column]
145
- when TextColumnProxy
146
- column = @columns[column].index
147
- @cell_rows[row] ||= []
148
- @cell_rows[row][column] = ::LibUI.table_value_string(val).to_s
149
- when NilClass
150
- column = @columns[column - 1].index
151
- @cell_rows[row][column][1] = ::LibUI.table_value_string(val).to_s
152
- when ButtonColumnProxy
153
- @columns[column].notify_listeners(:on_clicked, row)
154
- when CheckboxColumnProxy, CheckboxTextColumnProxy
155
- column = @columns[column].index
156
- @cell_rows[row] ||= []
157
- @cell_rows[row][column] = ::LibUI.table_value_int(val).to_i == 1
158
- end
159
- end
160
-
161
- @model = ::LibUI.new_table_model(@model_handler)
162
-
163
- @table_params = ::LibUI::FFI::TableParams.malloc
164
- @table_params.Model = @model
165
- @table_params.RowBackgroundColorModelColumn = -1
166
-
167
- @libui = ControlProxy.new_control(@keyword, [@table_params])
168
- @libui.tap do
169
- @columns.each {|column| column&.send(:build_control) }
170
- end
171
- end
172
-
173
- def next_column_index
174
- @next_column_index ||= -1
175
- @next_column_index += 1
176
- end
177
-
178
- end
179
- end
180
- end
@@ -1,42 +0,0 @@
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
- require 'glimmer/libui/editable_column'
25
-
26
- module Glimmer
27
- module LibUI
28
- # Proxy for LibUI text column objects
29
- #
30
- # Follows the Proxy Design Pattern
31
- class TextColumnProxy < ControlProxy
32
- include Column
33
- include EditableColumn
34
-
35
- private
36
-
37
- def build_control
38
- @parent_proxy.append_text_column(name, column_index, editable_value)
39
- end
40
- end
41
- end
42
- end