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, #keyword, #libui, #parent_proxy
Instance Method Summary
collapse
Methods included from Parent
#children, #post_initialize_child
#apply_transform, #post_initialize_child, #transform, #undo_transform
#append_properties, #append_property, #can_handle_listener?, constant_symbol, #content, control_proxies, 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, #handle_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, widget_proxy_class, #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.
37
38
39
40
41
42
43
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 37
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
139
140
141
142
143
144
145
146
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 139
def align(value = nil)
if value.nil?
@align
else
@align = value
redraw
end
end
|
#attributed_string ⇒ Object
104
105
106
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 104
def attributed_string
@attributed_string ||= reset_attributed_string
end
|
#default_font(value = nil) ⇒ Object
Also known as:
default_font=, set_default_font
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 112
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
129
130
131
132
133
134
135
136
137
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 129
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
53
54
55
56
57
58
59
60
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 53
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
150
151
152
153
154
155
156
157
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 150
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
|
#post_add_content ⇒ Object
#redraw ⇒ Object
69
70
71
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 69
def redraw
@parent_proxy&.queue_redraw_all
end
|
#reset_attributed_string ⇒ Object
108
109
110
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 108
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
73
74
75
76
77
78
79
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 73
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
83
84
85
86
87
88
89
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 83
def y(value = nil)
if value.nil?
@y ||= args[1] || 0
else
@y = value
end
end
|