Skip to content

Container ​

cpp
class Container : public Widget;

The primary layout widget. It maps 1:1 to a Taitank flexbox node: children are laid out by Taitank, and the Container only paints its own rounded background.

cpp
#include <neoflux/widgets/container.h>

Construction ​

cpp
auto container = std::make_shared<Container>();

Adding children ​

MethodSignatureNotes
SetChildContainer& SetChild(std::shared_ptr<Widget> child)Single-child convenience (chainable, returns Container&)
childContainer& child(std::shared_ptr<Widget> child)Append one child (chainable, returns Container&)
childrenContainer& children(std::initializer_list<std::shared_ptr<Widget>> children)Append many (chainable, returns Container&)
build[[nodiscard]] std::shared_ptr<Widget> build()Inherited from Widget; chain terminator

See the Fluent API guide for the chained idiom.

Layout knobs (all chainable, return Container&) ​

MethodSignatureMeaning
SetFlexDirectionContainer& SetFlexDirection(FlexDirection d)Main axis. kRow / kRowReverse / kColumn / kColumnReverse. Default kColumn.
SetJustifyContentContainer& SetJustifyContent(HAlign a)Main-axis alignment: HAlign::kLeft/kCenter/kRight.
SetAlignItemsContainer& SetAlignItems(VAlign a)Cross-axis alignment: VAlign::kTop/kCenter/kBottom.
SetFlexGrowContainer& SetFlexGrow(float grow)How much this container expands to fill parent space.
SetWidthContainer& SetWidth(float w)Fixed width; 0 = flexible.
SetHeightContainer& SetHeight(float h)Fixed height; 0 = flexible.

Spacing & appearance (chainable, return Container&) ​

MethodSignatureMeaning
SetPaddingContainer& SetPadding(const EdgeInsets& p)Inner padding.
SetMarginContainer& SetMargin(const EdgeInsets& m)Outer margin.
SetBackgroundColorContainer& SetBackgroundColor(const Color& c)Background fill.
SetBorderRadiusContainer& SetBorderRadius(float r)Corner radius in px; 0 = sharp.

Example ​

cpp
auto card = std::make_shared<Container>();
card->SetFlexDirection(FlexDirection::kColumn)
    .SetPadding({.left = 16, .top = 12, .right = 16, .bottom = 12})
    .SetBackgroundColor({.r = 255, .g = 255, .b = 255, .a = 255})
    .SetBorderRadius(8.0F);
card->AddChild(title);
card->AddChild(body);

Equivalent fluent form:

cpp
auto card = std::make_shared<Container>()
    ->SetFlexDirection(FlexDirection::kColumn)
    .SetPadding({.left = 16, .top = 12, .right = 16, .bottom = 12})
    .SetBackgroundColor({255, 255, 255, 255})
    .SetBorderRadius(8.0F)
    .children({title, body})
    .build();

Comments

Released under the GPL-3.0 License.