class Glimmer::LibUI::ControlProxy::TextProxy

Proxy for LibUI text objects

Follows the Proxy Design Pattern

Constants

A
Align
B
DefaultFont
Family
G
Italic
R
Size
Stretch
String
Type
Weight
Width

Public Class Methods

new(keyword, parent, args, &block) click to toggle source
# 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

Public Instance Methods

align(value = nil) click to toggle source
# 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
Also aliased as: align=, set_align
align=(value = nil)
Alias for: align
attributed_string() click to toggle source
# File lib/glimmer/libui/control_proxy/text_proxy.rb, line 104
def attributed_string
  @attributed_string ||= reset_attributed_string
end
default_font(value = nil) click to toggle source
# 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
Also aliased as: default_font=, set_default_font
default_font=(value = nil)
Alias for: default_font
default_font_descriptor() click to toggle source
# 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
destroy() click to toggle source
# File lib/glimmer/libui/control_proxy/text_proxy.rb, line 62
def destroy
  return if ControlProxy.main_window_proxy&.destroying?
  deregister_all_custom_listeners
  @parent_proxy&.children&.delete(self)
  ControlProxy.control_proxies.delete(self)
end
draw(area_draw_params) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/glimmer/libui/control_proxy/text_proxy.rb, line 45
def post_add_content
  super
  if @parent_proxy.nil? && AreaProxy.current_area_draw_params
    draw(AreaProxy.current_area_draw_params)
    destroy
  end
end
redraw() click to toggle source
# File lib/glimmer/libui/control_proxy/text_proxy.rb, line 69
def redraw
  @parent_proxy&.queue_redraw_all
end
reset_attributed_string() click to toggle source
# File lib/glimmer/libui/control_proxy/text_proxy.rb, line 108
def reset_attributed_string
  @attributed_string = ::LibUI.new_attributed_string('')
end
set_align(value = nil)
Alias for: align
set_default_font(value = nil)
Alias for: default_font
set_width(value = nil)
Alias for: width
set_x(value = nil)
Alias for: x
set_y(value = nil)
Alias for: y
width(value = nil) click to toggle source
# File lib/glimmer/libui/control_proxy/text_proxy.rb, line 93
def width(value = nil)
  if value.nil?
    @width ||= args[2] || (AreaProxy.current_area_draw_params && (AreaProxy.current_area_draw_params[:area_width] - 2*x))
  else
    @width = value
    redraw
  end
end
Also aliased as: width=, set_width
width=(value = nil)
Alias for: width
x(value = nil) click to toggle source
# 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
Also aliased as: x=, set_x
x=(value = nil)
Alias for: x
y(value = nil) click to toggle source
# 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
Also aliased as: y=, set_y
y=(value = nil)
Alias for: y

Private Instance Methods

build_control() click to toggle source
# File lib/glimmer/libui/control_proxy/text_proxy.rb, line 161
def build_control
  @libui = ::LibUI.draw_new_text_layout(draw_text_layout_params)
end
init_draw_brush(draw_brush, draw_brush_args) click to toggle source
# File lib/glimmer/libui/control_proxy/text_proxy.rb, line 165
def init_draw_brush(draw_brush, draw_brush_args)
  draw_brush.Type = Glimmer::LibUI.enum_symbol_to_value(:draw_brush_type, draw_brush_args[:type])
  draw_brush.R = (draw_brush_args[:r] || draw_brush_args[:red]).to_f / 255.0
  draw_brush.G = (draw_brush_args[:g] || draw_brush_args[:green]).to_f / 255.0
  draw_brush.B = (draw_brush_args[:b] || draw_brush_args[:blue]).to_f / 255.0
  draw_brush.A = (draw_brush_args[:a] || draw_brush_args[:alpha])
end