Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
Flint::UINode Class Reference

Abstract base class for all UI widgets, managing hierarchy tracking, layout passes, and input routing. More...

#include <flint/ui/ui-node.h>

+ Inheritance diagram for Flint::UINode:
+ Collaboration diagram for Flint::UINode:

Public Member Functions

FLINT_API void setContext (UIContext *context)
 Recursively propagates a pointer back to the parent-managing workspace layer.
 
FLINT_API void addChild (std::unique_ptr< UINode > child)
 Inserts a child widget to live inside this layout element container boundary.
 
FLINT_API void setPosition (Vec2f position)
 Updates the relative local rendering position coordinates of this element block.
 
Vec2f getPosition () const
 Get the node's relative local position.
 
FLINT_API void setSize (Vec2f size)
 Assigns a manual static override layout budget footprint dimensions limit.
 
Vec2f getSize () const
 Get the node's base size.
 
FLINT_API void setVisible (bool visible)
 Sets widget visibility.
 
FLINT_API void setEnabled (bool enabled)
 Enables or disables user interaction for this widget.
 
FLINT_API void setID (std::string id)
 Sets a unique string identifier for this node.
 
FLINT_API const std::string & getId () const
 Gets the unique lookup ID string of this node.
 
FLINT_API const Rect< float > & getLayoutRect () const
 Gets the final screen-space bounding box calculated during the arrange pass.
 
bool isVisible () const
 
bool isEnabled () const
 
Vec2f getDesiredSize () const
 Get the node's requested size from the measure pass.
 
const std::vector< std::unique_ptr< UINode > > & getChildren () const
 Get the list of this node's child nodes.
 
virtual void setFocused (bool focused)
 Sets whether this node is currently focused.
 
FLINT_API void setText (std::string text)
 Sets the text content for widgets that display text.
 
FLINT_API const std::string & getText () const
 Gets the current text content of the widget.
 
FLINT_API void setFontSize (uint16_t fontSize)
 Set the rendering font size in points.
 
FLINT_API uint16_t getFontSize () const
 
FLINT_API void setColor (Color color)
 Sets the base color of the widget.
 
FLINT_API Color getColor () const
 
virtual void setNormalColor (Color color)
 Sets the base color of the widget.
 
virtual void setActiveColor (Color color)
 Sets visual colors used when inputs hover across or lock selections on the widget container.
 
virtual FLINT_API void measure (UIConstraints constraints)
 Pass 1 of the layout engine: Crawls branches recursively to compute base display boundaries requested by child assets.
 
virtual FLINT_API void arrange (const Rect< float > &rect)
 Pass 2 of the layout engine: Evaluates layout adjustments to pin final screen coordinate values to the tree structures.
 
virtual FLINT_API void handleEvent (const UIEvent &event)
 Traverses active child collections to pass translated physical hardware inputs down to focused widgets.
 
virtual FLINT_API void render (UICanvas &canvas) const
 Pushes current styling rules and geometries straight down to the active pipeline vertex drawing queue arrays.
 
virtual bool isFocusable () const
 Dictates if keyboard selection trackers or gamepad vectors can snap control focuses onto this item.
 
virtual FLINT_API bool hitTest (Vec2f point) const
 Computes true if a vector coordinate sits inside the spatial arrangement bounding tracking layout box.
 
void setFont (std::string name)
 Assigns a custom typography description token mapping back to cached font elements.
 
void setFontWeight (uint16_t weight)
 Assigns thickness parameters across structural type vectors (e.g., 400 for regular, 700 for bold).
 
void setTextOpticalBias (float bias)
 
float getTextOpticalBias () const
 
virtual bool consumesDirectionalInput () const
 Dictates whether this widget captures directional inputs instead of passing them to focus navigation.
 
bool isFocused () const
 
FLINT_API void setHorizontalAlign (UIAlign align)
 
FLINT_API void setVerticalAlign (UIAlign align)
 
FLINT_API UIAlign getHorizontalAlign () const
 
FLINT_API UIAlign getVerticalAlign () const
 
FLINT_API void setLayoutGrow (float grow)
 Assigns dynamic expansion multipliers used to balance alignment distributions inside sequential layout panels.
 
FLINT_API float getLayoutGrow () const
 Gets the dynamic expansion weight used inside stack layout grids.
 

Protected Member Functions

virtual const Color & currentColor () const
 Dynamically picks active color metrics using real-time interaction states.
 

Protected Attributes

std::string m_id
 
UINode * m_parent = nullptr
 
std::vector< std::unique_ptr< UINode > > m_children
 
Vec2f m_localPosition {}
 
Vec2f m_desiredSize {}
 
Vec2f m_baseSize {}
 
Rect< float > m_layoutRect {}
 
bool m_visible = true
 
bool m_enabled = true
 
float m_displayScale = 1.0f
 
std::string m_fontName
 
uint16_t m_fontWeight = 400
 
uint16_t m_fontSize = 16
 
float m_textOpticalBias = 0.f
 
std::string m_text
 
Color m_normalColor = Colors::white
 
Color m_activeColor = {0, 255, 0, 255}
 
bool m_hovered = false
 
bool m_focused = false
 
UIAlign m_horizontalAlign = UIAlign::Stretch
 
UIAlign m_verticalAlign = UIAlign::Start
 
float m_layoutGrow = 0.f
 

Detailed Description

Abstract base class for all UI widgets, managing hierarchy tracking, layout passes, and input routing.

Note
Node trees can include their own child-nodes. For example, a UIPanel can house a UIButton widget, which can in turn contain a UISprite. Example:
├── UIButton
│ └── UISprite
└── UISlider
A clickable interactive text button widget supporting custom sprite icons.
Definition button.h:26
A container widget that arranges child nodes into sequential layout distributions.
Definition panel.h:19
An interactive value-selector bar supporting mouse dragging and gamepad focus adjustments.
Definition slider.h:17
A static texture rendering frame component wrapper.
Definition sprite.h:18

Definition at line 31 of file ui-node.h.

Member Function Documentation

◆ addChild()

FLINT_API void Flint::UINode::addChild ( std::unique_ptr< UINode > child)

Inserts a child widget to live inside this layout element container boundary.

Note
This node assumes complete memory ownership of the sub-element unique pointer. The target child automatically inherits this element's parent tracking context pointers.
Parameters
childUnique pointer configuration block wrapper holding the sub-widget instance.

◆ arrange()

virtual FLINT_API void Flint::UINode::arrange ( const Rect< float > & rect)
virtual

Pass 2 of the layout engine: Evaluates layout adjustments to pin final screen coordinate values to the tree structures.

Parameters
rectThe absolute coordinate grid budget segment assigned to this specific node box by the parent manager.

Reimplemented in Flint::UIButton, Flint::UILabel, Flint::UIPanel, Flint::UISlider, and Flint::UISprite.

◆ consumesDirectionalInput()

virtual bool Flint::UINode::consumesDirectionalInput ( ) const
inlinevirtual

Dictates whether this widget captures directional inputs instead of passing them to focus navigation.

Note
Override this to return true for widgets that use keyboard or gamepad navigation for internal values, like adjusting a slider or moving a text box caret.

Reimplemented in Flint::UISlider.

Definition at line 199 of file ui-node.h.

◆ currentColor()

virtual const Color & Flint::UINode::currentColor ( ) const
inlineprotectedvirtual

Dynamically picks active color metrics using real-time interaction states.

Reimplemented in Flint::UISlider.

Definition at line 247 of file ui-node.h.

◆ getChildren()

const std::vector< std::unique_ptr< UINode > > & Flint::UINode::getChildren ( ) const
inlinenodiscard

Get the list of this node's child nodes.

Definition at line 105 of file ui-node.h.

◆ getDesiredSize()

Vec2f Flint::UINode::getDesiredSize ( ) const
inlinenodiscard

Get the node's requested size from the measure pass.

Definition at line 100 of file ui-node.h.

◆ getPosition()

Vec2f Flint::UINode::getPosition ( ) const
inline

Get the node's relative local position.

Definition at line 54 of file ui-node.h.

◆ getSize()

Vec2f Flint::UINode::getSize ( ) const
inline

Get the node's base size.

Definition at line 62 of file ui-node.h.

◆ getTextOpticalBias()

float Flint::UINode::getTextOpticalBias ( ) const
inlinenodiscard

Definition at line 190 of file ui-node.h.

◆ handleEvent()

virtual FLINT_API void Flint::UINode::handleEvent ( const UIEvent & event)
virtual

Traverses active child collections to pass translated physical hardware inputs down to focused widgets.

Reimplemented in Flint::UIButton, and Flint::UISlider.

◆ hitTest()

virtual FLINT_API bool Flint::UINode::hitTest ( Vec2f point) const
virtual

Computes true if a vector coordinate sits inside the spatial arrangement bounding tracking layout box.

Reimplemented in Flint::UISlider.

◆ isEnabled()

bool Flint::UINode::isEnabled ( ) const
inlinenodiscard

Definition at line 95 of file ui-node.h.

◆ isFocusable()

virtual bool Flint::UINode::isFocusable ( ) const
inlinevirtual

Dictates if keyboard selection trackers or gamepad vectors can snap control focuses onto this item.

Reimplemented in Flint::UIButton, and Flint::UISlider.

Definition at line 166 of file ui-node.h.

◆ isFocused()

bool Flint::UINode::isFocused ( ) const
inlinenodiscard

Definition at line 203 of file ui-node.h.

◆ isVisible()

bool Flint::UINode::isVisible ( ) const
inlinenodiscard

Definition at line 91 of file ui-node.h.

◆ measure()

virtual FLINT_API void Flint::UINode::measure ( UIConstraints constraints)
virtual

Pass 1 of the layout engine: Crawls branches recursively to compute base display boundaries requested by child assets.

Parameters
constraintsSpatial boundaries and global display density multipliers passed down by parent vectors.

Reimplemented in Flint::UIButton, Flint::UILabel, Flint::UIPanel, Flint::UISlider, and Flint::UISprite.

◆ render()

virtual FLINT_API void Flint::UINode::render ( UICanvas & canvas) const
virtual

Pushes current styling rules and geometries straight down to the active pipeline vertex drawing queue arrays.

Reimplemented in Flint::UIButton, Flint::UILabel, Flint::UIPanel, Flint::UISlider, and Flint::UISprite.

◆ setActiveColor()

virtual void Flint::UINode::setActiveColor ( Color color)
inlinevirtual

Sets visual colors used when inputs hover across or lock selections on the widget container.

Definition at line 136 of file ui-node.h.

◆ setContext()

FLINT_API void Flint::UINode::setContext ( UIContext * context)

Recursively propagates a pointer back to the parent-managing workspace layer.

Note
This acts as the context assembly loop. If a node mounting to a new tree carries an identification string that collides with an existing registered asset, its ID is cleared to prevent tree lookup failures.
Parameters
contextNon-owning reference link to the managing UIContext workspace canvas.

◆ setEnabled()

FLINT_API void Flint::UINode::setEnabled ( bool enabled)

Enables or disables user interaction for this widget.

Note
Disabled widgets remain fully visible but ignore all user interaction.

◆ setFocused()

virtual void Flint::UINode::setFocused ( bool focused)
inlinevirtual

Sets whether this node is currently focused.

Reimplemented in Flint::UISlider.

Definition at line 110 of file ui-node.h.

◆ setFont()

void Flint::UINode::setFont ( std::string name)
inline

Assigns a custom typography description token mapping back to cached font elements.

Definition at line 176 of file ui-node.h.

◆ setFontWeight()

void Flint::UINode::setFontWeight ( uint16_t weight)
inline

Assigns thickness parameters across structural type vectors (e.g., 400 for regular, 700 for bold).

Definition at line 182 of file ui-node.h.

◆ setID()

FLINT_API void Flint::UINode::setID ( std::string id)

Sets a unique string identifier for this node.

Warning
If the ID is already taken by another widget in the same UIContext, the assignment is rejected and a warning is logged.
Parameters
idThe unique tracking name string for this widget.
See also
UIContext::findById

◆ setNormalColor()

virtual void Flint::UINode::setNormalColor ( Color color)
inlinevirtual

Sets the base color of the widget.

Deprecated
Same as UINode::setColor and will eventually be deleted.

Definition at line 130 of file ui-node.h.

◆ setTextOpticalBias()

void Flint::UINode::setTextOpticalBias ( float bias)
inline

Definition at line 186 of file ui-node.h.

◆ setVisible()

FLINT_API void Flint::UINode::setVisible ( bool visible)

Sets widget visibility.

Note
Passing false completely hides the node (and its children), causing it to not affect the layout of sibling nodes or receive any user interaction.

Member Data Documentation

◆ m_activeColor

Color Flint::UINode::m_activeColor = {0, 255, 0, 255}
protected

Definition at line 243 of file ui-node.h.

◆ m_baseSize

Vec2f Flint::UINode::m_baseSize {}
protected

Explicit developer-overridden static size limits.

Definition at line 227 of file ui-node.h.

◆ m_children

std::vector<std::unique_ptr<UINode> > Flint::UINode::m_children
protected

Definition at line 222 of file ui-node.h.

◆ m_desiredSize

Vec2f Flint::UINode::m_desiredSize {}
protected

Dimensions requested by this node during the measure pass.

Definition at line 226 of file ui-node.h.

◆ m_displayScale

float Flint::UINode::m_displayScale = 1.0f
protected

Definition at line 233 of file ui-node.h.

◆ m_enabled

bool Flint::UINode::m_enabled = true
protected

Definition at line 232 of file ui-node.h.

◆ m_focused

bool Flint::UINode::m_focused = false
protected

Definition at line 252 of file ui-node.h.

◆ m_fontName

std::string Flint::UINode::m_fontName
protected

Definition at line 235 of file ui-node.h.

◆ m_fontSize

uint16_t Flint::UINode::m_fontSize = 16
protected

Definition at line 237 of file ui-node.h.

◆ m_fontWeight

uint16_t Flint::UINode::m_fontWeight = 400
protected

Definition at line 236 of file ui-node.h.

◆ m_horizontalAlign

UIAlign Flint::UINode::m_horizontalAlign = UIAlign::Stretch
protected

Definition at line 254 of file ui-node.h.

◆ m_hovered

bool Flint::UINode::m_hovered = false
protected

Definition at line 251 of file ui-node.h.

◆ m_id

std::string Flint::UINode::m_id
protected

Definition at line 220 of file ui-node.h.

◆ m_layoutGrow

float Flint::UINode::m_layoutGrow = 0.f
protected

Definition at line 256 of file ui-node.h.

◆ m_layoutRect

Rect<float> Flint::UINode::m_layoutRect {}
protected

Final calculated screen-space absolute layout bounding box.

Definition at line 229 of file ui-node.h.

◆ m_localPosition

Vec2f Flint::UINode::m_localPosition {}
protected

Relative rendering offset coordinates from the parent's origin.

Definition at line 225 of file ui-node.h.

◆ m_normalColor

Color Flint::UINode::m_normalColor = Colors::white
protected

Definition at line 242 of file ui-node.h.

◆ m_parent

UINode* Flint::UINode::m_parent = nullptr
protected

Definition at line 221 of file ui-node.h.

◆ m_text

std::string Flint::UINode::m_text
protected

Definition at line 240 of file ui-node.h.

◆ m_textOpticalBias

float Flint::UINode::m_textOpticalBias = 0.f
protected

Definition at line 238 of file ui-node.h.

◆ m_verticalAlign

UIAlign Flint::UINode::m_verticalAlign = UIAlign::Start
protected

Definition at line 255 of file ui-node.h.

◆ m_visible

bool Flint::UINode::m_visible = true
protected

Definition at line 231 of file ui-node.h.


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