AttributedText
Text with styles.
| Header | #include "nativeui/gfx/attributed_text.h" |
| Namespace | namespace nu |
| Type | class (RefCounted) |
On Windows, due to the limitations of GdiPlus, it is only supported to change
the whole text's color and font, i.e. the SetFontFor and SetColorFor APIs
are unsupported.
Constructors
AttributedText(const std::string& text, TextFormat format)
Create an AttributedText with format and default font and color.
Parameters
const std::string&textTextFormatformat
AttributedText(const std::string& text, TextAttributes attributes)
Create an AttributedText with attributes.
Parameters
const std::string&textTextAttributesattributes
Methods
void SetFormat(TextFormat format)
Overwrite styles with format.
Parameters
TextFormatformat
const TextFormat& GetFormat() const
Return current styles.
Return
const TextFormat&void SetFont(scoped_refptr<Font> font)
Set the whole text's font.
Parameters
scoped_refptr<Font>font
void SetFontFor(scoped_refptr<Font> font, int start, int end) macOS Linux
Set the font of text between character range [start, end). Passing
-1 as end means the rest of the text.
Parameters
scoped_refptr<Font>fontintstartintend
void SetColor(Color color)
Set the whole text's color.
Parameters
Colorcolor
void SetColorFor(Color font, int start, int end) macOS Linux
Set the color of text between character range [start, end). Passing
-1 as end means the rest of the text.
Parameters
Colorfontintstartintend
void Clear()
Reset font and color to system default.
RectF GetBoundsFor(const SizeF& size) const
Return the bounds required to draw the text within size.
Parameters
const SizeF&size
Return
RectFvoid SetText(const std::string& text)
Change the text content.
Parameters
const std::string&text
std::string GetText() const
Return the plain text.
Return
std::stringNativeAttributedText GetNative() const
Return the native instance wrapped by the class.
Return
NativeAttributedText