Sizing

Goals

Cross-axis alignment

HBox should approximately center compact children vertically (middle), and VBox should approximately center them horizontally (center). Children that expand on that axis can still fill the available space. This positions the widget, not the text inside it, and does not require pixel-identical output across toolkits.

Backend support and native limits are listed in the reference alignment matrix. Textual uses native group alignment, so mixed-size children do not necessarily have individual matching center lines. Explicit dimensions also retain backend-specific size-hint/minimum behavior.

Concepts

In following demos, elements come with 5px padding/gap and 3px colored border.

Case 1: Fit the content

The most compact sizing.
Static
Static
Static
Static
Static
Static
Static
Static

Case 2: Container with specified size

The outmost container is specified with a size of 150x150 px. (Positioning is not discussed here.)
Static
A Static
B Static
C Static
D Static
E Static
F Static
G Static
H Static
I Static
J Static
A Static
B Static
C Static
D Static
E Static
F Static
G Static
H Static
I Static
J Static

Case 3: Weighting

The outmost container is specified with a width of 150%.
weighted
weighted
weighted
 
weighted
weighted
weighted
weighted

Case 4: More complex cases

A Static
B Static
C Static
D Static
E Static
F Static
G Static
H Static
I Static
J Static
canvas