Fixed, percentage, and flexible sizes for panels and containers.
Size specifies how much space a child node occupies inside a row or column. You assign it when configuring panels and containers in layout options, or update it later with LayoutNode::SetSize().
This row distributes its space among three panels using different sizing units:
body->AddPanel({ .size = "240px" });
body->AddPanel({ .size = "30%" });
body->AddPanel({ .size = "2fr" });
A nullable smart pointer.
Definition RefPtr.h:126
Layout Units
Panels and containers accept different measurement forms along their parent container's axis:
- Logical pixels specify a fixed distance. A bare number or a string with px sets the dimension in display-independent pixels.
- Percentages claim a fraction of the container's free space. A string with % reserves that portion of the space remaining after fixed siblings.
- Flex shares divide whatever space remains. A string with fr takes a proportional cut of the free space left after fixed and percentage allocations.
Computed Sizes
When sizes depend on runtime calculations rather than string constants, use factory methods or the Flex helper type. Call Size::Fr() or Flex to specify flex shares.
Pass numeric values directly instead of formatting strings:
constexpr Flex(double factor)
Create a flex factor from a computed number.
Definition Length.h:224
constexpr Size()=default
Create an unset Size (the receiving field's default applies).
static constexpr Size Pct(double value)
Create a percent-of-free-space Size.
Definition Length.h:441
Literals and Runtime Strings
String literals passed to Size are parsed and validated at compile time. Any syntax typo or unsupported unit produces a compiler error.
For strings read at runtime, use Size::TryParse():
sidebar->SetSize(parsed);
static constexpr bool TryParse(const char *text, size_t length, Size &out)
Parse a runtime string with the same rules as the literal form.
Definition Length.h:461
Default and Unset Sizes
A default-constructed Size has no explicit unit or value. Leaving a size unset instructs the receiving field to apply its own default, which gives panels and containers in a row or column a single flex share (1fr) and floating panels 100%.
Setting an explicit size of 0 or "0px" collapses the node to zero pixels along the layout axis instead of expanding it.
- See also
- Length, Flex, PanelOptions, LayoutNode::SetSize()