utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
utility::graphic::Text Class Reference

Storage for text content and rendering properties. More...

#include <headers/utility/graphic/text/text.hpp>

Inheritance diagram for utility::graphic::Text:
Collaboration diagram for utility::graphic::Text:

Public Member Functions

 Text (std::shared_ptr< RessourceProvider > ressourceProvider, const PoseF &pose, const Color32Bit &color, const std::string &content, uint32_t fontSize, const std::string &font)
 Constructor.
 
 Text (const Text &other)=delete
 Copy constructor.
 
 Text (Text &&other) noexcept=default
 Move constructor.
 
std::shared_ptr< MeshgetMesh () const
 Get the mesh for rendering the text.
 
const std::string & getFontFamily (void) const
 Get the font family (path) used for rendering the text.
 
Textoperator= (const Text &other)=delete
 Copy assignment operator.
 
Textoperator= (Text &&other) noexcept=default
 Move assignment operator.
 
const std::string & getContent (void) const
 Get the text content.
 
TextsetContent (const std::string &content)
 Set the text content.
 
uint32_t getFontSize (void) const
 Get the font size.
 
graphic::SizeF getTextDimensions (void) const
 Get the dimensions of the rendered text.
 
TextsetFontSize (uint32_t fontSize)
 Set the font size.
 
bool empty (void) const noexcept
 Check if text content is empty.
 
bool hasFontPath (void) const noexcept
 Check if font path is set.
 
TextclearContent (void)
 Clear text content.
 
bool operator== (const Text &other) const
 Equality comparison.
 
bool operator!= (const Text &other) const
 Inequality comparison.
 
- Public Member Functions inherited from utility::graphic::Renderable
 Renderable (const PoseF &pose, const Color32Bit &color)
 Default constructor for Renderable.
 
virtual ~Renderable ()=default
 Virtual destructor for Renderable.
 
RenderablesetPose (const PoseF &pose)
 Set the text pose.
 
void setPose (PoseF &&pose)
 Set the text pose.
 
const PoseFgetPose (void) const
 Get the text pose.
 
glm::mat4 getModelMatrix (void) const
 Get the object-to-world model matrix of this renderable.
 
RenderablesetColor (const graphic::Color32Bit &color)
 Set the text color.
 
void setColor (graphic::Color32Bit &&color)
 Set the text color.
 
const graphic::Color32BitgetColor (void) const
 Get the text color.].
 
std::vector< std::shared_ptr< Mesh > > getMeshes () const
 Get the meshes associated with this renderable object.
 

Protected Member Functions

void updateMesh (void)
 Updates the mesh for rendering the text based on the current content, font, and font size.
 
codePointString utf8ToCodepoints (const std::string &str) const
 Converts a UTF-8 encoded string to a string of Unicode code points.
 
- Protected Member Functions inherited from utility::logging::Loggable< Text, logging::DefaultLogger >
 Loggable (void)
 Construct a Loggable with the specified LoggerType.
 
 Loggable (Loggable &&other) noexcept
 Move constructor for Loggable.
 
Loggableoperator= (Loggable &&other) noexcept
 Move assignment operator for Loggable.
 
LoggerType & getLogger (void)
 Get the internal logger.
 
LoggerType & getLogger (void) const
 Get the internal logger.
 
virtual ~Loggable (void)=default
 Virtual destructor for proper cleanup.
 

Protected Attributes

std::shared_ptr< Font_font
 Shared pointer to the font used for rendering.
 
- Protected Attributes inherited from utility::graphic::Renderable
std::vector< std::shared_ptr< Mesh > > _meshes
 Meshes associated with this renderable object.
 
Color32Bit _color
 Text RGBA color.
 
PoseF _pose
 World pose (position and orientation) of the text.
 

Detailed Description

Storage for text content and rendering properties.

Encapsulates all properties needed to render text, including content, font information and size.

Definition at line 72 of file text.hpp.

Constructor & Destructor Documentation

◆ Text() [1/3]

utility::graphic::Text::Text ( std::shared_ptr< RessourceProvider ressourceProvider,
const PoseF pose,
const Color32Bit color,
const std::string &  content,
uint32_t  fontSize,
const std::string &  font 
)

Constructor.

This constructor initializes a Text object with the specified content, font size, and font path. It also takes references to a RessourceProvider and an SystemIO, which are used to load the necessary font resources for rendering the text.

Parameters
ressourceProviderA reference to the RessourceProvider instance used to load font resources.
poseThe initial position and orientation for the text.
colorThe initial color of the text.
contentThe text content to be displayed.
fontSizeThe font size in points for rendering the text.
fontThe file path to the font resource to be used for rendering the text.

Definition at line 32 of file text.cpp.

Here is the call graph for this function:

◆ Text() [2/3]

utility::graphic::Text::Text ( const Text other)
delete

Copy constructor.

Parameters
otherThe Text object to copy from.

◆ Text() [3/3]

utility::graphic::Text::Text ( Text &&  other)
defaultnoexcept

Move constructor.

Parameters
otherThe Text object to move from.

