glimmer-dsl-libui 0.2.2 → 0.2.6

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.
@@ -34,9 +34,9 @@ module Glimmer
34
34
  {
35
35
  family: @font_descriptor.Family.to_s,
36
36
  size: @font_descriptor.Size,
37
- weight: @font_descriptor.Weight,
38
- italic: @font_descriptor.Italic,
39
- stretch: @font_descriptor.Stretch
37
+ weight: Glimmer::LibUI.enum_value_to_symbol(:text_weight, @font_descriptor.Weight),
38
+ italic: Glimmer::LibUI.enum_value_to_symbol(:text_italic, @font_descriptor.Italic),
39
+ stretch: Glimmer::LibUI.enum_value_to_symbol(:text_stretch, @font_descriptor.Stretch),
40
40
  }
41
41
  end
42
42
 
@@ -0,0 +1,53 @@
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/control_proxy/area_proxy'
24
+ require 'glimmer/libui/parent'
25
+
26
+ module Glimmer
27
+ module LibUI
28
+ class ControlProxy
29
+ # Proxy for LibUI open type features objects
30
+ #
31
+ # Follows the Proxy Design Pattern
32
+ class OpenTypeFeaturesProxy < ControlProxy
33
+ include Parent
34
+
35
+ def destroy
36
+ ::LibUI.free_open_type_features(@libui)
37
+ @parent_proxy&.children&.delete(self)
38
+ ControlProxy.control_proxies.delete(self)
39
+ end
40
+
41
+ def redraw
42
+ @parent_proxy.redraw
43
+ end
44
+
45
+ private
46
+
47
+ def build_control
48
+ @libui = ::LibUI.new_open_type_features
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,59 @@
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/control_proxy/area_proxy'
24
+ require 'glimmer/libui/parent'
25
+
26
+ module Glimmer
27
+ module LibUI
28
+ class ControlProxy
29
+ # Proxy for LibUI open type tag objects
30
+ #
31
+ # Follows the Proxy Design Pattern
32
+ class OpenTypeTagProxy < ControlProxy
33
+ def destroy
34
+ @parent_proxy&.children&.delete(self)
35
+ ControlProxy.control_proxies.delete(self)
36
+ end
37
+
38
+ def redraw
39
+ @parent_proxy.redraw
40
+ end
41
+
42
+ private
43
+
44
+ def build_control
45
+ tag_args = @args.dup
46
+ tag_args[0] = ordinalize(tag_args[0])
47
+ tag_args[1] = ordinalize(tag_args[1])
48
+ tag_args[2] = ordinalize(tag_args[2])
49
+ tag_args[3] = ordinalize(tag_args[3])
50
+ ::LibUI.open_type_features_add(@parent_proxy.libui, *tag_args)
51
+ end
52
+
53
+ def ordinalize(arg)
54
+ arg.is_a?(String) ? arg.ord : arg
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -34,13 +34,11 @@ module Glimmer
34
34
  include Parent
35
35
  prepend Transformable
36
36
 
37
- # TODO support mode without parent proxy
38
37
  def initialize(keyword, parent, args, &block)
39
38
  @keyword = keyword
40
39
  @parent_proxy = parent
41
40
  @args = args
42
41
  @block = block
43
- @enabled = true
44
42
  post_add_content if @block.nil?
45
43
  end
46
44
 
