LMMS
Loading...
Searching...
No Matches
juce::AttributedString Class Reference

#include <juce_AttributedString.h>

Classes

class  Attribute

Public Types

enum  WordWrap { none , byWord , byChar }
enum  ReadingDirection { natural , leftToRight , rightToLeft }

Public Member Functions

 AttributedString ()=default
 AttributedString (const String &newString)
 AttributedString (const AttributedString &)=default
AttributedStringoperator= (const AttributedString &)=default
 AttributedString (AttributedString &&) noexcept=default
AttributedStringoperator= (AttributedString &&) noexcept=default
const StringgetText () const noexcept
void setText (const String &newText)
void append (const String &textToAppend)
void append (const String &textToAppend, const Font &font)
void append (const String &textToAppend, Colour colour)
void append (const String &textToAppend, const Font &font, Colour colour)
void append (const AttributedString &other)
void clear ()
void draw (Graphics &g, const Rectangle< float > &area) const
Justification getJustification () const noexcept
void setJustification (Justification newJustification) noexcept
WordWrap getWordWrap () const noexcept
void setWordWrap (WordWrap newWordWrap) noexcept
ReadingDirection getReadingDirection () const noexcept
void setReadingDirection (ReadingDirection newReadingDirection) noexcept
float getLineSpacing () const noexcept
void setLineSpacing (float newLineSpacing) noexcept
int getNumAttributes () const noexcept
const AttributegetAttribute (int index) const noexcept
void setColour (Range< int > range, Colour colour)
void setColour (Colour colour)
void setFont (Range< int > range, const Font &font)
void setFont (const Font &font)

Private Attributes

String text
float lineSpacing = 0.0f
Justification justification = Justification::left
WordWrap wordWrap = AttributedString::byWord
ReadingDirection readingDirection = AttributedString::natural
Array< Attributeattributes

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().

Invariants:

  • Every character in the string is a member of exactly one attribute.
  • Attributes are sorted such that the range-end of attribute 'i' is equal to the range-begin of attribute 'i + 1'.
See also
TextLayout

@tags{Graphics}

Member Enumeration Documentation

◆ ReadingDirection

enum juce::AttributedString::ReadingDirection

Types of reading direction that can be used.

See also
getReadingDirection, setReadingDirection
Enumerator
natural 
leftToRight 
rightToLeft 

◆ WordWrap

enum juce::AttributedString::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]

juce::AttributedString::AttributedString ( )
default

Creates an empty attributed string.

◆ AttributedString() [2/4]

juce::AttributedString::AttributedString ( const String & newString)
inlineexplicit

Creates an attributed string with the given text.

◆ AttributedString() [3/4]

juce::AttributedString::AttributedString ( const AttributedString & )
default

◆ AttributedString() [4/4]

juce::AttributedString::AttributedString ( AttributedString && )
defaultnoexcept

Member Function Documentation

◆ append() [1/5]

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

◆ append() [2/5]

void juce::AttributedString::append ( const String & textToAppend)

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

◆ append() [3/5]

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

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

◆ append() [4/5]

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

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

◆ append() [5/5]

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

Appends some text, with a specified font and colour.

◆ clear()

void juce::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 juce::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 & juce::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 juce::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 juce::AttributedString::getLineSpacing ( ) const
inlinenoexcept

Returns the extra line-spacing distance.

◆ getNumAttributes()

int juce::AttributedString::getNumAttributes ( ) const
inlinenoexcept

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

◆ getReadingDirection()

ReadingDirection juce::AttributedString::getReadingDirection ( ) const
inlinenoexcept

Returns the reading direction for the text.

◆ getText()

const String & juce::AttributedString::getText ( ) const
inlinenoexcept

Returns the complete text of this attributed string.

◆ getWordWrap()

WordWrap juce::AttributedString::getWordWrap ( ) const
inlinenoexcept

Returns the word-wrapping behaviour.

◆ operator=() [1/2]

AttributedString & juce::AttributedString::operator= ( AttributedString && )
defaultnoexcept

◆ operator=() [2/2]

AttributedString & juce::AttributedString::operator= ( const AttributedString & )
default

◆ setColour() [1/2]

void juce::AttributedString::setColour ( Colour colour)

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

◆ setColour() [2/2]

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

Adds a colour attribute for the specified range.

◆ setFont() [1/2]

void juce::AttributedString::setFont ( const Font & font)

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

◆ setFont() [2/2]

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

Adds a font attribute for the specified range.

◆ setJustification()

void juce::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 juce::AttributedString::setLineSpacing ( float newLineSpacing)
noexcept

Sets an extra line-spacing distance.

◆ setReadingDirection()

void juce::AttributedString::setReadingDirection ( ReadingDirection newReadingDirection)
noexcept

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

◆ setText()

void juce::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 juce::AttributedString::setWordWrap ( WordWrap newWordWrap)
noexcept

Sets the word-wrapping behaviour.

Member Data Documentation

◆ attributes

Array<Attribute> juce::AttributedString::attributes
private

◆ justification

Justification juce::AttributedString::justification = Justification::left
private

◆ lineSpacing

float juce::AttributedString::lineSpacing = 0.0f
private

◆ readingDirection

ReadingDirection juce::AttributedString::readingDirection = AttributedString::natural
private

◆ text

String juce::AttributedString::text
private

◆ wordWrap

WordWrap juce::AttributedString::wordWrap = AttributedString::byWord
private

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