lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
lmgl::ui::Text Class Reference

Text UI element for rendering strings. More...

#include <text.hpp>

Inheritance diagram for lmgl::ui::Text:
lmgl::ui::UIElement

Public Member Functions

 Text (const std::string &text="", const std::string &name="Text")
 Constructor for Text.
 ~Text () override=default
 Destructor for Text.
void set_text (const std::string &text)
 Set the text string.
const std::string & get_text () const
 Get the text string.
void set_font (std::shared_ptr< Font > font)
 Set the font.
std::shared_ptr< Fontget_font () const
 Get the current font.
void set_color (const glm::vec4 &color)
 Set the text color.
const glm::vec4 & get_color () const
 Get the text color.
void set_alignment (TextAlign align)
 Set text alignment.
TextAlign get_alignment () const
 Get text alignment.
void render (float canvas_width, float canvas_height, const glm::mat4 &projection) override
 Render the text.
Public Member Functions inherited from lmgl::ui::UIElement
 UIElement (const std::string &name="UIElement")
 Constructor for UIElement.
virtual ~UIElement ()=default
 Virtual destructor.
void set_position (const glm::vec2 &position)
 Set the position of the UI element.
void set_size (const glm::vec2 &size)
 Set the size of the UI element.
void set_anchor (Anchor anchor)
 Set the anchor of the UI element.
void set_render_order (int order)
 Set the render order (z-index).
void set_visible (bool visible)
 Set visibility of the UI element.
void set_name (const std::string &name)
 Set the name of the UI element.
const glm::vec2 & get_position () const
 Get the position of the UI element.
const glm::vec2 & get_size () const
 Get the size of the UI element.
Anchor get_anchor () const
 Get the anchor of the UI element.
int get_render_order () const
 Get the render order.
bool is_visible () const
 Check if the UI element is visible.
const std::string & get_name () const
 Get the name of the UI element.
std::shared_ptr< UIElementget_parent () const
 Get the parent UI element.
void add_child (const std::shared_ptr< UIElement > child)
 Add a child UI element.
void remove_child (const std::shared_ptr< UIElement > child)
 Remove a child UI element.
std::vector< std::shared_ptr< UIElement > > get_children () const
 Get all child UI elements.
glm::vec2 get_absolute_position (float canvas_width, float canvas_height) const
 Compute the absolute screen position based on anchor and parent.

Additional Inherited Members

Protected Attributes inherited from lmgl::ui::UIElement
std::string m_name
 Name of the UI element.
glm::vec2 m_position {0.0f, 0.0f}
 Position in pixels (relative to anchor).
glm::vec2 m_size {100.0f, 100.0f}
 Size in pixels.
Anchor m_anchor {Anchor::TopLeft}
 Anchor preset.
int m_render_order {0}
 Render order (z-index).
bool m_visible {true}
 Visibility flag.
std::weak_ptr< UIElementm_parent
 Parent UI element.
std::vector< std::shared_ptr< UIElement > > m_children
 Child UI elements.

Detailed Description

Text UI element for rendering strings.

The Text class renders text using a Font, with support for color, alignment, and automatic size calculation.

Constructor & Destructor Documentation

◆ Text()

lmgl::ui::Text::Text ( const std::string & text = "",
const std::string & name = "Text" )

Constructor for Text.

Parameters
textInitial text string.
nameOptional name for the element.

Member Function Documentation

◆ get_alignment()

TextAlign lmgl::ui::Text::get_alignment ( ) const
inline

Get text alignment.

Returns
Current alignment.

◆ get_color()

const glm::vec4 & lmgl::ui::Text::get_color ( ) const
inline

Get the text color.

Returns
RGBA color.

◆ get_font()

std::shared_ptr< Font > lmgl::ui::Text::get_font ( ) const
inline

Get the current font.

Returns
Shared pointer to the font.

◆ get_text()

const std::string & lmgl::ui::Text::get_text ( ) const
inline

Get the text string.

Returns
Current text string.

◆ render()

void lmgl::ui::Text::render ( float canvas_width,
float canvas_height,
const glm::mat4 & projection )
overridevirtual

Render the text.

Parameters
canvas_widthWidth of the canvas in pixels.
canvas_heightHeight of the canvas in pixels.
projectionProjection matrix for UI rendering.

Implements lmgl::ui::UIElement.

◆ set_alignment()

void lmgl::ui::Text::set_alignment ( TextAlign align)
inline

Set text alignment.

Parameters
alignAlignment option.

◆ set_color()

void lmgl::ui::Text::set_color ( const glm::vec4 & color)
inline

Set the text color.

Parameters
colorRGBA color (values 0.0-1.0).

◆ set_font()

void lmgl::ui::Text::set_font ( std::shared_ptr< Font > font)

Set the font.

Parameters
fontShared pointer to the font.

◆ set_text()

void lmgl::ui::Text::set_text ( const std::string & text)

Set the text string.

Parameters
textNew text string.

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