AttributedText

Text with styles.

Header#include "nativeui/gfx/attributed_text.h"
Namespacenamespace nu
Typeclass (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

AttributedText(const std::string& text, TextAttributes attributes)

Create an AttributedText with attributes.

Parameters

Methods

void SetFormat(TextFormat format)

Overwrite styles with format.

Parameters

const TextFormat& GetFormat() const

Return current styles.

Return

const TextFormat&

void SetFont(scoped_refptr<Font> font)

Set the whole text's font.

Parameters

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

void SetColor(Color color)

Set the whole text's color.

Parameters

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

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

Return

RectF

void SetText(const std::string& text)

Change the text content.

Parameters

std::string GetText() const

Return the plain text.

Return

std::string

NativeAttributedText GetNative() const

Return the native instance wrapped by the class.

Return

NativeAttributedText