TGUI  1.6.1
Loading...
Searching...
No Matches

Backend-independent wrapper around the backend-specific text class. More...

#include <TGUI/Text.hpp>

Classes

struct  Blueprint
 Describes a text piece, before turning it into an actual Text object. More...
 

Public Member Functions

 Text ()
 Default constructor.
 
 Text (const Text &)
 
 Text (Text &&) noexcept=default
 
Textoperator= (const Text &)
 
Textoperator= (Text &&) noexcept=default
 
void setPosition (Vector2f position)
 Sets the position of the text.
 
Vector2f getPosition () const
 Returns the position of the text.
 
Vector2f getSize () const
 Returns the size of the text.
 
void setString (const String &string)
 Changes the text.
 
const StringgetString () const
 Returns the text.
 
void setCharacterSize (unsigned int size)
 Changes the character size of the text.
 
unsigned int getCharacterSize () const
 Returns the character size of the text.
 
void setColor (Color color)
 Changes the text fill color.
 
Color getColor () const
 Returns the text fill color.
 
void setOpacity (float opacity)
 Changes the opacity of the text.
 
float getOpacity () const
 Returns the opacity of the text.
 
void setFont (const Font &font)
 Changes the font used for the text.
 
Font getFont () const
 Returns the font of the text.
 
void setStyle (TextStyles style)
 Changes the style of the text.
 
TextStyles getStyle () const
 Returns the style of the text.
 
void setOutlineColor (Color color)
 Changes the text outline color.
 
Color getOutlineColor () const
 Returns the text outline color.
 
void setOutlineThickness (float thickness)
 Changes the text outline thickness.
 
float getOutlineThickness () const
 Returns the text outline thickness.
 
Vector2f findCharacterPos (std::size_t index) const
 Return the position of the index-th character.
 
float getExtraHorizontalPadding () const
 Returns a small distance that text should be placed from the side of a widget as padding.
 
float getExtraHorizontalOffset () const
 Returns an extra distance that text should be placed from the side of a widget as padding.
 
float getLineHeight () const
 Returns the height of a single line of text.
 
float getLineWidth () const
 Returns the width of a single line of text.
 
std::shared_ptr< BackendTextgetBackendText () const
 Returns the internal text.
 

Static Public Member Functions

static float getExtraHorizontalPadding (const Font &font, unsigned int characterSize)
 Returns a small distance that text should be placed from the side of a widget as padding.
 
static float getExtraHorizontalOffset (const Font &font, unsigned int characterSize)
 Returns an extra distance that text should be placed from the side of a widget as padding.
 
static float getExtraVerticalPadding (unsigned int characterSize)
 Returns the distance that text should be placed from the bottom of the widget as padding.
 
static float getLineHeight (const Font &font, unsigned int characterSize)
 Returns the height of a single line of text.
 
static float getLineWidth (const String &text, const Font &font, unsigned int characterSize, TextStyles textStyle={})
 Returns the width of a single line of text.
 
static unsigned int findBestTextSize (const Font &font, float height, int fit=0)
 Finds the best character size for the text.
 
static String wordWrap (float maxWidth, const String &text, const Font &font, unsigned int textSize, bool bold)
 
static std::vector< std::vector< Blueprint > > wordWrap (float maxWidth, const std::vector< std::vector< Blueprint > > &lines, const Font &font)
 

Detailed Description

Backend-independent wrapper around the backend-specific text class.

Member Function Documentation

◆ findBestTextSize()

static unsigned int tgui::Text::findBestTextSize ( const Font & font,
float height,
int fit = 0 )
staticnodiscard

Finds the best character size for the text.

Parameters
fontFont of the text
heightHeight that the text should fill
fit0 to choose best fit, 1 to select font of at least that height, -1 to select font of maximum that height
Returns
Chosen character size

◆ findCharacterPos()

Vector2f tgui::Text::findCharacterPos ( std::size_t index) const
nodiscard

Return the position of the index-th character.

If index is out of range, the position of the end of the string is returned.

Parameters
indexIndex of the character
Returns
Position of the character
Warning
Unlike the function in sf::Text, this function does not take global transformations into account.

◆ getBackendText()

std::shared_ptr< BackendText > tgui::Text::getBackendText ( ) const
nodiscard

Returns the internal text.

Returns
Backend text that is used internally

◆ getCharacterSize()

unsigned int tgui::Text::getCharacterSize ( ) const
nodiscard

Returns the character size of the text.

Returns
The current text size

◆ getColor()

Color tgui::Text::getColor ( ) const
nodiscard

Returns the text fill color.

Returns
text color

◆ getExtraHorizontalOffset() [1/2]

