Class: Glimmer::LibUI::AttributedString
- Inherits:
-
Object
- Object
- Glimmer::LibUI::AttributedString
- Includes:
- DataBindable
- Defined in:
- lib/glimmer/libui/attributed_string.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#block ⇒ Object
Returns the value of attribute block.
-
#content_added ⇒ Object
(also: #content_added?)
readonly
Returns the value of attribute content_added.
-
#keyword ⇒ Object
readonly
Returns the value of attribute keyword.
-
#parent_proxy ⇒ Object
readonly
Returns the value of attribute parent_proxy.
Instance Method Summary collapse
- #area_proxy ⇒ Object
- #background(value = nil) ⇒ Object (also: #background=, #set_background)
- #color(value = nil) ⇒ Object (also: #color=, #set_color)
- #content(&block) ⇒ Object
- #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.
- #open_type_features(value = nil) ⇒ Object (also: #open_type_features=, #set_open_type_features)
- #post_add_content(block = nil) ⇒ Object
- #post_initialize_child(child) ⇒ Object
- #redraw ⇒ Object
- #remove_open_type_features ⇒ Object
- #request_auto_redraw ⇒ Object
- #string(value = nil) ⇒ Object (also: #string=, #set_string)
- #underline(value = nil) ⇒ Object (also: #underline=, #set_underline)
- #underline_color(value = nil) ⇒ Object (also: #underline_color=, #set_underline_color)
Methods included from DataBindable
#data_bind, #data_bind_read, #data_bind_write, #data_binding_model_attribute_observer_registrations
Constructor Details
#initialize(keyword, parent_proxy, args, &block) ⇒ AttributedString
Returns a new instance of AttributedString.
36 37 38 39 40 41 42 43 |
# 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 |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
32 33 34 |
# File 'lib/glimmer/libui/attributed_string.rb', line 32 def args @args end |
#block ⇒ Object
Returns the value of attribute block.
33 34 35 |
# File 'lib/glimmer/libui/attributed_string.rb', line 33 def block @block end |
#content_added ⇒ Object (readonly) Also known as: content_added?
Returns the value of attribute content_added.
32 33 34 |
# File 'lib/glimmer/libui/attributed_string.rb', line 32 def content_added @content_added end |
#keyword ⇒ Object (readonly)
Returns the value of attribute keyword.
32 33 34 |
# File 'lib/glimmer/libui/attributed_string.rb', line 32 def keyword @keyword end |
#parent_proxy ⇒ Object (readonly)
Returns the value of attribute parent_proxy.
32 33 34 |
# File 'lib/glimmer/libui/attributed_string.rb', line 32 def parent_proxy @parent_proxy end |
Instance Method Details
#area_proxy ⇒ Object
213 214 215 |
# File 'lib/glimmer/libui/attributed_string.rb', line 213 def area_proxy @parent_proxy.parent_proxy end |
#background(value = nil) ⇒ Object Also known as: background=, set_background
78 79 80 81 82 83 84 85 |
# 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 |
#color(value = nil) ⇒ Object Also known as: color=, set_color
67 68 69 70 71 72 73 74 |
# 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 |
#content(&block) ⇒ Object
217 218 219 |
# 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 ⇒ Object
199 200 201 202 203 |
# File 'lib/glimmer/libui/attributed_string.rb', line 199 def destroy return if ControlProxy.main_window_proxy&. open_type_features.destroy unless open_type_features.nil? @parent_proxy&.children&.delete(self) end |
#draw(area_draw_params) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# 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.bytesize) 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.bytesize) 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.bytesize) 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.bytesize) 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.bytesize) 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.bytesize) 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.bytesize) 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.bytesize) 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.bytesize) 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.bytesize) 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.bytesize) end destroy if area_proxy.nil? end |
#font(value = nil) ⇒ Object Also known as: font=, set_font
56 57 58 59 60 61 62 63 |
# 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 |
#open_type_features(value = nil) ⇒ Object Also known as: open_type_features=, set_open_type_features
111 112 113 114 115 116 117 118 |
# 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 |
#post_add_content(block = nil) ⇒ Object
131 132 133 134 135 136 137 138 139 |
# 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) ⇒ Object
141 142 143 |
# 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 ⇒ Object
205 206 207 |
# File 'lib/glimmer/libui/attributed_string.rb', line 205 def redraw area_proxy&.redraw end |
#remove_open_type_features ⇒ Object
122 123 124 125 126 127 128 129 |
# 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 ⇒ Object
209 210 211 |
# File 'lib/glimmer/libui/attributed_string.rb', line 209 def request_auto_redraw area_proxy&.request_auto_redraw end |
#string(value = nil) ⇒ Object Also known as: string=, set_string
45 46 47 48 49 50 51 52 |
# 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 |
#underline(value = nil) ⇒ Object Also known as: underline=, set_underline
89 90 91 92 93 94 95 96 |
# 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 |
#underline_color(value = nil) ⇒ Object Also known as: underline_color=, set_underline_color
100 101 102 103 104 105 106 107 |
# 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 |