JUCE  v5.1.1-3-g1a0b28c73
JUCE API
AttributedString Class Reference

A text string with a set of colour/font settings that are associated with sub-ranges of the text. More...

#include <juce_AttributedString.h>

Collaboration diagram for AttributedString:

Classes

class  Attribute
 An attribute that has been applied to a range of characters in an AttributedString. More...
 

Public Types

enum  ReadingDirection {
  natural,
  leftToRight,
  rightToLeft
}
 Types of reading direction that can be used. More...
 
enum  WordWrap {
  none,
  byWord,
  byChar
}
 Types of word-wrap behaviour. More...
 

Public Member Functions

 AttributedString ()
 Creates an empty attributed string. More...
 
 AttributedString (const String &text)
 Creates an attributed string with the given text. More...
 
 AttributedString (const AttributedString &)
 
 AttributedString (AttributedString &&) noexcept
 
 ~AttributedString () noexcept
 Destructor. More...
 
void append (const String &textToAppend)
 Appends some text (with a default font and colour). More...
 
void append (const String &textToAppend, const Font &font)
 Appends some text, with a specified font, and the default colour (black). More...
 
void append (const String &textToAppend, Colour colour)
 Appends some text, with a specified colour, and the default font. More...
 
void append (const String &textToAppend, const Font &font, Colour colour)
 Appends some text, with a specified font and colour. More...
 
void append (const AttributedString &other)
 Appends another AttributedString to this one. More...
 
void clear ()
 Resets the string, clearing all text and attributes. More...
 
void draw (Graphics &g, const Rectangle< float > &area) const
 Draws this string within the given area. More...
 
const AttributegetAttribute (int index) const noexcept
 Returns one of the string's attributes. More...
 
Justification getJustification () const noexcept
 Returns the justification that should be used for laying-out the text. More...
 
float getLineSpacing () const noexcept
 Returns the extra line-spacing distance. More...
 
int getNumAttributes () const noexcept
 Returns the number of attributes that have been added to this string. More...
 
ReadingDirection getReadingDirection () const noexcept
 Returns the reading direction for the text. More...
 
const StringgetText () const noexcept
 Returns the complete text of this attributed string. More...
 
WordWrap getWordWrap () const noexcept
 Returns the word-wrapping behaviour. More...
 
AttributedStringoperator= (const AttributedString &)
 
AttributedStringoperator= (AttributedString &&) noexcept
 
void setColour (Range< int > range, Colour colour)
 Adds a colour attribute for the specified range. More...
 
void setColour (Colour colour)
 Removes all existing colour attributes, and applies this colour to the whole string. More...
 
void setFont (Range< int > range, const Font &font)
 Adds a font attribute for the specified range. More...
 
void setFont (const Font &font)
 Removes all existing font attributes, and applies this font to the whole string. More...
 
void setJustification (Justification newJustification) noexcept
 Sets the justification that should be used for laying-out the text. More...
 
void setLineSpacing (float newLineSpacing) noexcept
 Sets an extra line-spacing distance. More...
 
void setReadingDirection (ReadingDirection newReadingDirection) noexcept
 Sets the reading direction that should be used for the text. More...
 
void setText (const String &newText)
 Replaces all the text. More...
 
void setWordWrap (WordWrap newWordWrap) noexcept
 Sets the word-wrapping behaviour. More...
 

Private Attributes

Array< Attributeattributes
 
Justification justification
 
float lineSpacing
 
ReadingDirection readingDirection
 
String text
 
WordWrap wordWrap
 

Detailed Description

A text string with a set of colour/font settings that are associated with sub-ranges of the text.

An attributed string lets you create a string with varied fonts, colours, word-wrapping, layout, etc., and draw it using AttributedString::draw().

See also
TextLayout

Member Enumeration Documentation

◆ ReadingDirection

Types of reading direction that can be used.

See also
getReadingDirection, setReadingDirection
Enumerator
natural 
leftToRight 
rightToLeft 

◆ WordWrap

Types of word-wrap behaviour.

See also
getWordWrap, setWordWrap
Enumerator
none 

No word-wrapping: lines extend indefinitely.

byWord 

Lines are wrapped on a word boundary.

byChar 

Lines are wrapped on a character boundary.

Constructor & Destructor Documentation

◆ AttributedString() [1/4]

AttributedString::AttributedString ( )

Creates an empty attributed string.

◆ AttributedString() [2/4]

AttributedString::AttributedString ( const String text)
explicit

Creates an attributed string with the given text.

◆ AttributedString() [3/4]

