Skip to content

LayoutSpec

#include <Layout.hpp>

Specifies how a widget should be sized and positioned within its layout slot.

This is passed to Container::addChild() to control layout behavior. Different layout engines may use different fields.

Common usage:

// Widget takes 50% of available width
container->addChild(widget, LayoutSpec{.fixedW = pct(50)});
// Widget has equal weight with siblings (stretches)
container->addChild(widget, LayoutSpec{.ratio = 1.0f});
ReturnNameDescription
floatratioRelative weight among siblings in stack layouts. Used when dividing remaining space among children.
ScalarSpecfixedWFixed slot width - overrides ratio in horizontal stacks.
ScalarSpecfixedHFixed slot height - overrides ratio in vertical stacks.
ScalarSpecsizeWIf set, widget is this size inside its slot. If not set, widget fills slot according to alignH/alignV.
ScalarSpecsizeH
ScalarSpecminW
ScalarSpecminHMinimum widget size.
ScalarSpecmaxW
ScalarSpecmaxHMaximum widget size.
AlignalignHHorizontal alignment.
AlignalignVVertical alignment.
MarginSpecmarginSpacing around widget.
intcolColumn in grid (0-based)
introwRow in grid (0-based)
intcolSpanHow many columns this widget spans.
introwSpanHow many rows this widget spans.
ScalarSpecabsXAbsolute X position.
ScalarSpecabsYAbsolute Y position.

float ratio = 1.0f

Relative weight among siblings in stack layouts. Used when dividing remaining space among children.


ScalarSpec fixedW

Fixed slot width - overrides ratio in horizontal stacks.


ScalarSpec fixedH

Fixed slot height - overrides ratio in vertical stacks.


ScalarSpec sizeW

If set, widget is this size inside its slot. If not set, widget fills slot according to alignH/alignV.


ScalarSpec sizeH

ScalarSpec minW

ScalarSpec minH

Minimum widget size.


ScalarSpec maxW

ScalarSpec maxH

Maximum widget size.


Align alignH = Align::Stretch

Horizontal alignment.

Alignment of widget within slot. Only meaningful when sizeW/sizeH is set or widget is smaller than slot.


Align alignV = Align::Stretch

Vertical alignment.


MarginSpec margin

Spacing around widget.


int col = 0

Column in grid (0-based)


int row = 0

Row in grid (0-based)


int colSpan = 1

How many columns this widget spans.


int rowSpan = 1

How many rows this widget spans.


ScalarSpec absX

Absolute X position.


ScalarSpec absY

Absolute Y position.