Container
Container
Section titled “Container”#include <Container.hpp>Inherits:
Widget
A widget that arranges child widgets using a layout engine.
Container is the primary way to organize multiple widgets. It holds children and uses a Layout to position them. By default, it uses VerticalStackLayout, but you can specify any Layout (Grid, Absolute, custom, etc.).
Container is not focusable itself - focus passes through to focusable children.
Usage patterns:
// Default vertical stackauto container = std::make_shared<Container>();container->addChild(std::make_shared<Label>("Title"));container->addChild(std::make_shared<Button>("Click me"));
// Horizontal stackauto hbox = std::make_shared<Container>( std::make_shared<StackLayout>(Axis::Horizontal));
// Grid layoutauto grid = std::make_shared<Container>( std::make_shared<GridLayout>(2, 3) // 2 cols, 3 rows);Public Methods
Section titled “Public Methods”| Return | Name | Description |
|---|---|---|
Container inline explicit | Creates a container with the specified layout. | |
void | addChild | Adds a child widget to the container. |
void | setLayout inline | Changes the layout engine. |
core::Size | measure virtual | Measures how much space this widget needs. |
void | layout virtual | Positions and sizes this widget and its children. |
std::vector< std::shared_ptr< Widget > > | getChildren virtual const inline | Returns this widget’s children. |
Container
Section titled “Container”inline explicit
inline explicit Container(std::shared_ptr< core::Layout > layout)Creates a container with the specified layout.
Parameters
Section titled “Parameters”layoutThe layout engine to use (default: VerticalStackLayout)
addChild
Section titled “addChild”void addChild(std::shared_ptr< Widget > child, core::LayoutSpec spec)Adds a child widget to the container.
The LayoutSpec controls how the child is sized and positioned within its slot.
Parameters
Section titled “Parameters”-
childThe widget to add -
specLayout specification for this child (optional)
Example Usage:
auto container = std::make_shared<Container>();auto button = std::make_shared<Button>("Flex");container->addChild(button, LayoutSpec{.ratio = 2.0f}); // Double weightsetLayout
Section titled “setLayout”inline
inline void setLayout(std::shared_ptr< core::Layout > l)Changes the layout engine.
Parameters
Section titled “Parameters”lThe new layout to use
measure
Section titled “measure”virtual
virtual core::Size measure(int availW, int availH)Measures how much space this widget needs.
Called during the measurement pass to determine widget size requirements. Should return the preferred size based on available space.
Parameters
Section titled “Parameters”-
availWMaximum available width (may be ignored by widget) -
availHMaximum available height (may be ignored by widget)
Returns
Section titled “Returns”The Size this widget wants, or needs at minimum
layout
Section titled “layout”virtual
virtual void layout(int x, int y, int width, int height)Positions and sizes this widget and its children.
Called after measurement to actually place the widget at a specific location. If your widget has children, you must call their layout() methods here.
Parameters
Section titled “Parameters”-
xThe X coordinate for this widget -
yThe Y coordinate for this widget -
widthThe width allocated to this widget -
heightThe height allocated to this widget
getChildren
Section titled “getChildren”virtual const inline
virtual inline std::vector< std::shared_ptr< Widget > > getChildren() constReturns this widget’s children.
Returns
Section titled “Returns”Vector of child widgets (empty if no children)
Protected Methods
Section titled “Protected Methods”| Return | Name | Description |
|---|---|---|
void | drawContent virtual | Draws this widget’s content. |
drawContent
Section titled “drawContent”virtual
virtual void drawContent(backend::Buffer & buf, core::Rect inner)Draws this widget’s content.
Called by render() after background and borders are drawn. This is where you should draw your widget’s actual content. The inner rectangle accounts for borders and padding.
Parameters
Section titled “Parameters”-
bufThe buffer to draw to -
innerThe inner rectangle (excluding border/padding)
Private Attributes
Section titled “Private Attributes”| Return | Name | Description |
|---|---|---|
std::shared_ptr< core::Layout > | layoutEngine | |
std::vector< core::ChildSlot > | children |
layoutEngine
Section titled “layoutEngine”std::shared_ptr< core::Layout > layoutEnginechildren
Section titled “children”std::vector< core::ChildSlot > children