Base class for all UI elements.
More...
#include <ui_element.hpp>
|
| | 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< UIElement > | get_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.
|
| virtual void | render (float canvas_width, float canvas_height, const glm::mat4 &projection)=0 |
| | Virtual render method to be overridden by derived classes.
|
|
|
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< UIElement > | m_parent |
| | Parent UI element.
|
|
std::vector< std::shared_ptr< UIElement > > | m_children |
| | Child UI elements.
|
Base class for all UI elements.
The UIElement class provides common functionality for UI components, including position, size, anchoring, visibility, and hierarchical parent-child relationships.
◆ UIElement()
| lmgl::ui::UIElement::UIElement |
( |
const std::string & | name = "UIElement" | ) |
|
Constructor for UIElement.
- Parameters
-
| name | Optional name for the UI element. |
◆ add_child()
| void lmgl::ui::UIElement::add_child |
( |
const std::shared_ptr< UIElement > | child | ) |
|
Add a child UI element.
- Parameters
-
| child | Shared pointer to the child element. |
◆ get_absolute_position()
| glm::vec2 lmgl::ui::UIElement::get_absolute_position |
( |
float | canvas_width, |
|
|
float | canvas_height ) const |
Compute the absolute screen position based on anchor and parent.
- Parameters
-
| canvas_width | Width of the canvas in pixels. |
| canvas_height | Height of the canvas in pixels. |
- Returns
- Absolute position in pixels.
◆ get_anchor()
| Anchor lmgl::ui::UIElement::get_anchor |
( |
| ) |
const |
|
inline |
Get the anchor of the UI element.
- Returns
- Anchor preset.
◆ get_children()
| std::vector< std::shared_ptr< UIElement > > lmgl::ui::UIElement::get_children |
( |
| ) |
const |
|
inline |
Get all child UI elements.
- Returns
- Vector of shared pointers to child elements.
◆ get_name()
| const std::string & lmgl::ui::UIElement::get_name |
( |
| ) |
const |
|
inline |
Get the name of the UI element.
- Returns
- Name of the element.
◆ get_parent()
| std::shared_ptr< UIElement > lmgl::ui::UIElement::get_parent |
( |
| ) |
const |
|
inline |
Get the parent UI element.
- Returns
- Shared pointer to the parent element, or nullptr if none.
◆ get_position()
| const glm::vec2 & lmgl::ui::UIElement::get_position |
( |
| ) |
const |
|
inline |
Get the position of the UI element.
- Returns
- Position in pixels.
◆ get_render_order()
| int lmgl::ui::UIElement::get_render_order |
( |
| ) |
const |
|
inline |
Get the render order.
- Returns
- Render order value.
◆ get_size()
| const glm::vec2 & lmgl::ui::UIElement::get_size |
( |
| ) |
const |
|
inline |
Get the size of the UI element.
- Returns
- Size in pixels.
◆ is_visible()
| bool lmgl::ui::UIElement::is_visible |
( |
| ) |
const |
|
inline |
Check if the UI element is visible.
- Returns
- True if visible, false otherwise.
◆ remove_child()
| void lmgl::ui::UIElement::remove_child |
( |
const std::shared_ptr< UIElement > | child | ) |
|
Remove a child UI element.
- Parameters
-
| child | Shared pointer to the child element. |
◆ render()
| virtual void lmgl::ui::UIElement::render |
( |
float | canvas_width, |
|
|
float | canvas_height, |
|
|
const glm::mat4 & | projection ) |
|
pure virtual |
◆ set_anchor()
| void lmgl::ui::UIElement::set_anchor |
( |
Anchor | anchor | ) |
|
|
inline |
Set the anchor of the UI element.
- Parameters
-
◆ set_name()
| void lmgl::ui::UIElement::set_name |
( |
const std::string & | name | ) |
|
|
inline |
Set the name of the UI element.
- Parameters
-
| name | New name for the element. |
◆ set_position()
| void lmgl::ui::UIElement::set_position |
( |
const glm::vec2 & | position | ) |
|
|
inline |
Set the position of the UI element.
- Parameters
-
| position | Position in pixels (x, y). |
◆ set_render_order()
| void lmgl::ui::UIElement::set_render_order |
( |
int | order | ) |
|
|
inline |
Set the render order (z-index).
Higher values render on top of lower values.
- Parameters
-
◆ set_size()
| void lmgl::ui::UIElement::set_size |
( |
const glm::vec2 & | size | ) |
|
|
inline |
Set the size of the UI element.
- Parameters
-
| size | Size in pixels (width, height). |
◆ set_visible()
| void lmgl::ui::UIElement::set_visible |
( |
bool | visible | ) |
|
|
inline |
Set visibility of the UI element.
- Parameters
-
| visible | True to show, false to hide. |
The documentation for this class was generated from the following files: