[ Widgets ]
Hbox
koto::Hbox is a composite Widget container that owns child widgets on the heap via std::unique_ptr<Widget> and draws them left-to-right using Layout::horizontal (Header: koto/hbox.hpp).
Quick example
Section titled “Quick example”Hbox row;row.add<Box>(Constraint::fixed(12)).title("Left").border_style(BorderStyle::Single);row.add<Box>(Constraint::fill()).title("Right").border_style(BorderStyle::Rounded);row.draw(frame, hbox_area);┌── Left ──┐╭────── Right ───────╮│ ││ │└──────────┘╰────────────────────╯Behavior
Section titled “Behavior”- Child ownership and fluent configuration:
Hbox::add<T>(Constraint c, Args&&... args)constructs astd::unique_ptr<T>(std::forward<Args>(args)...), appends{std::move(widget), c}tom_children, and returnsT&so you can chain widget setter methods directly (include/koto/hbox.hpp:15-25). - Zero-heap layout path for
<= 16children: Whenm_children.size() <= LayoutResult::InlineCapacity(16),Hbox::draw()copies child constraints into a stackstd::array<Constraint, 16>, callsLayout::horizontal(area, std::span<const Constraint>(...)), and invokesm_children[i].widget->draw(frame, rect[i]). Whenm_children.size() > 16, it allocates astd::vector<Constraint>before callingLayout::horizontal(src/hbox.cpp:16-42).
Methods
Section titled “Methods”| Method | Description | Default |
|---|---|---|
Hbox() | Default-constructs an empty horizontal container (move-only due to std::unique_ptr<Widget>). | m_children empty |
add<T>(Constraint c, Args&&... args) | Constructs child widget T(args...) with horizontal constraint c, stores it, and returns T&. | None |
draw(Frame& frame, Area area) | Partitions area horizontally and draws each child into its corresponding sub-area. | None |
Gotchas
Section titled “Gotchas”- Heap allocation per child: Although
Hbox::draw()avoids heap allocation for theConstraintarray whenm_children.size() <= 16, every call toHbox::add<T>(...)allocates the childWidgeton the heap viastd::make_unique<T>(...). In hot 60 FPSon_rendercallbacks, partitioning areas directly withLayout::horizontal(area, {...})and drawing stack-allocated widgets avoids per-framestd::make_uniqueallocations. - Move-only container: Because
m_childrenholdsstd::unique_ptr<Widget>,Hboxcannot be copied.