A multi-purpose dynamic layout for arranging nodes along an axis. Can be used to arrange nodes in a single line, a grid, or a flex layout. The RowLayout and ColumnLayout classes function as simple thin wrappers over AxisLayout. The positioning of individual nodes in the layout can be further controlled using AxisLayoutOptions
Class AxisLayout
#include <Geode/ui/Layout.hpp>
⚠️ Calculating layouts can get increasingly expensive for large amounts of child nodes being fit into a small space - while this should never prove a real performance concern as most layouts only have a few hundred children at the very most, be aware that you probably shouldn't call CCNode::updateLayout every frame for a menu with thousands of children
Examples1
auto menu = CCMenu::create();
// The menu's children will be arranged horizontally, unless they overflow
// the content size width in which case a new line will be inserted and
// aligned to the left. The menu automatically will automatically grow in
// height to fit all the rows
menu->setLayout(
RowLayout::create()
->setGap(10.f)
->setGrowCrossAxis(true)
->setAxisAlignment(AxisAlignment::Start)
);
menu->setContentSize({ 200.f, 0.f });
menu->addChild(...);
menu->updateLayout();
Public static methods1
staticgeode::AxisLayout*create(geode::Axisaxis)
Create a new AxisLayout. Note that this class is not automatically managed by default, so you must assign it to a CCNode or manually manage the memory yourself. See the chainable setters on AxisLayout for what options you can customize for the layout
axis
ℹ For convenience, you can use the RowLayout and ColumnLayout classes, which are just thin wrappers over AxisLayout
Public member functions27
virtualvoidapply()
virtualcocos2d::CCSizegetSizeHint()const
geode::AxisgetAxis()const
geode::AxisAlignmentgetAxisAlignment()const
geode::AxisAlignmentgetCrossAxisAlignment()const
geode::AxisAlignmentgetCrossAxisLineAlignment()const
floatgetGap()const
boolgetAxisReverse()const
boolgetCrossAxisReverse()const
boolgetAutoScale()const
boolgetGrowCrossAxis()const
boolgetCrossAxisOverflow()const
std::optional<float>getAutoGrowAxis()const
floatgetDefaultMinScale()const
floatgetDefaultMaxScale()const
geode::AxisLayout*setAxis(geode::Axisaxis)
geode::AxisLayout*setAxisAlignment(geode::AxisAlignmentalign)
Sets where to align the target node’s children on the main axis (X-axis for Row, Y-axis for Column)
geode::AxisLayout*setCrossAxisAlignment(geode::AxisAlignmentalign)
Sets where to align the target node’s children on the cross-axis (Y-axis for Row, X-axis for Column)
geode::AxisLayout*setCrossAxisLineAlignment(geode::AxisAlignmentalign)
Sets where to align the target node’s children on the cross-axis for each row (Y-axis for Row, X-axis for Column)
geode::AxisLayout*setGap(floatgap)
The spacing between the children of the node this layout applies to. Measured as the space between their edges, not centres. Does not apply on the main / cross axis if their alignment is AxisAlignment::Even
geode::AxisLayout*setAxisReverse(boolreverse)
Whether to reverse the direction of the children in this layout or not
geode::AxisLayout*setCrossAxisReverse(boolreverse)
Whether to reverse the direction of the rows on the cross-axis or not
geode::AxisLayout*setAutoScale(boolenable)
If enabled, then the layout may scale the target’s children if they are about to overflow. Assumes that all the childrens’ intended scale is 1
geode::AxisLayout*setGrowCrossAxis(boolexpand)
If true, if the main axis overflows extra nodes will be placed on new rows/columns on the cross-axis
geode::AxisLayout*setCrossAxisOverflow(boolallow)
If true, the cross-axis content size of the target node will be automatically adjusted to fit the children
geode::AxisLayout*setAutoGrowAxis()
If not std::nullopt
, then the axis will be automatically extended to fit all items in a single row whose minimum length is the specified. Useful for scrollable list layer contents
geode::AxisLayout*setDefaultScaleLimits(floatmin,floatmax)
Set the default minimum/maximum scales for nodes in the layout