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&
textTextFormat
format
AttributedText(const std::string& text, TextAttributes attributes)
Create an AttributedText
with attributes
.
Parameters
const std::string&
textTextAttributes
attributes
Methods
void SetFormat(TextFormat format)
Overwrite styles with format
.
Parameters
TextFormat
format
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
macOS Linux
void SetFontFor(scoped_refptr<Font> font, int start, int end)Set the font
of text between character range [start, end)
. Passing
-1
as end
means the rest of the text.
Parameters
scoped_refptr<Font>
fontint
startint
end
void SetColor(Color color)
Set the whole text's color
.
Parameters
Color
color
macOS Linux
void SetColorFor(Color font, int start, int end)Set the color
of text between character range [start, end)
. Passing
-1
as end
means the rest of the text.
Parameters
Color
fontint
startint
end
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
RectF
void SetText(const std::string& text)
Change the text content.
Parameters
const std::string&
text
std::string GetText() const
Return the plain text.
Return
std::string
NativeAttributedText GetNative() const
Return the native instance wrapped by the class.
Return
NativeAttributedText