flex
Lays out the children of a container in a row or a column with the flexible box layout of CSS. It is a geometry manager beside pack, grid, and place. ztk::flex is a second name of the same command, for a script that has its own flex proc.
Synopsis
flex WINDOW ?WINDOW ...? ?-option value ...?
flex configure WINDOW ?WINDOW ...? ?-option value ...?
flex container WINDOW ?-option value ...?
flex forget WINDOW ?WINDOW ...?
flex info WINDOW
flex slaves WINDOW
flex content WINDOW
flex propagate WINDOW ?BOOLEAN?
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
WINDOW |
widget path | configure makes each window an item of its parent. In a container with display: flex, the items follow the order of creation of the children, as in CSS, so a window that flex forget left and flex adds again gets its old place; raise and lower do not move an item. In a container of the command, a new item goes at the end of the list. A window that is an item keeps its place in the list. |
|
-grow |
number | 0 |
The share of the free space that the item gets. |
-shrink |
number | 1 |
The share of the missing space that the item gives up, scaled by its basis. |
-basis |
auto or screen distance |
auto |
The size of the item on the main axis before it grows or shrinks. auto is the width or height of the style, else the requested size. |
-align |
auto, start, end, center, stretch |
auto |
The place of the item on the cross axis of its line. auto uses the -align of the container. |
-order |
integer | 0 |
The visual order. Items with the same order keep the list order. |
-margin |
1 to 4 screen distances | 0 |
The space around the item: top, right, bottom, left, as in CSS. |
container WINDOW |
subcommand | Sets the options of the container below. With no option it gives each option and its used value. | |
-direction |
row, row-reverse, column, column-reverse |
row |
The main axis. |
-wrap |
nowrap, wrap, wrap-reverse |
nowrap |
With wrap, an item that does not fit starts a new line. |
-justify |
start, end, center, space-between, space-around, space-evenly |
start |
The place of the items on the main axis. |
-align (container) |
start, end, center, stretch |
stretch |
The place of the items on the cross axis. |
-aligncontent |
stretch and the values of -justify |
stretch |
The place of the lines of a wrapping container. |
-gap |
1 or 2 screen distances | 0 |
The row gap, then the column gap. |
-padding |
1 to 4 screen distances | 0 |
The space inside the border and the padding of the style of the container. |
forget WINDOW ... |
subcommand | Ends the management of each window. A container with display: flex does not manage the window again. |
|
info WINDOW |
subcommand | Gives -in and the item options with their used values. |
|
slaves WINDOW, content WINDOW |
subcommand | Gives the items of the container in list order: the order of creation in a container with display: flex. |
|
propagate WINDOW ?BOOLEAN? |
subcommand | As pack propagate: with 0 the content does not set the requested size of the container. |
An option of the command wins over the CSS value of the same property. A container with display: flex in its style manages each child that has no manager, with no flex call (Flex layout).
Return value
info, container with no option, slaves, content, and propagate with no boolean give their value. The other forms give an empty string.
Errors
| Error | When |
|---|---|
bad window path name "W" |
No widget has the name. |
bad option "X": must be configure, container, content, forget, info, propagate, or slaves |
An unknown subcommand. |
bad option "-X": must be -align, -basis, -grow, -margin, -order, or -shrink |
An unknown item option. |
bad direction "X": must be row, row-reverse, column, or column-reverse |
A bad value of -direction. -wrap, -justify, -align, and -aligncontent give the same form. |
bad grow value "X": must be a number that is 0 or more |
A negative -grow or -shrink. |
window "W" isn't managed by flex |
info of a window that is not an item. |
can't manage "W": it's a top-level window |
A toplevel as an item. |
cannot use geometry manager flex inside W which already has slaves managed by pack |
The container has content of another manager. |
Platforms
| Platform | Works |
|---|---|
| Windows | Yes |
| macOS | Yes |
| Linux, Wayland | Yes |
| Linux, X11 | Yes |
| Web | Yes |
| iOS, Android | Yes |
| Headless | Yes |
Example
frame .bar
pack .bar -fill x
flex container .bar -gap 8 -padding 8 -align center
button .bar.new -text New
frame .bar.space
entry .bar.find
flex .bar.new
flex .bar.space -grow 1
flex .bar.find -basis 120
update
flex info .bar.space
The live window shows here.