Class: Glimmer::LibUI::AttributedString
- Inherits:
-
Object
- Object
- Glimmer::LibUI::AttributedString
- Defined in:
- lib/glimmer/libui/attributed_string.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#keyword ⇒ Object
readonly
Returns the value of attribute keyword.
-
#parent_proxy ⇒ Object
readonly
Returns the value of attribute parent_proxy.
-
#string ⇒ Object
Returns the value of attribute string.
Instance Method Summary collapse
- #area_proxy ⇒ Object
- #background(value = nil) ⇒ Object (also: #background=, #set_background)
- #color(value = nil) ⇒ Object (also: #color=, #set_color)
- #destroy ⇒ Object
- #draw(area_draw_params) ⇒ Object
- #font(value = nil) ⇒ Object (also: #font=, #set_font)
-
#initialize(keyword, parent_proxy, args, &block) ⇒ AttributedString
constructor
A new instance of AttributedString.
- #post_add_content ⇒ Object
- #redraw ⇒ Object
- #underline(value = nil) ⇒ Object (also: #underline=, #set_underline)
- #underline_color(value = nil) ⇒ Object (also: #underline_color=, #set_underline_color)
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
#args ⇒ Object (readonly)
Returns the value of attribute args.
31 32 33 |
# File 'lib/glimmer/libui/attributed_string.rb', line 31 def args @args end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
31 32 33 |
# File 'lib/glimmer/libui/attributed_string.rb', line 31 def block @block end |
#keyword ⇒ Object (readonly)
Returns the value of attribute keyword.
31 32 33 |
# File 'lib/glimmer/libui/attributed_string.rb', line 31 def keyword @keyword end |
#parent_proxy ⇒ Object (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 |
#string ⇒ Object
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_proxy ⇒ Object
151 152 153 |
# File 'lib/glimmer/libui/attributed_string.rb', line 151 def area_proxy @parent_proxy.parent_proxy end |
#background(value = nil) ⇒ Object Also known as: background=, set_background
64 65 66 67 68 69 70 71 |
# File 'lib/glimmer/libui/attributed_string.rb', line 64 def background(value = nil) if value.nil? @background else @background = Glimmer::LibUI.interpret_color(value) redraw end 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 |
#destroy ⇒ Object
143 144 145 |
# File 'lib/glimmer/libui/attributed_string.rb', line 143 def destroy @parent_proxy&.children&.delete(self) end |
#draw(area_draw_params) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/glimmer/libui/attributed_string.rb', line 103 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? 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_content ⇒ Object
97 98 99 100 101 |
# File 'lib/glimmer/libui/attributed_string.rb', line 97 def post_add_content block_result = block&.call @string = block_result if block_result.is_a?(String) @parent_proxy&.post_initialize_child(self) end |
#redraw ⇒ Object
147 148 149 |
# File 'lib/glimmer/libui/attributed_string.rb', line 147 def redraw area_proxy&.queue_redraw_all end |
#underline(value = nil) ⇒ Object Also known as: underline=, set_underline
75 76 77 78 79 80 81 82 |
# File 'lib/glimmer/libui/attributed_string.rb', line 75 def underline(value = nil) if value.nil? @underline else @underline = value redraw end end |
#underline_color(value = nil) ⇒ Object Also known as: underline_color=, set_underline_color
86 87 88 89 90 91 92 93 |
# File 'lib/glimmer/libui/attributed_string.rb', line 86 def underline_color(value = nil) if value.nil? @underline_color else @underline_color = value redraw end end |