float tgui::Text::getExtraHorizontalOffset ( ) const
nodiscard

Returns an extra distance that text should be placed from the side of a widget as padding.

This distance is slightly larger than getExtraHorizontalPadding.

◆ getExtraHorizontalOffset() [2/2]

static float tgui::Text::getExtraHorizontalOffset ( const Font & font,
unsigned int characterSize )
staticnodiscard

Returns an extra distance that text should be placed from the side of a widget as padding.

This distance is slightly larger than getExtraHorizontalPadding.

◆ getExtraHorizontalPadding() [1/2]

float tgui::Text::getExtraHorizontalPadding ( ) const
nodiscard

Returns a small distance that text should be placed from the side of a widget as padding.

This distance is slightly smaller than getExtraHorizontalOffset.

◆ getExtraHorizontalPadding() [2/2]

static float tgui::Text::getExtraHorizontalPadding ( const Font & font,
unsigned int characterSize )
staticnodiscard

Returns a small distance that text should be placed from the side of a widget as padding.

This distance is slightly smaller than getExtraHorizontalOffset.

◆ getFont()

Font tgui::Text::getFont ( ) const
nodiscard

Returns the font of the text.

Returns
text font

◆ getOpacity()

float tgui::Text::getOpacity ( ) const
nodiscard

Returns the opacity of the text.

Returns
text opacity

◆ getOutlineColor()

Color tgui::Text::getOutlineColor ( ) const
nodiscard

Returns the text outline color.

Returns
text outline color

◆ getOutlineThickness()

float tgui::Text::getOutlineThickness ( ) const
nodiscard

Returns the text outline thickness.

Returns
text outline thickness

◆ getPosition()

Vector2f tgui::Text::getPosition ( ) const
nodiscard

Returns the position of the text.

Returns
Text position

◆ getSize()

Vector2f tgui::Text::getSize ( ) const
nodiscard

Returns the size of the text.

Returns
Size required for drawing the text

◆ getString()

const String & tgui::Text::getString ( ) const
nodiscard

Returns the text.

Returns
The current text

◆ getStyle()

TextStyles tgui::Text::getStyle ( ) const
nodiscard

Returns the style of the text.

Returns
The current text style

◆ setCharacterSize()

void tgui::Text::setCharacterSize ( unsigned int size)

Changes the character size of the text.

Parameters
sizeThe new text size

◆ setColor()

void tgui::Text::setColor ( Color color)

Changes the text fill color.

Parameters
colorThe new text color

◆ setFont()

void tgui::Text::setFont ( const Font & font)

Changes the font used for the text.

Parameters
fontThe new font

◆ setOpacity()

void tgui::Text::setOpacity ( float opacity)

Changes the opacity of the text.

Parameters
opacityThe text opacity

◆ setOutlineColor()

void tgui::Text::setOutlineColor ( Color color)

Changes the text outline color.

Parameters
colorThe new text outline color

◆ setOutlineThickness()

void tgui::Text::setOutlineThickness ( float thickness)

Changes the text outline thickness.

Parameters
thicknessThe new text outline thickness

◆ setPosition()

void tgui::Text::setPosition ( Vector2f position)

Sets the position of the text.

Parameters
positionPosition of the text

◆ setString()

void tgui::Text::setString ( const String & string)

Changes the text.

Parameters
stringThe new text

◆ setStyle()

void tgui::Text::setStyle ( TextStyles style)

Changes the style of the text.

The possible styles can be found in the tgui::TextStyle::Style enum. You can also pass a combination of multiple styles, for example tgui::TextStyle::Bold | tgui::TextStyle::Italic. The default style is tgui::TextStyle::Regular.

Parameters
styleNew text style

◆ wordWrap() [1/2]

static std::vector< std::vector< Blueprint > > tgui::Text::wordWrap ( float maxWidth,
const std::vector< std::vector< Blueprint > > & lines,
const Font & font )
staticnodiscard

Takes multiple lines of potentially multiple text pieces, and splits lines so that the width does not exceed maxWidth

Parameters
maxWidthMaximum width of the text
linesExisting lines that need to be split if they are too long
fontFont of the text
Returns
Lines of text pieces (either the same as the input or more lines when some were split)

◆ wordWrap() [2/2]

static String tgui::Text::wordWrap ( float maxWidth,
const String & text,
const Font & font,
unsigned int textSize,
bool bold )
staticnodiscard

Takes a string and inserts newlines into it so that the width does not exceed maxWidth.

Parameters
maxWidthMaximum width of the text
textThe text to wrap
fontFont of the text
textSizeThe text size
boldShould the text be bold?
Returns
Text with additional '
' characters

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