HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Data Fields
tt::ShapedText Class Reference

#include <TTauri/Text/ShapedText.hpp>

Public Types

using iterator
 
using const_iterator
 

Public Member Functions

 ShapedText (ShapedText const &other)=default
 
 ShapedText (ShapedText &&other) noexcept=default
 
ShapedTextoperator= (ShapedText const &other)=default
 
ShapedTextoperator= (ShapedText &&other) noexcept=default
 
 ShapedText (std::vector< AttributedGrapheme > const &text, float width, Alignment const alignment=Alignment::MiddleCenter, bool wrap=true) noexcept
 Create shaped text from attributed text.
 
 ShapedText (gstring const &text, TextStyle const &style, float width, Alignment const alignment=Alignment::MiddleCenter, bool wrap=true) noexcept
 Create shaped text from a string.
 
 ShapedText (std::string_view text, TextStyle const &style, float width, Alignment const alignment=Alignment::MiddleCenter, bool wrap=true) noexcept
 Create shaped text from a string.
 
size_t size () const noexcept
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
float topAccender () const noexcept
 
float bottomDescender () const noexcept
 
float topCapHeight () const noexcept
 
float bottomCapHeight () const noexcept
 
float middleCapHeight () const noexcept
 Get the capHeight of the middle line(s).
 
float baselineOffset (float height) noexcept
 Get the offset of the baseline The offset of the baseline when the text needs to be rendered inside a box of the given height.
 
float middleOffset (float height) const noexcept
 Get the offset of the middle of a line.
 
mat::T2 T (aarect rectangle) noexcept
 Get the translation for where to place the text.
 
mat::T2 TMiddle (vec position) noexcept
 Get the translation for where to place the text.
 
const_iterator find (ssize_t position) const noexcept
 Find a glyph that corresponds to position.
 
aarect rectangleOfGrapheme (ssize_t index) const noexcept
 Get a rectangle for the grapheme.
 
aarect leftToRightCaret (ssize_t index, bool overwrite) const noexcept
 Return the cursor-carets.
 
std::vector< aarectselectionRectangles (ssize_t first, ssize_t last) const noexcept
 Return a list of merged rectangles to display for the selection.
 
std::optional< ssize_tindexOfCharAtCoordinate (vec coordinate) const noexcept
 Return the index of the character .
 
std::optional< ssize_tindexOfCharOnTheLeft (ssize_t logicalIndex) const noexcept
 Return the index of the character to the left.
 
std::optional< ssize_tindexOfCharOnTheRight (ssize_t logicalIndex) const noexcept
 Return the index of the character to the right.
 
std::pair< ssize_t, ssize_tindicesOfWord (ssize_t logicalIndex) const noexcept
 Return the index at the left side and right side of a word.
 
std::pair< ssize_t, ssize_tindicesOfParagraph (ssize_t logicalIndex) const noexcept
 Return the index at the left side and right side of a paragraph.
 
ssize_t indexAtRightSideOfWord (ssize_t logicalIndex) const noexcept
 Return the index at the left side of a word.
 
std::optional< ssize_tindexOfWordOnTheLeft (ssize_t logicalIndex) const noexcept
 Return the index of the word to the left.
 
std::optional< ssize_tindexOfWordOnTheRight (ssize_t logicalIndex) const noexcept
 Return the index of the word to the right.
 
Path get_path () const noexcept
 Convert the whole shaped text into a layered path.
 
int indexFromCoordinate (vec coordinate) const noexcept
 Get the index into the text from a coordinate.
 
std::vector< int > indicesFromCoordinates (vec start, vec current) const noexcept
 Get the index into the text from a coordinate.
 

Data Fields

Alignment alignment
 
aarect boundingBox
 
float width
 
vec preferredExtent
 

Detailed Description

ShapedText represent a piece of text shaped to be displayed.

Member Typedef Documentation

◆ const_iterator

