psychic-ui 0.0.0
Loading...
Searching...
No Matches
psychic_ui::TextLayout Class Reference

#include <TextLayout.hpp>

Public Member Functions

void setText (const icu::UnicodeString &text)
bool setStyle (const TextLayoutStyle &style)
const TextLayoutStyle & style () const
void setMultiline (bool multiline)
float maxContentWidth ()
size_t lineCountAt (float width)
void layout (float width)
void paint (SkCanvas *canvas, float x, float y, SkColor color)
void paintSelection (SkCanvas *canvas, float x, float y, unsigned int begin, unsigned int end, SkColor background, SkColor foreground)
SkRect caretRect (unsigned int index)
unsigned int indexAt (float x, float y)
float fittingWidth (float width)

Static Public Member Functions

static std::size_t paragraphsBuilt ()

Detailed Description

Lays out text with SkParagraph: shaping, font fallback, line breaking and alignment, and the geometry editing needs (caret rectangles and hit testing; TextEditing has the rest). Every index is in UTF-16 code units, like icu::UnicodeString's.

Every line is lineHeight tall, its glyphs centred in it (CSS's half-leading). One-line layouts never wrap: their text overflows the width instead, or ends in an ellipsis that fits (TextOverflow::Ellipsis), and line returns lay out as spaces.

Colors are given when painting, so a color change (a transition) never builds or lays out the paragraph again.

Member Function Documentation

◆ caretRect()

SkRect psychic_ui::TextLayout::caretRect ( unsigned int index)

The caret before the character at the index: a zero-width rectangle across its line

◆ fittingWidth()

float psychic_ui::TextLayout::fittingWidth ( float width)

The x where the visible text ends when it's cut at the width: the end of the last glyph cluster that fits whole

◆ indexAt()

unsigned int psychic_ui::TextLayout::indexAt ( float x,
float y )

The caret index closest to a point

◆ layout()

void psychic_ui::TextLayout::layout ( float width)

Lay the text out at the width of its box

◆ lineCountAt()

size_t psychic_ui::TextLayout::lineCountAt ( float width)

How many lines the text takes at that width, without changing the layout used for painting and the queries below

◆ maxContentWidth()

float psychic_ui::TextLayout::maxContentWidth ( )

The width of the widest line when nothing wraps

◆ paint()

void psychic_ui::TextLayout::paint ( SkCanvas * canvas,
float x,
float y,
SkColor color )

Paint the text in a color with its top left at (x, y)

◆ paintSelection()

void psychic_ui::TextLayout::paintSelection ( SkCanvas * canvas,
float x,
float y,
unsigned int begin,
unsigned int end,
SkColor background,
SkColor foreground )

Paint the selection from begin to end over the text painted at (x, y): its rectangles (a line's height each, in visual order, so bidirectional text gets several) in background, and the text inside them again in foreground

◆ paragraphsBuilt()

std::size_t psychic_ui::TextLayout::paragraphsBuilt ( )
static

How many paragraphs every TextLayout has built so far, for tests of what rebuilds them

◆ setMultiline()

void psychic_ui::TextLayout::setMultiline ( bool multiline)

Whether the text wraps at the width (or stays on one line, past it)

◆ setStyle()

bool psychic_ui::TextLayout::setStyle ( const TextLayoutStyle & style)

Set what the text is laid out with

Returns
Whether that changes it (then its size may have changed too)

◆ setText()

void psychic_ui::TextLayout::setText ( const icu::UnicodeString & text)

Set the text, copied (call again after changing it)


The documentation for this class was generated from the following files: