A Pre-formatted piece of text, which may contain multiple fonts and colours. More...
Classes | |
class | Glyph |
A positioned glyph. More... | |
class | Line |
A line containing a sequence of glyph-runs. More... | |
class | Run |
A sequence of glyphs with a common font and colour. More... | |
Public Types | |
using | iterator = DereferencingIterator< Line* const*> |
using | const_iterator = DereferencingIterator<const Line* const*> |
Public Member Functions | |
TextLayout () | |
Creates an empty layout. | |
TextLayout (const TextLayout &) | |
TextLayout & | operator= (const TextLayout &) |
TextLayout (TextLayout &&) noexcept | |
TextLayout & | operator= (TextLayout &&) noexcept |
~TextLayout () | |
Destructor. | |
void | createLayout (const AttributedString &, float maxWidth) |
Creates a layout from the given attributed string. | |
void | createLayout (const AttributedString &, float maxWidth, float maxHeight) |
Creates a layout from the given attributed string, given some size constraints. | |
void | createLayoutWithBalancedLineLengths (const AttributedString &, float maxWidth) |
Creates a layout, attempting to choose a width which results in lines of a similar length. | |
void | createLayoutWithBalancedLineLengths (const AttributedString &, float maxWidth, float maxHeight) |
Creates a layout, attempting to choose a width which results in lines of a similar length. | |
void | draw (Graphics &, Rectangle< float > area) const |
Draws the layout within the specified area. | |
float | getWidth () const noexcept |
Returns the maximum width of the content. | |
float | getHeight () const noexcept |
Returns the maximum height of the content. | |
int | getNumLines () const noexcept |
Returns the number of lines in the layout. | |
Line & | getLine (int index) const noexcept |
Returns one of the lines. | |
void | addLine (std::unique_ptr< Line >) |
Adds a line to the layout. | |
void | ensureStorageAllocated (int numLinesNeeded) |
Pre-allocates space for the specified number of lines. | |
iterator | begin () |
Returns an iterator over the lines of content. | |
const_iterator | begin () const |
const_iterator | cbegin () const |
iterator | end () |
Returns an iterator over the lines of content. | |
const_iterator | end () const |
const_iterator | cend () const |
void | recalculateSize () |
If you modify the TextLayout after creating it, call this to compute the new dimensions of the content. | |
Static Public Member Functions | |
static Rectangle< float > | getStringBounds (const AttributedString &string) |
This convenience function adds an AttributedString to a TextLayout and returns the bounding box of the text after shaping. | |
static Rectangle< float > | getStringBounds (const Font &font, StringRef text) |
This convenience function adds text to a TextLayout using the specified font and returns the bounding box of the text after shaping. | |
static float | getStringWidth (const AttributedString &string) |
This convenience function adds an AttributedString to a TextLayout and returns the bounding box of the text after shaping. | |
static float | getStringWidth (const Font &font, StringRef text) |
This convenience function adds text to a TextLayout using the specified font and returns the width of the bounding box of the text after shaping. | |
A Pre-formatted piece of text, which may contain multiple fonts and colours.
A TextLayout is created from an AttributedString, and once created can be quickly drawn into a Graphics context.
using TextLayout::iterator = DereferencingIterator< Line* const*> |
using TextLayout::const_iterator = DereferencingIterator<const Line* const*> |
TextLayout::TextLayout | ( | ) |
Creates an empty layout.
Having created a TextLayout, you can populate it using createLayout() or createLayoutWithBalancedLineLengths().
Referenced by getStringBounds(), operator=(), operator=(), TextLayout(), TextLayout(), and ~TextLayout().
TextLayout::TextLayout | ( | const TextLayout & | ) |
References TextLayout().
|
noexcept |
References TextLayout().
TextLayout::~TextLayout | ( | ) |
Destructor.
References TextLayout().
TextLayout & TextLayout::operator= | ( | const TextLayout & | ) |
References TextLayout().
|
noexcept |
References TextLayout().
void TextLayout::createLayout | ( | const AttributedString & | , |
float | maxWidth ) |
Creates a layout from the given attributed string.
This will replace any data that is currently stored in the layout.
References createLayout().
Referenced by createLayout(), createLayout(), and getStringBounds().
void TextLayout::createLayout | ( | const AttributedString & | , |
float | maxWidth, | ||
float | maxHeight ) |
Creates a layout from the given attributed string, given some size constraints.
This will replace any data that is currently stored in the layout.
References createLayout().
void TextLayout::createLayoutWithBalancedLineLengths | ( | const AttributedString & | , |
float | maxWidth ) |
Creates a layout, attempting to choose a width which results in lines of a similar length.
This will be slower than the normal createLayout method, but produces a tidier result.
References createLayoutWithBalancedLineLengths().
Referenced by createLayoutWithBalancedLineLengths(), and createLayoutWithBalancedLineLengths().
void TextLayout::createLayoutWithBalancedLineLengths | ( | const AttributedString & | , |
float | maxWidth, | ||
float | maxHeight ) |
Creates a layout, attempting to choose a width which results in lines of a similar length.
This will be slower than the normal createLayout method, but produces a tidier result.
References createLayoutWithBalancedLineLengths().
Draws the layout within the specified area.
The position of the text within the rectangle is controlled by the justification flags set in the original AttributedString that was used to create this layout.
References draw().
Referenced by draw().
|
noexcept |
|
noexcept |
Returns the maximum height of the content.
|
noexcept |
Returns the number of lines in the layout.
Referenced by getStringBounds().
|
noexcept |
Returns one of the lines.
Referenced by getStringBounds().
void TextLayout::addLine | ( | std::unique_ptr< Line > | ) |
Adds a line to the layout.
The layout will take ownership of this line object and will delete it when it is no longer needed.
void TextLayout::ensureStorageAllocated | ( | int | numLinesNeeded | ) |
Pre-allocates space for the specified number of lines.
iterator TextLayout::begin | ( | ) |
Returns an iterator over the lines of content.
const_iterator TextLayout::begin | ( | ) | const |
const_iterator TextLayout::cbegin | ( | ) | const |
iterator TextLayout::end | ( | ) |
Returns an iterator over the lines of content.
const_iterator TextLayout::end | ( | ) | const |
const_iterator TextLayout::cend | ( | ) | const |
void TextLayout::recalculateSize | ( | ) |
If you modify the TextLayout after creating it, call this to compute the new dimensions of the content.
|
static |
This convenience function adds an AttributedString to a TextLayout and returns the bounding box of the text after shaping.
The returned bounding box is positioned with its origin at the left end of the text's baseline.
References createLayout(), getLine(), TextLayout::Line::getLineBounds(), getNumLines(), and TextLayout().
Referenced by getStringBounds(), getStringWidth(), and getStringWidth().
This convenience function adds text to a TextLayout using the specified font and returns the bounding box of the text after shaping.
The returned bounding box is positioned with its origin at the left end of the text's baseline.
References AttributedString::append(), and getStringBounds().
|
static |
This convenience function adds an AttributedString to a TextLayout and returns the bounding box of the text after shaping.
References getStringBounds().
This convenience function adds text to a TextLayout using the specified font and returns the width of the bounding box of the text after shaping.
References getStringBounds().