[ Widgets ]
Vbox
koto::Vbox is a composite Widget container that owns child widgets via std::unique_ptr<Widget> and draws them top-to-bottom using Layout::vertical (Header: koto/vbox.hpp).
Quick example
Section titled “Quick example”Vbox col;col.add<Box>(Constraint::fixed(3)).title("Top").border_style(BorderStyle::Rounded);col.add<Box>(Constraint::fill()).title("Bottom").border_style(BorderStyle::Single);col.draw(frame, vbox_area);╭─────────── Top ────────────╮│ │╰────────────────────────────╯┌────────── Bottom ──────────┐│ │└────────────────────────────┘Behavior
Section titled “Behavior”- Child ownership and fluent chaining:
Vbox::add<T>(Constraint c, Args&&... args)allocates astd::unique_ptr<T>(std::forward<Args>(args)...), appends{std::move(widget), c}tom_children, and returns aT&reference so you can chain configuration calls on the newly added child (include/koto/vbox.hpp:15-25). - Nesting
HboxandVbox: Because bothVboxandHboxderive fromkoto::Widget, you can nest anHboxinside aVboxviaauto& row = vbox.add<Hbox>(Constraint::fill());and populaterow.add<...>(...). - Stack constraint buffer for
<= 16children: Whenm_children.size() <= LayoutResult::InlineCapacity(16),Vbox::draw()copies the child constraints into a stackstd::array<Constraint, 16>, callsLayout::vertical(area, std::span<const Constraint>(...)), and draws each child intorect[i](src/vbox.cpp:16-28).
Methods
Section titled “Methods”| Method | Description | Default |
|---|---|---|
Vbox() | Default-constructs an empty vertical container (move-only due to std::unique_ptr<Widget>). | m_children empty |
add<T>(Constraint c, Args&&... args) | Constructs child widget T(args...) with vertical constraint c, stores it, and returns T&. | None |
draw(Frame& frame, Area area) | Partitions area vertically and draws each child into its corresponding sub-area. | None |
Gotchas
Section titled “Gotchas”- Per-child heap allocation in
add<T>: Callingvbox.add<T>(...)invokesstd::make_unique<T>(...). To avoid heap allocations insideon_render, either construct a staticVboxwhen children do not depend on per-frame state or useLayout::vertical(area, {...})with stack-allocated widgets.