AttributedString::AttributedString ( const AttributedString )

◆ AttributedString() [4/4]

AttributedString::AttributedString ( AttributedString &&  )
noexcept

◆ ~AttributedString()

AttributedString::~AttributedString ( )
noexcept

Destructor.

Member Function Documentation

◆ append() [1/5]

void AttributedString::append ( const String textToAppend)

Appends some text (with a default font and colour).

◆ append() [2/5]

void AttributedString::append ( const String textToAppend,
const Font font 
)

Appends some text, with a specified font, and the default colour (black).

◆ append() [3/5]

void AttributedString::append ( const String textToAppend,
Colour  colour 
)

Appends some text, with a specified colour, and the default font.

◆ append() [4/5]

void AttributedString::append ( const String textToAppend,
const Font font,
Colour  colour 
)

Appends some text, with a specified font and colour.

◆ append() [5/5]

void AttributedString::append ( const AttributedString other)

Appends another AttributedString to this one.

Note that this will only append the text, fonts, and colours - it won't copy any other properties such as justification, line-spacing, etc from the other object.

◆ clear()

void AttributedString::clear ( )

Resets the string, clearing all text and attributes.

Note that this won't affect global settings like the justification type, word-wrap mode, etc.

◆ draw()

void AttributedString::draw ( Graphics g,
const Rectangle< float > &  area 
) const

Draws this string within the given area.

The layout of the string within the rectangle is controlled by the justification value passed to setJustification().

◆ getAttribute()

const Attribute& AttributedString::getAttribute ( int  index) const
inlinenoexcept

Returns one of the string's attributes.

The index provided must be less than getNumAttributes(), and >= 0.

◆ getJustification()

Justification AttributedString::getJustification ( ) const
inlinenoexcept

Returns the justification that should be used for laying-out the text.

This may include both vertical and horizontal flags.

◆ getLineSpacing()

float AttributedString::getLineSpacing ( ) const
inlinenoexcept

Returns the extra line-spacing distance.

◆ getNumAttributes()

int AttributedString::getNumAttributes ( ) const
inlinenoexcept

Returns the number of attributes that have been added to this string.

◆ getReadingDirection()

ReadingDirection AttributedString::getReadingDirection ( ) const
inlinenoexcept

Returns the reading direction for the text.

◆ getText()

const String& AttributedString::getText ( ) const
inlinenoexcept

Returns the complete text of this attributed string.

◆ getWordWrap()

WordWrap AttributedString::getWordWrap ( ) const
inlinenoexcept

Returns the word-wrapping behaviour.

◆ operator=() [1/2]

AttributedString& AttributedString::operator= ( const AttributedString )

◆ operator=() [2/2]

AttributedString& AttributedString::operator= ( AttributedString &&  )
noexcept

◆ setColour() [1/2]

void AttributedString::setColour ( Range< int range,
Colour  colour 
)

Adds a colour attribute for the specified range.

◆ setColour() [2/2]

void AttributedString::setColour ( Colour  colour)

Removes all existing colour attributes, and applies this colour to the whole string.

◆ setFont() [1/2]

void AttributedString::setFont ( Range< int range,
const Font font 
)

Adds a font attribute for the specified range.

◆ setFont() [2/2]

void AttributedString::setFont ( const Font font)

Removes all existing font attributes, and applies this font to the whole string.

◆ setJustification()

void AttributedString::setJustification ( Justification  newJustification)
noexcept

Sets the justification that should be used for laying-out the text.

This may include both vertical and horizontal flags.

◆ setLineSpacing()

void AttributedString::setLineSpacing ( float  newLineSpacing)
noexcept

Sets an extra line-spacing distance.

◆ setReadingDirection()

void AttributedString::setReadingDirection ( ReadingDirection  newReadingDirection)
noexcept

Sets the reading direction that should be used for the text.

◆ setText()

void AttributedString::setText ( const String newText)

Replaces all the text.

This will change the text, but won't affect any of the colour or font attributes that have been added.

◆ setWordWrap()

void AttributedString::setWordWrap ( WordWrap  newWordWrap)
noexcept

Sets the word-wrapping behaviour.

Member Data Documentation

◆ attributes

Array<Attribute> AttributedString::attributes
private

◆ justification

Justification AttributedString::justification
private

◆ lineSpacing

float AttributedString::lineSpacing
private

◆ readingDirection

ReadingDirection AttributedString::readingDirection
private

◆ text

String AttributedString::text
private

◆ wordWrap

WordWrap AttributedString::wordWrap
private

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