JUCE
Classes | Public Types | Public Member Functions | List of all members
TextLayout Class Referencefinal

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. More...
 
 TextLayout (const TextLayout &)
 
TextLayoutoperator= (const TextLayout &)
 
 TextLayout (TextLayout &&) noexcept
 
TextLayoutoperator= (TextLayout &&) noexcept
 
 ~TextLayout ()
 Destructor. More...
 
void createLayout (const AttributedString &, float maxWidth)
 Creates a layout from the given attributed string. More...
 
void createLayout (const AttributedString &, float maxWidth, float maxHeight)
 Creates a layout from the given attributed string, given some size constraints. More...
 
void createLayoutWithBalancedLineLengths (const AttributedString &, float maxWidth)
 Creates a layout, attempting to choose a width which results in lines of a similar length. More...
 
void createLayoutWithBalancedLineLengths (const AttributedString &, float maxWidth, float maxHeight)
 Creates a layout, attempting to choose a width which results in lines of a similar length. More...
 
void draw (Graphics &, Rectangle< float > area) const
 Draws the layout within the specified area. More...
 
float getWidth () const noexcept
 Returns the maximum width of the content. More...
 
float getHeight () const noexcept
 Returns the maximum height of the content. More...
 
int getNumLines () const noexcept
 Returns the number of lines in the layout. More...
 
LinegetLine (int index) const noexcept
 Returns one of the lines. More...
 
void addLine (std::unique_ptr< Line >)
 Adds a line to the layout. More...
 
void ensureStorageAllocated (int numLinesNeeded)
 Pre-allocates space for the specified number of lines. More...
 
iterator begin ()
 Returns an iterator over the lines of content. More...
 
const_iterator begin () const
 
const_iterator cbegin () const
 
iterator end ()
 Returns an iterator over the lines of content. More...
 
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. More...
 

Detailed Description

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.

See also
AttributedString

Member Typedef Documentation

◆ iterator

using TextLayout::iterator = DereferencingIterator< Line* const*>

◆ const_iterator

using TextLayout::const_iterator = DereferencingIterator<const Line* const*>

Constructor & Destructor Documentation

◆ TextLayout() [1/3]

TextLayout::TextLayout ( )

Creates an empty layout.

Having created a TextLayout, you can populate it using createLayout() or createLayoutWithBalancedLineLengths().

◆ TextLayout() [2/3]

TextLayout::TextLayout ( const TextLayout )

◆ TextLayout() [3/3]

TextLayout::TextLayout ( TextLayout &&  )
noexcept

◆ ~TextLayout()

TextLayout::~TextLayout ( )

Destructor.

Member Function Documentation

◆ operator=() [1/2]

TextLayout& TextLayout::operator= ( const TextLayout )

◆ operator=() [2/2]

TextLayout& TextLayout::operator= ( TextLayout &&  )
noexcept

◆ createLayout() [1/2]

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.

◆ createLayout() [2/2]

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.

◆ createLayoutWithBalancedLineLengths() [1/2]

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.

◆ createLayoutWithBalancedLineLengths() [2/2]

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.

◆ draw()

void TextLayout::draw ( Graphics ,
Rectangle< float >  area 
) const

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.

◆ getWidth()

float TextLayout::getWidth ( ) const
noexcept

Returns the maximum width of the content.

◆ getHeight()

float TextLayout::getHeight ( ) const
noexcept

Returns the maximum height of the content.

◆ getNumLines()

int TextLayout::getNumLines ( ) const
noexcept

Returns the number of lines in the layout.

◆ getLine()

Line& TextLayout::getLine ( int  index) const
noexcept

Returns one of the lines.

◆ addLine()

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.

◆ ensureStorageAllocated()

void TextLayout::ensureStorageAllocated ( int  numLinesNeeded)

Pre-allocates space for the specified number of lines.

◆ begin() [1/2]

iterator TextLayout::begin ( )

Returns an iterator over the lines of content.

◆ begin() [2/2]

const_iterator TextLayout::begin ( ) const

◆ cbegin()

const_iterator TextLayout::cbegin ( ) const

◆ end() [1/2]

iterator TextLayout::end ( )

Returns an iterator over the lines of content.

◆ end() [2/2]

const_iterator TextLayout::end ( ) const

◆ cend()

const_iterator TextLayout::cend ( ) const

References JUCE_LEAK_DETECTOR.

◆ recalculateSize()

void TextLayout::recalculateSize ( )

If you modify the TextLayout after creating it, call this to compute the new dimensions of the content.


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