Class: Glimmer::LibUI::AttributedString

Inherits:
Object
  • Object
show all
Defined in:
lib/glimmer/libui/attributed_string.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword, parent_proxy, args, &block) ⇒ AttributedString

Returns a new instance of AttributedString.



33
34
35
36
37
38
39
40
# File 'lib/glimmer/libui/attributed_string.rb', line 33

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



31
32
33
# File 'lib/glimmer/libui/attributed_string.rb', line 31

def args
  @args
end

#blockObject (readonly)

Returns the value of attribute block.



31
32
33
# File 'lib/glimmer/libui/attributed_string.rb', line 31

def block
  @block
end

#keywordObject (readonly)

Returns the value of attribute keyword.



31
32
33
# File 'lib/glimmer/libui/attributed_string.rb', line 31

def keyword
  @keyword
end

#parent_proxyObject (readonly)

Returns the value of attribute parent_proxy.



31
32
33
# File 'lib/glimmer/libui/attributed_string.rb', line 31

def parent_proxy
  @parent_proxy
end

#stringObject

Returns the value of attribute string.



30
31
32
# File 'lib/glimmer/libui/attributed_string.rb', line 30

def string
  @string
end

Instance Method Details

#area_proxyObject



130
131
132
# File 'lib/glimmer/libui/attributed_string.rb', line 130

def area_proxy
  @parent_proxy.parent_proxy
end

#color(value = nil) ⇒ Object Also known as: color=, set_color



53
54
55
56
57
58
59
60
# File 'lib/glimmer/libui/attributed_string.rb', line 53

def color(value = nil)
  if value.nil?
    @color
  else
    @color = Glimmer::LibUI.interpret_color(value)
    redraw
  end
end

#destroyObject



122
123
124
# File 'lib/glimmer/libui/attributed_string.rb', line 122

def destroy
  @parent_proxy&.children&.delete(self)
end

#draw(area_draw_params) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/glimmer/libui/attributed_string.rb', line 92

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 font.nil?
    family_attribute = ::LibUI.new_family_attribute(font[:family])
    ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, family_attribute, @start, @start + @string.size)
    size_attribute = ::LibUI.new_size_attribute(font[:size])
    ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, size_attribute, @start, @start + @string.size)
    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)
    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)
    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
  destroy if area_proxy.nil?
end

#font(value = nil) ⇒ Object Also known as: font=, set_font



42
43
44
45
46
47
48
49
# File 'lib/glimmer/libui/attributed_string.rb', line 42

def font(value = nil)
  if value.nil?
    @font
  else
    @font = value
    redraw
  end
end

#post_add_contentObject



86
87
88
89
90
# File 'lib/glimmer/libui/attributed_string.rb', line 86

def post_add_content
  block_result = block&.call
  @string = block_result if block_result.is_a?(String)
  @parent_proxy&.post_initialize_child(self)
end

#redrawObject



126
127
128
# File 'lib/glimmer/libui/attributed_string.rb', line 126

def redraw
  area_proxy&.queue_redraw_all
end