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, #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_aliases, #custom_listeners, #default_destroy, descendant_keyword_constant_map, #destroy_child, #enabled, exists?, #handle_custom_listener, #handle_listener, #has_custom_listener?, image_proxies, keyword, #libui_api_keyword, main_window_proxy, map_descendant_keyword_constants_for, menu_proxies, #method_missing, new_control, #post_initialize_child, reset_descendant_keyword_constant_map, #respond_to?, #respond_to_libui?, #send_to_libui, #visible, widget_proxy_class, #window_proxy
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
137
138
139
140
141
142
143
144
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 137
def align(value = nil)
if value.nil?
@align
else
@align = value
redraw
end
end
|
#attributed_string ⇒ Object
102
103
104
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 102
def attributed_string
@attributed_string ||= reset_attributed_string
end
|
#default_font(value = nil) ⇒ Object
Also known as:
default_font=, set_default_font
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 110
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
127
128
129
130
131
132
133
134
135
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 127
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
|
#destroy ⇒ Object
62
63
64
65
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 62
def destroy
@parent_proxy&.children&.delete(self)
ControlProxy.control_proxies.delete(self)
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
148
149
150
151
152
153
154
155
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 148
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
67
68
69
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 67
def redraw
@parent_proxy&.queue_redraw_all
end
|
#reset_attributed_string ⇒ Object
106
107
108
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 106
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
71
72
73
74
75
76
77
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 71
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
81
82
83
84
85
86
87
|
# File 'lib/glimmer/libui/control_proxy/text_proxy.rb', line 81
def y(value = nil)
if value.nil?
@y ||= args[1] || 0
else
@y = value
end
end
|