67class UIElement :
public std::enable_shared_from_this<UIElement> {
74 UIElement(
const std::string &name =
"UIElement");
179 void add_child(
const std::shared_ptr<UIElement> child);
186 void remove_child(
const std::shared_ptr<UIElement> child);
211 virtual void render(
float canvas_width,
float canvas_height,
const glm::mat4 &projection) = 0;
245 glm::vec2 get_anchor_offset(
float canvas_width,
float canvas_height)
const;
std::vector< std::shared_ptr< UIElement > > m_children
Child UI elements.
Definition ui_element.hpp:235
Anchor m_anchor
Anchor preset.
Definition ui_element.hpp:224
std::weak_ptr< UIElement > m_parent
Parent UI element.
Definition ui_element.hpp:233
void set_name(const std::string &name)
Set the name of the UI element.
Definition ui_element.hpp:123
glm::vec2 get_absolute_position(float canvas_width, float canvas_height) const
Compute the absolute screen position based on anchor and parent.
Definition ui_element.cpp:29
virtual void render(float canvas_width, float canvas_height, const glm::mat4 &projection)=0
Virtual render method to be overridden by derived classes.
void set_position(const glm::vec2 &position)
Set the position of the UI element.
Definition ui_element.hpp:86
void set_anchor(Anchor anchor)
Set the anchor of the UI element.
Definition ui_element.hpp:100
void set_size(const glm::vec2 &size)
Set the size of the UI element.
Definition ui_element.hpp:93
Anchor get_anchor() const
Get the anchor of the UI element.
Definition ui_element.hpp:144
std::shared_ptr< UIElement > get_parent() const
Get the parent UI element.
Definition ui_element.hpp:172
virtual ~UIElement()=default
Virtual destructor.
int m_render_order
Render order (z-index).
Definition ui_element.hpp:227
UIElement(const std::string &name="UIElement")
Constructor for UIElement.
Definition ui_element.cpp:10
void set_visible(bool visible)
Set visibility of the UI element.
Definition ui_element.hpp:116
const glm::vec2 & get_size() const
Get the size of the UI element.
Definition ui_element.hpp:137
glm::vec2 m_position
Position in pixels (relative to anchor).
Definition ui_element.hpp:218
std::vector< std::shared_ptr< UIElement > > get_children() const
Get all child UI elements.
Definition ui_element.hpp:193
void add_child(const std::shared_ptr< UIElement > child)
Add a child UI element.
Definition ui_element.cpp:12
const glm::vec2 & get_position() const
Get the position of the UI element.
Definition ui_element.hpp:130
std::string m_name
Name of the UI element.
Definition ui_element.hpp:215
void set_render_order(int order)
Set the render order (z-index).
Definition ui_element.hpp:109
bool m_visible
Visibility flag.
Definition ui_element.hpp:230
bool is_visible() const
Check if the UI element is visible.
Definition ui_element.hpp:158
int get_render_order() const
Get the render order.
Definition ui_element.hpp:151
const std::string & get_name() const
Get the name of the UI element.
Definition ui_element.hpp:165
glm::vec2 m_size
Size in pixels.
Definition ui_element.hpp:221
void remove_child(const std::shared_ptr< UIElement > child)
Remove a child UI element.
Definition ui_element.cpp:19
Anchor
Enumeration for UI element anchoring.
Definition ui_element.hpp:48
Forward declarations for Assimp Material structure.
Definition model_loader.cpp:12