JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
juce::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"

Classes

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

Public Types

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

Public Member Functions

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

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:

See also
TextLayout

@tags{Graphics}

Definition at line 46 of file juce_AttributedString.h.

Member Enumeration Documentation

◆ ReadingDirection

Types of reading direction that can be used.

See also
getReadingDirection, setReadingDirection

Definition at line 130 of file juce_AttributedString.h.

◆ 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.

Definition at line 113 of file juce_AttributedString.h.

Constructor & Destructor Documentation

◆ AttributedString()

juce::AttributedString::AttributedString ( const String newString)
explicit

Creates an attributed string with the given text.

Definition at line 53 of file juce_AttributedString.h.

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.

Definition at line 203 of file juce_AttributedString.cpp.

◆ append() [2/5]

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

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

Definition at line 175 of file juce_AttributedString.cpp.

◆ append() [3/5]

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

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

Definition at line 189 of file juce_AttributedString.cpp.

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

Definition at line 182 of file juce_AttributedString.cpp.

◆ append() [5/5]

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

Appends some text, with a specified font and colour.

Definition at line 196 of file juce_AttributedString.cpp.

◆ 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.

Definition at line 217 of file juce_AttributedString.cpp.

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

Definition at line 267 of file juce_AttributedString.cpp.

◆ getAttribute()

const Attribute & juce::AttributedString::getAttribute ( int  index) const
noexcept

Returns one of the string's attributes.

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

Definition at line 184 of file juce_AttributedString.h.

◆ getJustification()

Justification juce::AttributedString::getJustification ( ) const
noexcept

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

This may include both vertical and horizontal flags.

Definition at line 102 of file juce_AttributedString.h.

◆ getLineSpacing()

float juce::AttributedString::getLineSpacing ( ) const
noexcept

Returns the extra line-spacing distance.

Definition at line 145 of file juce_AttributedString.h.

◆ getNumAttributes()

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

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

Definition at line 179 of file juce_AttributedString.h.

◆ getReadingDirection()

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

Returns the reading direction for the text.

Definition at line 138 of file juce_AttributedString.h.

◆ getText()

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

Returns the complete text of this attributed string.

Definition at line 62 of file juce_AttributedString.h.

◆ getWordWrap()

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

Returns the word-wrapping behaviour.

Definition at line 121 of file juce_AttributedString.h.

◆ setColour() [1/2]

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

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

Definition at line 255 of file juce_AttributedString.cpp.

◆ setColour() [2/2]

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

Adds a colour attribute for the specified range.

Definition at line 243 of file juce_AttributedString.cpp.

◆ setFont() [1/2]

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

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

Definition at line 261 of file juce_AttributedString.cpp.

◆ setFont() [2/2]

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

Adds a font attribute for the specified range.

Definition at line 249 of file juce_AttributedString.cpp.

◆ 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.

Definition at line 223 of file juce_AttributedString.cpp.

◆ setLineSpacing()

void juce::AttributedString::setLineSpacing ( float  newLineSpacing)
noexcept

Sets an extra line-spacing distance.

Definition at line 238 of file juce_AttributedString.cpp.

◆ setReadingDirection()

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

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

Definition at line 233 of file juce_AttributedString.cpp.

◆ 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.

Definition at line 161 of file juce_AttributedString.cpp.

◆ setWordWrap()

void juce::AttributedString::setWordWrap ( WordWrap  newWordWrap)
noexcept

Sets the word-wrapping behaviour.

Definition at line 228 of file juce_AttributedString.cpp.


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