Member Function Documentation

◆ clearContent()

Text & utility::graphic::Text::clearContent ( void  )
inline

Clear text content.

Returns
Reference to this Text instance for chaining.

Definition at line 252 of file text.hpp.

◆ empty()

bool utility::graphic::Text::empty ( void  ) const
inlinenoexcept

Check if text content is empty.

Returns
True if content has no characters.

Definition at line 234 of file text.hpp.

◆ getContent()

const std::string & utility::graphic::Text::getContent ( void  ) const

Get the text content.

Returns
Reference to the text content string.

Definition at line 58 of file text.cpp.

◆ getFontFamily()

const std::string & utility::graphic::Text::getFontFamily ( void  ) const

Get the font family (path) used for rendering the text.

This method returns the path to the font file that is currently being used to render the text. The font family is determined by the font file specified during the construction of the Text object or when the font is changed. It can be used to identify the font being used for rendering or to retrieve additional font information if needed.

Returns
A const reference to the string containing the path to the font file used for rendering the text.

Definition at line 53 of file text.cpp.

◆ getFontSize()

uint32_t utility::graphic::Text::getFontSize ( void  ) const

Get the font size.

Returns
Font size in points.

Definition at line 70 of file text.cpp.

◆ getMesh()

std::shared_ptr< Mesh > utility::graphic::Text::getMesh ( ) const

Get the mesh for rendering the text.

This method returns a shared pointer to the Mesh object that represents the geometry of the text for rendering. The mesh is generated based on the current text content, font, and font size, and it is updated whenever the text properties change (e.g., when the content or font size is modified).

Returns
A shared pointer to the Mesh object for rendering the text.

Definition at line 48 of file text.cpp.

◆ getTextDimensions()

graphic::SizeF utility::graphic::Text::getTextDimensions ( void  ) const

Get the dimensions of the rendered text.

This method calculates and returns the dimensions of the rendered text based on the current content, font, and font size. It uses the Font class to retrieve the glyph information for the text content and computes the overall width and height of the text as it would be rendered, which can be useful for layout and positioning purposes.

Returns
A SizeF containing the width and height of the rendered text.

Definition at line 84 of file text.cpp.

Here is the call graph for this function:

◆ hasFontPath()

bool utility::graphic::Text::hasFontPath ( void  ) const
inlinenoexcept

Check if font path is set.

Returns
True if a non-empty font path is configured.

Definition at line 243 of file text.hpp.

◆ operator!=()

bool utility::graphic::Text::operator!= ( const Text other) const
inline

Inequality comparison.

Parameters
otherText object to compare with.
Returns
True when any property differs.

Definition at line 275 of file text.hpp.

◆ operator=() [1/2]

Text & utility::graphic::Text::operator= ( const Text other)
delete

Copy assignment operator.

Parameters
otherThe Text object to copy from.
Returns
A reference to this Text object.

◆ operator=() [2/2]

Text & utility::graphic::Text::operator= ( Text &&  other)
defaultnoexcept

Move assignment operator.

Parameters
otherThe Text object to move from.
Returns
A reference to this Text object.

◆ operator==()

bool utility::graphic::Text::operator== ( const Text other) const
inline

Equality comparison.

Parameters
otherText object to compare with.
Returns
True when the visible text state is equal.

Definition at line 263 of file text.hpp.

◆ setContent()

Text & utility::graphic::Text::setContent ( const std::string &  content)

Set the text content.

Parameters
contentThe new text content.
Returns
Reference to this Text instance for chaining.

Definition at line 63 of file text.cpp.

Here is the call graph for this function:

◆ setFontSize()

Text & utility::graphic::Text::setFontSize ( uint32_t  fontSize)

Set the font size.

Parameters
fontSizeFont size in points.
Returns
Reference to this Text instance for chaining.

Definition at line 75 of file text.cpp.

Here is the call graph for this function:

◆ updateMesh()

void utility::graphic::Text::updateMesh ( void  )
protected

Updates the mesh for rendering the text based on the current content, font, and font size.

This method regenerates the mesh geometry for the text whenever the content, font, or font size changes. It uses the Font class to retrieve the necessary glyph information and constructs a new Mesh object that represents the geometry of the text for rendering.

Definition at line 107 of file text.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf8ToCodepoints()

std::vector< uint32_t > utility::graphic::Text::utf8ToCodepoints ( const std::string &  str) const
protected

Converts a UTF-8 encoded string to a string of Unicode code points.

This method takes a UTF-8 encoded string as input and converts it to a string of Unicode code points, which can be used for rendering text with the appropriate glyphs. It processes the UTF-8 encoding to extract the individual Unicode code points and returns them in a codePointString format, which is a vector of uint32_t values representing the Unicode code

Parameters
strThe UTF-8 encoded string to convert.
Returns
A codePointString containing the Unicode code points extracted from the input UTF-8 string.

Definition at line 167 of file text.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ _font

std::shared_ptr<Font> utility::graphic::Text::_font
protected

Shared pointer to the font used for rendering.

Definition at line 83 of file text.hpp.


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