JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::TextLayout Class Referencefinal

A Pre-formatted piece of text, which may contain multiple fonts and colours. More...

#include <juce_TextLayout.h>

Collaboration diagram for juce::TextLayout:

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 Member Functions

 TextLayout ()
 Creates an empty layout. More...
 
 TextLayout (const TextLayout &)
 
 TextLayout (TextLayout &&) noexcept
 
 ~TextLayout ()
 Destructor. More...
 
void addLine (Line *)
 Adds a line to the layout. 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...
 
void ensureStorageAllocated (int numLinesNeeded)
 Pre-allocates space for the specified number of lines. More...
 
float getHeight () const noexcept
 Returns the maximum height of the content. More...
 
LinegetLine (int index) const noexcept
 Returns one of the lines. More...
 
int getNumLines () const noexcept
 Returns the number of lines in the layout. More...
 
float getWidth () const noexcept
 Returns the maximum width of the content. More...
 
TextLayoutoperator= (const TextLayout &)
 
TextLayoutoperator= (TextLayout &&) noexcept
 

Private Member Functions

bool createNativeLayout (const AttributedString &)
 
void createStandardLayout (const AttributedString &)
 
void recalculateSize ()
 

Private Attributes

float height
 
Justification justification
 
OwnedArray< Linelines
 
float width
 

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

{Graphics}

Constructor & Destructor Documentation

◆ TextLayout() [1/3]

juce::TextLayout::TextLayout ( )

Creates an empty layout.

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

◆ TextLayout() [2/3]

juce::TextLayout::TextLayout ( const TextLayout )

◆ TextLayout() [3/3]

juce::TextLayout::TextLayout ( TextLayout &&  )
noexcept

◆ ~TextLayout()

juce::TextLayout::~TextLayout ( )

Destructor.

Member Function Documentation

◆ addLine()

void juce::TextLayout::addLine ( 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.

◆ createLayout() [1/2]

void juce::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 juce::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 juce::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 juce::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.

◆ createNativeLayout()

bool juce::TextLayout::createNativeLayout ( const AttributedString )
private

◆ createStandardLayout()

void juce::TextLayout::createStandardLayout ( const AttributedString )
private

◆ draw()

void juce::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.

◆ ensureStorageAllocated()

void juce::TextLayout::ensureStorageAllocated ( int  numLinesNeeded)

Pre-allocates space for the specified number of lines.

◆ getHeight()

float juce::TextLayout::getHeight ( ) const
inlinenoexcept

Returns the maximum height of the content.

◆ getLine()

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

Returns one of the lines.

◆ getNumLines()

int juce::TextLayout::getNumLines ( ) const
inlinenoexcept

Returns the number of lines in the layout.

◆ getWidth()

float juce::TextLayout::getWidth ( ) const
inlinenoexcept

Returns the maximum width of the content.

◆ operator=() [1/2]

TextLayout& juce::TextLayout::operator= ( const TextLayout )

◆ operator=() [2/2]

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

◆ recalculateSize()

void juce::TextLayout::recalculateSize ( )
private

Member Data Documentation

◆ height

float juce::TextLayout::height
private

◆ justification

Justification juce::TextLayout::justification
private

◆ lines

OwnedArray<Line> juce::TextLayout::lines
private

◆ width

float juce::TextLayout::width
private

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