Public Member Functions

TextLayout Class Reference

A laid-out arrangement of text. More...

List of all members.

Public Member Functions

 TextLayout ()
 Creates an empty text layout.
 TextLayout (const TextLayout &other)
 Creates a copy of another layout object.
 TextLayout (const String &text, const Font &font)
 Creates a text layout from an initial string and font.
 ~TextLayout ()
 Destructor.
TextLayoutoperator= (const TextLayout &layoutToCopy)
 Copies another layout onto this one.
void clear ()
 Clears the layout, removing all its text.
void appendText (const String &textToAppend, const Font &fontToUse)
 Adds a string to the end of the arrangement.
void setText (const String &newText, const Font &fontToUse)
 Replaces all the text with a new string.
bool isEmpty () const
 Returns true if the layout has not had any text added yet.
void layout (int maximumWidth, const Justification &justification, bool attemptToBalanceLineLengths)
 Breaks the text up to form a paragraph with the given width.
int getWidth () const
 Returns the overall width of the entire text layout.
int getHeight () const
 Returns the overall height of the entire text layout.
int getNumLines () const
 Returns the total number of lines of text.
int getLineWidth (int lineNumber) const
 Returns the width of a particular line of text.
void draw (Graphics &g, int topLeftX, int topLeftY) const
 Renders the text at a specified position using a graphics context.
void drawWithin (Graphics &g, int x, int y, int w, int h, const Justification &layoutFlags) const
 Renders the text within a specified rectangle using a graphics context.

Detailed Description

A laid-out arrangement of text.

You can add text in different fonts to a TextLayout object, then call its layout() method to word-wrap it into lines. The layout can then be drawn using a graphics context.

It's handy if you've got a message to display, because you can format it, measure the extent of the layout, and then create a suitably-sized window to show it in.

See also:
Font, Graphics::drawFittedText, GlyphArrangement

Constructor & Destructor Documentation

TextLayout::TextLayout (  )

Creates an empty text layout.

Text can then be appended using the appendText() method.

TextLayout::TextLayout ( const TextLayout other )

Creates a copy of another layout object.

TextLayout::TextLayout ( const String text,
const Font font 
)

Creates a text layout from an initial string and font.

TextLayout::~TextLayout (  )

Destructor.


Member Function Documentation

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

Copies another layout onto this one.

void TextLayout::clear (  )

Clears the layout, removing all its text.

void TextLayout::appendText ( const String textToAppend,
const Font fontToUse 
)

Adds a string to the end of the arrangement.

The string will be broken onto new lines wherever it contains carriage-returns or linefeeds. After adding it, you can call layout() to wrap long lines into a paragraph and justify it.

void TextLayout::setText ( const String newText,
const Font fontToUse 
)

Replaces all the text with a new string.

This is equivalent to calling clear() followed by appendText().

bool TextLayout::isEmpty (  ) const

Returns true if the layout has not had any text added yet.

void TextLayout::layout ( int  maximumWidth,
const Justification justification,
bool  attemptToBalanceLineLengths 
)

Breaks the text up to form a paragraph with the given width.

Parameters:
maximumWidthany text wider than this will be split across multiple lines
justificationhow the lines are to be laid-out horizontally
attemptToBalanceLineLengthsif true, it will try to split the lines at a width that keeps all the lines of text at a similar length - this is good when you're displaying a short message and don't want it to get split onto two lines with only a couple of words on the second line, which looks untidy.
int TextLayout::getWidth (  ) const

Returns the overall width of the entire text layout.

int TextLayout::getHeight (  ) const

Returns the overall height of the entire text layout.

int TextLayout::getNumLines (  ) const

Returns the total number of lines of text.

int TextLayout::getLineWidth ( int  lineNumber ) const

Returns the width of a particular line of text.

Parameters:
lineNumberthe line, from 0 to (getNumLines() - 1)
void TextLayout::draw ( Graphics g,
int  topLeftX,
int  topLeftY 
) const

Renders the text at a specified position using a graphics context.

void TextLayout::drawWithin ( Graphics g,
int  x,
int  y,
int  w,
int  h,
const Justification layoutFlags 
) const

Renders the text within a specified rectangle using a graphics context.

The justification flags dictate how the block of text should be positioned within the rectangle.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines