UILayout¶
Base class for UI layout containers.
Description¶
UILayout is the base class for all layout containers. Layouts organize UI elements automatically, handling positioning, spacing, and optional scrolling. Layouts are themselves UI elements that can be added to scenes.
Namespace¶
Inheritance¶
- Inherits from:
UIElement - Inherited by:
UIVerticalLayout,UIHorizontalLayout,UIGridLayout,UIAnchorLayout
ScrollBehavior Enum¶
Defines how scrolling behaves in layouts.
Values: - ScrollBehavior::NONE: No scrolling allowed - ScrollBehavior::SCROLL: Scroll freely within bounds - ScrollBehavior::CLAMP: Scroll but clamp to content bounds
Public Methods¶
virtual void addElement(UIElement* element) = 0¶
Adds a UI element to the layout. Must be implemented by derived classes.
Parameters: - element (UIElement*): Pointer to the element to add
virtual void removeElement(UIElement* element) = 0¶
Removes a UI element from the layout. Must be implemented by derived classes.
Parameters: - element (UIElement*): Pointer to the element to remove
virtual void updateLayout() = 0¶
Recalculates positions of all elements in the layout. Must be implemented by derived classes.
Returns: - void
Notes: - Should be called automatically when elements are added/removed
virtual void handleInput(const InputManager& input) = 0¶
Handles input for layout navigation (scroll, selection, etc.). Must be implemented by derived classes.
Parameters: - input (const pixelroot32::input::InputManager&): Reference to the InputManager
void setPadding(float p)¶
Sets the padding (internal spacing) of the layout.
Parameters: - p (float): Padding value in pixels
Returns: - void
Notes: - Layout is automatically recalculated
float getPadding() const¶
Gets the current padding.
Returns: - float: Padding value in pixels
void setSpacing(float s)¶
Sets the spacing between elements.
Parameters: - s (float): Spacing value in pixels
Returns: - void
Notes: - Layout is automatically recalculated - Default: 4.0 pixels
float getSpacing() const¶
Gets the current spacing.
Returns: - float: Spacing value in pixels
size_t getElementCount() const¶
Gets the number of elements in the layout.
Returns: - size_t: Element count
UIElement* getElement(size_t index) const¶
Gets the element at a specific index.
Parameters: - index (size_t): Element index
Returns: - UIElement*: Pointer to the element, or nullptr if index is invalid
void clearElements()¶
Clears all elements from the layout.
Returns: - void
Notes: - Elements are not deleted (you must manage their lifetimes) - Layout is automatically recalculated
Protected Members¶
std::vector<UIElement*> elements: List of child elementsfloat padding: Internal paddingfloat spacing: Spacing between elements (default: 4.0)float scrollOffset: Current scroll offsetbool enableScroll: Whether scrolling is enabledScrollBehavior scrollBehavior: Scroll behavior mode
See Also¶
- UIElement - Base UI element class
- UIVerticalLayout - Vertical layout
- UIHorizontalLayout - Horizontal layout
- UIGridLayout - Grid layout
- UIAnchorLayout - Anchor layout
- Manual - User Interface
- API Overview