class Glimmer::LibUI::AttributedString

Attributes

args[R]
block[RW]
content_added[R]
content_added?[R]
keyword[R]
parent_proxy[R]

Public Class Methods

new(keyword, parent_proxy, args, &block) click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 36
def initialize(keyword, parent_proxy, args, &block)
  @keyword = keyword
  @parent_proxy = parent_proxy
  @args = args
  @string = @args.first || ''
  @block = block
  post_add_content if @block.nil?
end

Public Instance Methods

area_proxy() click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 213
def area_proxy
  @parent_proxy.parent_proxy
end
background(value = nil) click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 78
def background(value = nil)
  if value.nil?
    @background
  else
    @background = Glimmer::LibUI.interpret_color(value)
    request_auto_redraw
  end
end
Also aliased as: background=, set_background
background=(value = nil)
Alias for: background
color(value = nil) click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 67
def color(value = nil)
  if value.nil?
    @color
  else
    @color = Glimmer::LibUI.interpret_color(value)
    request_auto_redraw
  end
end
Also aliased as: color=, set_color
color=(value = nil)
Alias for: color
content(&block) click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 217
def content(&block)
  Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::StringExpression.new, @keyword, {post_add_content: true}, &block)
end
destroy() click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 199
def destroy
  return if ControlProxy.main_window_proxy&.destroying?
  open_type_features.destroy unless open_type_features.nil?
  @parent_proxy&.children&.delete(self)
end
draw(area_draw_params) click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 145
def draw(area_draw_params)
  @start = ::LibUI.attributed_string_len(@parent_proxy.attributed_string)
  ::LibUI.attributed_string_append_unattributed(@parent_proxy.attributed_string, @string)
  unless color.nil?
    color_attribute = ::LibUI.new_color_attribute(@color[:r].to_f / 255.0, @color[:g].to_f / 255.0, @color[:b].to_f / 255.0, @color[:a] || 1.0)
    ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, color_attribute, @start, @start + @string.size)
  end
  unless background.nil?
    background_attribute = ::LibUI.new_background_attribute(@background[:r].to_f / 255.0, @background[:g].to_f / 255.0, @background[:b].to_f / 255.0, @background[:a] || 1.0)
    ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, background_attribute, @start, @start + @string.size)
  end
  unless underline.nil?
    underline_attribute = ::LibUI.new_underline_attribute(Glimmer::LibUI.enum_symbol_to_value(:underline, @underline))
    ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, underline_attribute, @start, @start + @string.size)
  end
  unless underline_color.nil?
    if Glimmer::LibUI.enum_symbols(:underline_color).include?(underline_color.to_s.to_sym) && underline_color.to_s.to_sym != :custom
      underline_color_attribute = ::LibUI.new_underline_color_attribute(Glimmer::LibUI.enum_symbol_to_value(:underline_color, @underline_color), 0, 0, 0, 0)
      ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, underline_color_attribute, @start, @start + @string.size)
    else
      the_color = Glimmer::LibUI.interpret_color(@underline_color)
      underline_color_attribute = ::LibUI.new_underline_color_attribute(0, the_color[:r].to_f / 255.0, the_color[:g].to_f / 255.0, the_color[:b].to_f / 255.0, the_color[:a] || 1.0)
      ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, underline_color_attribute, @start, @start + @string.size)
    end
  end
  unless font.nil?
    if font[:family]
      family_attribute = ::LibUI.new_family_attribute(font[:family])
      ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, family_attribute, @start, @start + @string.size)
    end
    if font[:size]
      size_attribute = ::LibUI.new_size_attribute(font[:size])
      ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, size_attribute, @start, @start + @string.size)
    end
    if font[:weight]
      weight_attribute = ::LibUI.new_weight_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_weight, font[:weight]))
      ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, weight_attribute, @start, @start + @string.size)
    end
    if font[:italic]
      italic_attribute = ::LibUI.new_italic_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_italic, font[:italic]))
      ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, italic_attribute, @start, @start + @string.size)
    end
    if font[:stretch]
      stretch_attribute = ::LibUI.new_stretch_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_stretch, font[:stretch]))
      ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, stretch_attribute, @start, @start + @string.size)
    end
  end
  unless open_type_features.nil?
    open_type_features_attribute = ::LibUI.new_features_attribute(open_type_features.libui)
    ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, open_type_features_attribute, @start, @start + @string.size)
  end
  destroy if area_proxy.nil?
end
font(value = nil) click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 56
def font(value = nil)
  if value.nil?
    @font
  else
    @font = value
    request_auto_redraw
  end
end
Also aliased as: font=, set_font
font=(value = nil)
Alias for: font
open_type_features(value = nil) click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 111
def open_type_features(value = nil)
  if value.nil?
    @open_type_features
  else
    @open_type_features = value
    request_auto_redraw
  end
end
open_type_features=(value = nil)
Alias for: open_type_features
post_add_content(block = nil) click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 131
def post_add_content(block = nil)
  block ||= @block
  block_result = block&.call
  unless @content_added
    @string = block_result if block_result.is_a?(String)
    @parent_proxy&.post_initialize_child(self)
    @content_added = true
  end
end
post_initialize_child(child) click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 141
def post_initialize_child(child)
  self.open_type_features = child if child.is_a?(Glimmer::LibUI::ControlProxy::OpenTypeFeaturesProxy)
end
redraw() click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 205
def redraw
  area_proxy&.redraw
end
remove_open_type_features() click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 122
def remove_open_type_features
  return if @removing_open_type_features
  @removing_open_type_features = true
  @open_type_features&.destroy
  @open_type_features = nil
  request_auto_redraw
  @removing_open_type_features = false
end
request_auto_redraw() click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 209
def request_auto_redraw
  area_proxy&.request_auto_redraw
end
set_background(value = nil)
Alias for: background
set_color(value = nil)
Alias for: color
set_font(value = nil)
Alias for: font
set_open_type_features(value = nil)
Alias for: open_type_features
set_string(value = nil)
Alias for: string
set_underline(value = nil)
Alias for: underline
set_underline_color(value = nil)
Alias for: underline_color
string(value = nil) click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 45
def string(value = nil)
  if value.nil?
    @string
  else
    @string = value
    request_auto_redraw
  end
end
Also aliased as: string=, set_string
string=(value = nil)
Alias for: string
underline(value = nil) click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 89
def underline(value = nil)
  if value.nil?
    @underline
  else
    @underline = value
    request_auto_redraw
  end
end
Also aliased as: underline=, set_underline
underline=(value = nil)
Alias for: underline
underline_color(value = nil) click to toggle source
# File lib/glimmer/libui/attributed_string.rb, line 100
def underline_color(value = nil)
  if value.nil?
    @underline_color
  else
    @underline_color = value
    request_auto_redraw
  end
end
underline_color=(value = nil)
Alias for: underline_color