Text¶
High-level text handling utilities.
Overview¶
Typical use cases:
Managing text rendering and glyph handling.
Header¶
<RaeptorCogs/Text.hpp>
Metadata¶
- Author
Estorc
- Version
v1.0
- Copyright
Copyright (c) 2025 Estorc MIT License.
Enums¶
Enum |
Description |
|---|---|
|
Enumeration for text alignment options. |
|
Flags for Text2D class. |
|
Enumeration for text word wrapping modes. |
-
enum class RaeptorCogs::TextAlignment¶
Enumeration for text alignment options.
Defines how text should be aligned within its bounding box.
Values:
-
enumerator LEFT¶
Align text to the left
-
enumerator CENTER¶
Center align text
-
enumerator RIGHT¶
Align text to the right
-
enumerator LEFT¶
-
enum class RaeptorCogs::TextFlags : uint32_t¶
Flags for Text2D class.
Defines various states for text rendering.
Values:
-
enumerator NONE¶
No flags set
-
enumerator TEXT_DIRTY¶
Flag to indicate if the text needs to be rebuilt
-
enumerator NONE¶
-
enum class RaeptorCogs::TextWordWrap¶
Enumeration for text word wrapping modes.
Defines how text should be wrapped when it exceeds a certain width.
Values:
-
enumerator NONE¶
No word wrapping
-
enumerator WORD¶
Wrap at word boundaries
-
enumerator CHARACTER¶
Wrap at character boundaries
-
enumerator NONE¶
Classes¶
Class |
Description |
|---|---|
|
Class representing a single glyph (character) in a text. |
|
Constant for normal font size. |
-
class Glyph : public RaeptorCogs::TransformableGraphic2D¶
Class representing a single glyph (character) in a text.
Inherits from TransformableGraphic2D to provide transformation capabilities.
See also
Public Functions
-
Glyph(Text2D &text, const U8Char &character, glm::vec2 advance = glm::vec2(0.0f, 0.0f))¶
Constructor for Glyph.
Note
Initializes the glyph with the specified character and advance.
- Parameters:
text – Reference to the parent Text2D object.
character – The character represented by this glyph.
advance – The advance vector for the glyph.
-
void setCharacter(const U8Char &character, glm::vec2 advance = glm::vec2(0.0f, 0.0f))¶
Set the character for this glyph.
- Parameters:
character – The new character.
advance – The advance vector for the glyph.
-
virtual bool computeInstanceData(GAPI::Common::InstanceAllocator &instanceAllocator, ComputeInstanceDataMode mode = ComputeInstanceDataMode::NONE) override¶
Compute instance data for this glyph.
Note
Overrides the base class method.
- Parameters:
instanceAllocator – Reference to the InstanceAllocator.
mode – The compute instance data mode.
- Returns:
true if instance data was computed, false otherwise.
-
virtual void bind() const override¶
Bind this glyph for rendering.
Note
Overrides the base class method.
-
virtual GLuint getID() const override¶
Get the unique ID of this glyph.
- Returns:
Unique ID of the glyph.
-
inline virtual bool isOpaque() const override¶
Check if the glyph is opaque.
Note
Overrides the base class method.
-
Glyph(Text2D &text, const U8Char &character, glm::vec2 advance = glm::vec2(0.0f, 0.0f))¶
-
class Text2D : public RaeptorCogs::TransformableGraphic2D, public RaeptorCogs::FlagSet<TextFlags>¶
Constant for normal font size.
Used as a default size for text rendering.
Note
Size is in points.
Public Functions
-
Text2D(Font &font, const U8String &content)¶
Constructor for Text2D.
Note
Initializes the text with the specified font and content.
- Parameters:
font – Reference to the Font object.
content – The text content.
-
inline Text2D(Font &font)¶
Constructor for Text2D with empty content.
Note
Initializes the text with the specified font and empty content.
- Parameters:
font – Reference to the Font object.
-
virtual void setRenderer(Singletons::Renderer *renderer) override¶
Set the renderer for this text.
Note
Overrides the base class method for adding the glyphs.
- Parameters:
renderer – Pointer to the Renderer singleton.
-
virtual void rebuildText()¶
Rebuild the text glyphs.
Note
Called when the text content, font, or size changes.
-
virtual void bind() const override¶
Bind this text for rendering.
Note
Overrides the base class method.
-
virtual GLuint getID() const override¶
Get the unique ID of this text.
- Returns:
Unique ID of the text.
-
inline virtual bool isOpaque() const override¶
Check if the text is opaque.
- Returns:
true if the text is opaque, false otherwise.
-
virtual bool isVisible() const override¶
Check if the text is visible.
- Returns:
true if the text is visible, false otherwise.
-
bool isTextDirty() const¶
Check if the text needs to be rebuilt.
- Returns:
true if the text is dirty, false otherwise.
-
virtual void setZIndex(float z) override¶
Set the Z-index of the text.
- Parameters:
z – The new Z-index value.
-
void setContent(const U8String &content)¶
Set the content of the text.
Note
Changing these properties will mark the text as dirty.
- Parameters:
content – The new text content.
-
void setFont(Font &font)¶
Set the font for the text.
Note
Changing the font will mark the text as dirty.
- Parameters:
font – Reference to the new Font object.
-
void setWordWrap(TextWordWrap wrap, float width = 0.0f)¶
Set the word wrapping mode and width.
Note
Changing these properties will mark the text as dirty.
- Parameters:
wrap – The word wrapping mode.
width – The width for word wrapping.
-
void setAlignment(TextAlignment align)¶
Set the text alignment mode.
Note
Changing the alignment will mark the text as dirty.
- Parameters:
align – The text alignment mode.
-
void setTextSize(float size)¶
Set the size of the text.
Note
Changing the size will mark the text as dirty.
- Parameters:
size – The new text size in points.
-
const U8String &getContent() const¶
Get the content of the text.
- Returns:
Reference to the text content.
-
TextWordWrap getWordWrapType() const¶
Get the word wrapping mode.
- Returns:
The word wrapping mode.
-
float getWordWrapWidth() const¶
Get the word wrap width.
- Returns:
The word wrap width.
-
TextAlignment getAlignment() const¶
Get the text alignment mode.
- Returns:
The text alignment mode.
-
float getTextSize() const¶
Get the size of the text.
- Returns:
The text size in points.
Private Functions
-
void setTextDirty(bool dirty)¶
Set the text dirty flag.
Note
Used internally to manage text state.
- Parameters:
dirty – true to mark the text as dirty, false otherwise.
Private Members
-
Font font = nullptr¶
Font used for rendering the text.
Note
Changing the font will require rebuilding the text.
-
std::vector<std::shared_ptr<Glyph>> glyphs¶
Vector of glyphs representing the text.
Note
Each glyph corresponds to a character in the text.
-
float textSize = NORMAL_FONT_SIZE¶
Size of the text.
Note
Size is in points.
-
float wordWrapWidth = 0.0f¶
Width for word wrapping.
Note
Used in conjunction with wordWrapType.
-
TextWordWrap wordWrapType = TextWordWrap::NONE¶
Word wrapping mode.
Note
Defines how text should be wrapped.
-
TextAlignment alignment = TextAlignment::LEFT¶
Text alignment mode.
Note
Defines how text should be aligned.
-
Text2D(Font &font, const U8String &content)¶