@@ -0,0 +1,173 @@
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/control_proxy/area_proxy'
24
+ require 'glimmer/libui/parent'
25
+ require 'glimmer/libui/control_proxy/transformable'
26
+
27
+ module Glimmer
28
+ module LibUI
29
+ class ControlProxy
30
+ # Proxy for LibUI text objects
31
+ #
32
+ # Follows the Proxy Design Pattern
33
+ class TextProxy < ControlProxy
34
+ include Parent
35
+ prepend Transformable
36
+
37
+ def initialize(keyword, parent, args, &block)
38
+ @keyword = keyword
39
+ @parent_proxy = parent
40
+ @args = args
41
+ @block = block
42
+ post_add_content if @block.nil?
43
+ end
44
+
45
+ def post_add_content
46
+ super
47
+ if @parent_proxy.nil? && AreaProxy.current_area_draw_params
48
+ draw(AreaProxy.current_area_draw_params)
49
+ destroy
50
+ end
51
+ end
52
+
53
+ def draw(area_draw_params)
54
+ reset_attributed_string
55
+ children.dup.each {|child| child.draw(area_draw_params)}
56
+ build_control
57
+ ::LibUI.draw_text(area_draw_params[:context], @libui, x, y)
58
+ ::LibUI.draw_free_text_layout(@libui)
59
+ ::LibUI.free_attributed_string(@attributed_string)
60
+ end
61
+
62
+ def destroy
63
+ @parent_proxy&.children&.delete(self)
64
+ ControlProxy.control_proxies.delete(self)
65
+ end
66
+
67
+ def redraw
68
+ @parent_proxy&.queue_redraw_all
69
+ end
70
+
71
+ def x(value = nil)
72
+ if value.nil?
73
+ @x ||= args[0] || 0
74
+ else
75
+ @x = value
76
+ end
77
+ end
78
+ alias x= x
79
+ alias set_x x
80
+
81
+ def y(value = nil)
82
+ if value.nil?
83
+ @y ||= args[1] || 0
84
+ else
85
+ @y = value
86
+ end
87
+ end
88
+ alias y= y
89
+ alias set_y y
90
+
91
+ def width(value = nil)
92
+ if value.nil?
93
+ @width ||= args[2] || (AreaProxy.current_area_draw_params && AreaProxy.current_area_draw_params[:area_width])
94
+ else
95
+ @width = value
96
+ redraw
97
+ end
98
+ end
99
+ alias width= width
100
+ alias set_width width
101
+
102
+ def attributed_string
103
+ @attributed_string ||= reset_attributed_string
104
+ end
105
+
106
+ def reset_attributed_string
107
+ @attributed_string = ::LibUI.new_attributed_string('')
108
+ end
109
+
110
+ def default_font(value = nil)
111
+ if value.nil?
112
+ @default_font ||= {
113
+ family: 'Helvetica',
114
+ size: 12.0,
115
+ weight: :normal,
116
+ italic: :normal,
117
+ stretch: :normal,
118
+ }
119
+ else
120
+ @default_font = value
121
+ redraw
122
+ end
123
+ end
124
+ alias default_font= default_font
125
+ alias set_default_font default_font
126
+
127
+ def default_font_descriptor
128
+ @default_font_descriptor ||= ::LibUI::FFI::FontDescriptor.malloc
129
+ @default_font_descriptor.Family = default_font[:family] || 'Helvetica'
130
+ @default_font_descriptor.Size = default_font[:size] || 12.0
131
+ @default_font_descriptor.Weight = Glimmer::LibUI.enum_symbol_to_value(:text_weight, default_font[:weight], default_symbol: :normal)
132
+ @default_font_descriptor.Italic = Glimmer::LibUI.enum_symbol_to_value(:text_italic, default_font[:italic], default_symbol: :normal)
133
+ @default_font_descriptor.Stretch = Glimmer::LibUI.enum_symbol_to_value(:text_stretch, default_font[:stretch], default_symbol: :normal)
134
+ @default_font_descriptor
135
+ end
136
+
137
+ def align(value = nil)
138
+ if value.nil?
139
+ @align
140
+ else
141
+ @align = value
142
+ redraw
143
+ end
144
+ end
145
+ alias align= align
146
+ alias set_align align
147
+
148
+ def draw_text_layout_params
149
+ @draw_text_layout_params ||= ::LibUI::FFI::DrawTextLayoutParams.malloc
150
+ @draw_text_layout_params.String = attributed_string
151
+ @draw_text_layout_params.DefaultFont = default_font_descriptor
152
+ @draw_text_layout_params.Width = width
153
+ @draw_text_layout_params.Align = Glimmer::LibUI.enum_symbol_to_value(:draw_text_align, align, default_symbol: :left)
154
+ @draw_text_layout_params
155
+ end
156
+
157
+ private
158
+
159
+ def build_control
160
+ @libui = ::LibUI.draw_new_text_layout(draw_text_layout_params)
161
+ end
162
+
163
+ def init_draw_brush(draw_brush, draw_brush_args)
164
+ draw_brush.Type = Glimmer::LibUI.enum_symbol_to_value(:draw_brush_type, draw_brush_args[:type])
165
+ draw_brush.R = (draw_brush_args[:r] || draw_brush_args[:red]).to_f / 255.0
166
+ draw_brush.G = (draw_brush_args[:g] || draw_brush_args[:green]).to_f / 255.0
167
+ draw_brush.B = (draw_brush_args[:b] || draw_brush_args[:blue]).to_f / 255.0
168
+ draw_brush.A = (draw_brush_args[:a] || draw_brush_args[:alpha])
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
data/lib/glimmer/libui.rb CHANGED
@@ -96,18 +96,28 @@ module Glimmer
96
96
  value
97
97
  end
98
98
 
99
- # Returns ruby underscored symbols for enum values starting with enum name (camelcase, e.g. 'ext_key')
100
99
  def enum_symbols(enum_name)
100
+ enum_symbol_values(enum_name).keys
101
+ end
102
+
103
+ # Returns ruby underscored symbols for enum values starting with enum name (camelcase, e.g. 'ext_key')
104
+ def enum_symbol_values(enum_name)
101
105
  enum_name = enum_name.to_s.underscore.to_sym
102
106
  @enum_symbols ||= {}
103
- @enum_symbols[enum_name] ||= ::LibUI.constants.select { |c| c.to_s.start_with?(enum_name.to_s.camelcase(:upper)) }.map { |c| c.to_s.underscore.sub("#{enum_name}_", '').to_sym }
107
+ @enum_symbols[enum_name] ||= ::LibUI.constants.select { |c| c.to_s.start_with?(enum_name.to_s.camelcase(:upper)) }.map { |c| [c.to_s.underscore.sub("#{enum_name}_", '').to_sym, ::LibUI.const_get(c)] }.to_h
108
+ end
109
+
110
+ def enum_value_to_symbol(enum_name, enum_value)
111
+ enum_symbol_values(enum_name).invert[enum_value]
104
112
  end
105
113
 
106
- def enum_symbol_to_value(enum_name, enum_symbol, default_index: 0)
114
+ def enum_symbol_to_value(enum_name, enum_symbol, default_symbol: nil, default_index: 0)
107
115
  if enum_symbol.is_a?(Integer)
108
116
  enum_symbol
109
117
  elsif enum_symbols(enum_name).include?(enum_symbol.to_s.to_sym)
110
- ::LibUI.const_get("#{enum_name}_#{enum_symbol}".camelcase(:upper))
118
+ enum_symbol_values(enum_name)[enum_symbol.to_s.to_sym]
119
+ elsif default_symbol
120
+ enum_symbol_to_value(enum_name, default_symbol)
111
121
  else
112
122
  enum_symbol_to_value(enum_name, enum_symbols(enum_name)[default_index])
113
123
  end
@@ -130,7 +140,7 @@ module Glimmer
130
140
 
131
141
  # Calls block on the main GUI event loop after time_in_seconds delay, repeating indefinitely by default
132
142
  # If `repeat:` keyword arg is passed with an Integer value, it repeats for that number of times
133
- # If `repeat:` keyword arg is passed with false or 0, then the block is only called onces
143
+ # If `repeat:` keyword arg is passed with false or 0, then the block is only called once
134
144
  # If block returns false at any point, the timer is stopped from further repetitions regardless of `repeat:` keyword arg value
135
145
  # If block returns true at any point, the timer continues for another repetition regardless of `repeat:` keyword arg value
136
146
  def timer(time_in_seconds = 0.1, repeat: true, &block)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-05 00:00:00.000000000 Z
11
+ date: 2021-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -215,6 +215,8 @@ files:
215
215
  - examples/basic_area.rb
216
216
  - examples/basic_area2.rb
217
217
  - examples/basic_button.rb
218
+ - examples/basic_draw_text.rb
219
+ - examples/basic_draw_text2.rb
218
220
  - examples/basic_entry.rb
219
221
  - examples/basic_table.rb
220
222
  - examples/basic_table_button.rb
@@ -229,6 +231,8 @@ files:
229
231
  - examples/color_button.rb
230
232
  - examples/color_the_circles.rb
231
233
  - examples/control_gallery.rb
234
+ - examples/custom_draw_text.rb
235
+ - examples/custom_draw_text2.rb
232
236
  - examples/date_time_picker.rb
233
237
  - examples/dynamic_area.rb
234
238
  - examples/dynamic_area2.rb
@@ -254,9 +258,11 @@ files:
254
258
  - lib/glimmer/dsl/libui/property_expression.rb
255
259
  - lib/glimmer/dsl/libui/save_file_expression.rb
256
260
  - lib/glimmer/dsl/libui/shape_expression.rb
261
+ - lib/glimmer/dsl/libui/string_expression.rb
257
262
  - lib/glimmer/dsl/libui/tab_item_expression.rb
258
263
  - lib/glimmer/fiddle_consumer.rb
259
264
  - lib/glimmer/libui.rb
265
+ - lib/glimmer/libui/attributed_string.rb
260
266
  - lib/glimmer/libui/control_proxy.rb
261
267
  - lib/glimmer/libui/control_proxy/area_proxy.rb
262
268
  - lib/glimmer/libui/control_proxy/area_proxy/scrolling_area_proxy.rb
@@ -306,10 +312,13 @@ files:
306
312
  - lib/glimmer/libui/control_proxy/message_box/msg_box_proxy.rb
307
313
  - lib/glimmer/libui/control_proxy/multiline_entry_proxy.rb
308
314
  - lib/glimmer/libui/control_proxy/multiline_entry_proxy/non_wrapping_multiline_entry_proxy.rb
315
+ - lib/glimmer/libui/control_proxy/open_type_features_proxy.rb
316
+ - lib/glimmer/libui/control_proxy/open_type_tag_proxy.rb
309
317
  - lib/glimmer/libui/control_proxy/path_proxy.rb
310
318
  - lib/glimmer/libui/control_proxy/radio_buttons_proxy.rb
311
319
  - lib/glimmer/libui/control_proxy/tab_item_proxy.rb
312
320
  - lib/glimmer/libui/control_proxy/table_proxy.rb
321
+ - lib/glimmer/libui/control_proxy/text_proxy.rb
313
322
  - lib/glimmer/libui/control_proxy/transformable.rb
314
323
  - lib/glimmer/libui/control_proxy/window_proxy.rb
315
324
  - lib/glimmer/libui/parent.rb