Initial value:
nested_vector_iterator<
std::vector<AttributedGlyphLine>::const_iterator,
std::vector<AttributedGlyphLine>::const_iterator,
AttributedGlyphLine::const_iterator>

◆ iterator

Initial value:
nested_vector_iterator<
std::vector<AttributedGlyphLine>::const_iterator,
std::vector<AttributedGlyphLine>::iterator,
AttributedGlyphLine::iterator>

Constructor & Destructor Documentation

◆ ShapedText() [1/3]

tt::ShapedText::ShapedText ( std::vector< AttributedGrapheme > const & text,
float width,
Alignment const alignment = Alignment::MiddleCenter,
bool wrap = true )
noexcept

Create shaped text from attributed text.

This function is used to draw rich-text. Each grapheme comes with its own text-style.

Vertical alignment is based on base line at y=0.0:

  • Bottom -> base line of the last line is at y=0.0
  • Top -> base line of the first line is at y=0.0
  • Middle ->
    • Odd # lines -> base line of middle line is at y=0.0
    • Even # lines -> gap between the two middle lines is at y=0.0

Horizontal alignment is based on the given width:

  • Left -> first character starts at x=0.0
  • Right -> last visible character end at x=maximum_width
  • Center -> middle of the visible text at x=maximum_width/2
Parameters
textThe text to draw.
alignmentThe alignment of the text within the extent.
widthThe width into which the text is horizontally aligned.
wrapTrue when text should be wrapped to fit inside the given width.

◆ ShapedText() [2/3]

tt::ShapedText::ShapedText ( gstring const & text,
TextStyle const & style,
float width,
Alignment const alignment = Alignment::MiddleCenter,
bool wrap = true )
noexcept

Create shaped text from a string.

This function is mostly used for drawing label text.

Parameters
textThe text to draw.
styleThe text style.
extentThe size of the box to draw in.
alignmentThe alignment of the text within the extent.
wrapWhen fitting the text in the extent wrap lines when needed.

◆ ShapedText() [3/3]

tt::ShapedText::ShapedText ( std::string_view text,
TextStyle const & style,
float width,
Alignment const alignment = Alignment::MiddleCenter,
bool wrap = true )
noexcept

Create shaped text from a string.

This function is mostly used for drawing label text.

Parameters
textThe text to draw.
styleThe text style.
extentThe size of the box to draw in.
alignmentThe alignment of the text within the extent.
wrapWhen fitting the text in the extent wrap lines when needed.

Member Function Documentation

◆ baselineOffset()

float tt::ShapedText::baselineOffset ( float height)
inlinenoexcept

Get the offset of the baseline The offset of the baseline when the text needs to be rendered inside a box of the given height.

The offset is depended on the vertical alignment of the shaped text.

◆ find()

const_iterator tt::ShapedText::find ( ssize_t position) const
noexcept

Find a glyph that corresponds to position.

◆ get_path()

Path tt::ShapedText::get_path ( ) const
noexcept

Convert the whole shaped text into a layered path.

◆ indexAtRightSideOfWord()

ssize_t tt::ShapedText::indexAtRightSideOfWord ( ssize_t logicalIndex) const
noexcept

Return the index at the left side of a word.

◆ indexFromCoordinate()

int tt::ShapedText::indexFromCoordinate ( vec coordinate) const
noexcept

Get the index into the text from a coordinate.

The index returned is from the text that was used to construct the ShapedText.

Parameters
coordinateA coordinate within the box.
Returns
index of the selected grapheme, or -1 if no grapheme was found near the coordinate.

◆ indexOfCharAtCoordinate()

std::optional< ssize_t > tt::ShapedText::indexOfCharAtCoordinate ( vec coordinate) const
noexcept

Return the index of the character .

Parameters
logicalIndexThe character at logicalIndex.
Returns
logicalIndex of the character to the left.

◆ indexOfCharOnTheLeft()

std::optional< ssize_t > tt::ShapedText::indexOfCharOnTheLeft ( ssize_t logicalIndex) const
noexcept

Return the index of the character to the left.

Parameters
logicalIndexThe character at logicalIndex.
Returns
logicalIndex of the character to the left.

◆ indexOfCharOnTheRight()

std::optional< ssize_t > tt::ShapedText::indexOfCharOnTheRight ( ssize_t logicalIndex) const
noexcept

Return the index of the character to the right.

Parameters
logicalIndexThe character at logicalIndex.
Returns
logicalIndex of the character to the right.

◆ indexOfWordOnTheLeft()

std::optional< ssize_t > tt::ShapedText::indexOfWordOnTheLeft ( ssize_t logicalIndex) const
noexcept

Return the index of the word to the left.

Parameters
logicalIndexThe character at logicalIndex.
Returns
logicalIndex of the character at the start of the word to the left.

◆ indexOfWordOnTheRight()

std::optional< ssize_t > tt::ShapedText::indexOfWordOnTheRight ( ssize_t logicalIndex) const
noexcept

Return the index of the word to the right.

Parameters
logicalIndexThe character at logicalIndex.
Returns
logicalIndex of the character at the start of the next word to the right.

◆ indicesFromCoordinates()

std::vector< int > tt::ShapedText::indicesFromCoordinates ( vec start,
vec current ) const
noexcept

Get the index into the text from a coordinate.

The index returned is from the text that was used to construct the ShapedText.

Parameters
startThe coordinate at the start of a mouse drag.
currentThe current coordinate of the mouse pointer, during the drag.
Returns
indices of all the graphemes selected during a drag.

◆ indicesOfParagraph()

std::pair< ssize_t, ssize_t > tt::ShapedText::indicesOfParagraph ( ssize_t logicalIndex) const
noexcept

Return the index at the left side and right side of a paragraph.

◆ indicesOfWord()

std::pair< ssize_t, ssize_t > tt::ShapedText::indicesOfWord ( ssize_t logicalIndex) const
noexcept

Return the index at the left side and right side of a word.

◆ leftToRightCaret()

aarect tt::ShapedText::leftToRightCaret ( ssize_t index,
bool overwrite ) const
noexcept

Return the cursor-carets.

The caret will be to the left of the character at position.

Parameters
indexLogical grapheme index.
overwriteWhen true display a overwrite cursor.
Returns
left-to-right caret rectangle to display.

◆ middleCapHeight()

float tt::ShapedText::middleCapHeight ( ) const
inlinenoexcept

Get the capHeight of the middle line(s).

◆ middleOffset()

float tt::ShapedText::middleOffset ( float height) const
inlinenoexcept

Get the offset of the middle of a line.

The offset of the baseline when the middle of a line needs to be at a specific height. The offset is depended on the vertical alignment of the shaped text.

◆ rectangleOfGrapheme()

aarect tt::ShapedText::rectangleOfGrapheme ( ssize_t index) const
noexcept

Get a rectangle for the grapheme.

The rectangle describes the edges of the grapheme:

  • From left side bearing to right side bearing of the glyph.
  • from descender to ascender of the line that the glyph is part of.
Parameters
index
Returns
A rectangle describing the position of the grapheme.

◆ selectionRectangles()

std::vector< aarect > tt::ShapedText::selectionRectangles ( ssize_t first,
ssize_t last ) const
noexcept

Return a list of merged rectangles to display for the selection.

The selection may be discontinues due to bidirectional text.

Parameters
firstThe first logical grapheme that is selected.
lastOne beyond the last logical grapheme that is selected.
Returns
A list of rectangles to display.

◆ T()

mat::T2 tt::ShapedText::T ( aarect rectangle)
inlinenoexcept

Get the translation for where to place the text.

Parameters
rectangleThe rectangle where the text should be aligned into. The width is ignored and assumed to be the same as the width passed during text shaping.

◆ TMiddle()

mat::T2 tt::ShapedText::TMiddle ( vec position)
inlinenoexcept

Get the translation for where to place the text.

Parameters
positionx is the left position, y is where the middle of the line should be.

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