Class: Glimmer::LibUI::ControlProxy::TextProxy
Overview
Proxy for LibUI text objects
Follows the Proxy Design Pattern
Constant Summary
BOOLEAN_PROPERTIES, KEYWORD_ALIASES, STRING_PROPERTIES, TransformProxy
Instance Attribute Summary
#args, #block, #content_added, #custom_control, #keyword, #libui, #options, #parent_custom_control, #parent_proxy, #slot
Instance Method Summary
collapse
#bounding_box, #contain?, #include?, #move, #move_by
Methods included from Parent
#children, #post_initialize_child
#apply_transform, #post_initialize_child, #transform, #undo_transform
#append_properties, #append_property, #bind_content, constant_symbol, #content, control_proxies, control_proxy_class, create, #custom_listener_name_aliases, #custom_listener_names, #default_destroy, #deregister_all_custom_listeners, #deregister_custom_listeners, descendant_keyword_constant_map, #destroy_child, #enabled, exists?, #handle_custom_listener, #has_custom_listener?, image_proxies, keyword, #libui_api_keyword, #listeners, #listeners_for, main_window_proxy, map_descendant_keyword_constants_for, menu_proxies, #method_missing, new_control, #notify_custom_listeners, #post_initialize_child, reset_descendant_keyword_constant_map, #respond_to?, #respond_to_libui?, #send_to_libui, #visible, #window_proxy
#data_bind, #data_bind_read, #data_bind_write, #data_binding_model_attribute_observer_registrations
Constructor Details
#initialize(keyword, parent, args, &block) ⇒ TextProxy
Returns a new instance of TextProxy.
38
39
40
41
42
43
44
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 38
def initialize(keyword, parent, args, &block)
@keyword = keyword
@parent_proxy = parent
@args = args
@block = block
post_add_content if @block.nil?
end
|
Instance Method Details
#align(value = nil) ⇒ Object
Also known as:
align=, set_align
140
141
142
143
144
145
146
147
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 140
def align(value = nil)
if value.nil?
@align
else
@align = value
redraw
end
end
|
#area_proxy ⇒ Object
160
161
162
163
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 160
def area_proxy
find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(ControlProxy::AreaProxy) }
end
|
#attributed_string ⇒ Object
105
106
107
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 105
def attributed_string
@attributed_string ||= reset_attributed_string
end
|
#calculate_extents ⇒ Object
224
225
226
227
228
229
230
231
232
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 224
def calculate_extents
extent_width = Fiddle::Pointer.malloc(Fiddle::SIZEOF_DOUBLE*8)
extent_height = Fiddle::Pointer.malloc(Fiddle::SIZEOF_DOUBLE*8)
::LibUI.draw_text_layout_extents(@libui, extent_width, extent_height)
@extent_width = extent_width[0, Fiddle::SIZEOF_DOUBLE*8].unpack1('i')
@extent_height = extent_height[0, Fiddle::SIZEOF_DOUBLE*8].unpack1('i')
end
|
#can_handle_listener?(listener_name) ⇒ Boolean
176
177
178
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 176
def can_handle_listener?(listener_name)
area_proxy&.can_handle_listener?(listener_name)
end
|
#default_font(value = nil) ⇒ Object
Also known as:
default_font=, set_default_font
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 113
def default_font(value = nil)
if value.nil?
@default_font ||= {
family: 'Helvetica',
size: 12.0,
weight: :normal,
italic: :normal,
stretch: :normal,
}
else
@default_font = value
redraw
end
end
|
#default_font_descriptor ⇒ Object
130
131
132
133
134
135
136
137
138
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 130
def default_font_descriptor
@default_font_descriptor ||= ::LibUI::FFI::FontDescriptor.malloc
@default_font_descriptor.Family = default_font[:family] || 'Helvetica'
@default_font_descriptor.Size = default_font[:size] || 12.0
@default_font_descriptor.Weight = Glimmer::LibUI.enum_symbol_to_value(:text_weight, default_font[:weight], default_symbol: :normal)
@default_font_descriptor.Italic = Glimmer::LibUI.enum_symbol_to_value(:text_italic, default_font[:italic], default_symbol: :normal)
@default_font_descriptor.Stretch = Glimmer::LibUI.enum_symbol_to_value(:text_stretch, default_font[:stretch], default_symbol: :normal)
@default_font_descriptor
end
|
#draw(area_draw_params) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 54
def draw(area_draw_params)
reset_attributed_string
children.dup.each {|child| child.draw(area_draw_params)}
build_control
::LibUI.draw_text(area_draw_params[:context], @libui, x, y)
::LibUI.draw_free_text_layout(@libui)
::LibUI.free_attributed_string(@attributed_string)
end
|
#draw_text_layout_params ⇒ Object
151
152
153
154
155
156
157
158
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 151
def draw_text_layout_params
@draw_text_layout_params ||= ::LibUI::FFI::DrawTextLayoutParams.malloc
@draw_text_layout_params.String = attributed_string
@draw_text_layout_params.DefaultFont = default_font_descriptor
@draw_text_layout_params.Width = width
@draw_text_layout_params.Align = Glimmer::LibUI.enum_symbol_to_value(:draw_text_align, align, default_symbol: :left)
@draw_text_layout_params
end
|
#extent_height ⇒ Object
211
212
213
214
215
216
217
218
219
220
221
222
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 211
def extent_height
if @extent_height.to_f > 0
@extent_height
else children_max_size = children.map(&:font).map {|font| font[:size] if font.respond_to?(:[]) }.compact.max
if children_max_size.to_f > 0
children_max_size
else
@default_font[:size]
end
end
end
|
#extent_width ⇒ Object
203
204
205
206
207
208
209
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 203
def extent_width
if @extent_width.to_f > 0
@extent_width
else width
end
end
|
#find_parent_in_ancestors(&condition) ⇒ Object
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 165
def find_parent_in_ancestors(&condition)
found = self
until condition.call(found)
found = found.parent_proxy
end
found
end
|
#handle_listener(listener_name, &listener) ⇒ Object
180
181
182
183
184
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 180
def handle_listener(listener_name, &listener)
area_proxy.handle_listener(listener_name) do |event|
listener.call(event) if include?(event[:x], event[:y])
end
end
|
#perfect_shape ⇒ Object
186
187
188
189
190
191
192
193
194
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 186
def perfect_shape
require 'perfect-shape'
the_perfect_shape_dependencies = perfect_shape_dependencies
if the_perfect_shape_dependencies != @perfect_shape_dependencies
absolute_x, absolute_y, width, height = @perfect_shape_dependencies = the_perfect_shape_dependencies
@perfect_shape = PerfectShape::Rectangle.new(x: absolute_x, y: absolute_y, width: width, height: height)
end
@perfect_shape
end
|
#perfect_shape_dependencies ⇒ Object
196
197
198
199
200
201
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 196
def perfect_shape_dependencies
absolute_x = x
absolute_y = y
[absolute_x, absolute_y, extent_width, extent_height]
end
|
#post_add_content ⇒ Object
#redraw ⇒ Object
70
71
72
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 70
def redraw
@parent_proxy&.queue_redraw_all
end
|
#reset_attributed_string ⇒ Object
109
110
111
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 109
def reset_attributed_string
@attributed_string = ::LibUI.new_attributed_string('')
end
|
#width(value = nil) ⇒ Object
Also known as:
width=, set_width
#x(value = nil) ⇒ Object
Also known as:
x=, set_x
74
75
76
77
78
79
80
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 74
def x(value = nil)
if value.nil?
@x ||= args[0] || 0
else
@x = value
end
end
|
#y(value = nil) ⇒ Object
Also known as:
y=, set_y
84
85
86
87
88
89
90
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 84
def y(value = nil)
if value.nil?
@y ||= args[1] || 0
else
@y = value
end
end
|