functui.flex¶
- functui.flex.flex(node: Layout) Flex[source]¶
Wrap layout in a
Flexclass to mark it as flexible.Equivalent to
flex_custom(grow=1 shrink=True, basis=False).
- functui.flex.flex_custom(grow=1, shrink=True, basis=False) Callable[[Layout], Flex][source]¶
Wrap child layout in a
Flexclass to mark it as flexible and adjust attributes.- Parameters:
grow – If there is any leftover space, this value is used to determine how much of this space does this child get relative to other children.
shrink – Should this child shrink if container does not fit into the available space? This property has an effect only when
basisis set toTrue.basis – If true, container will take this children’s minimum size into account. If false, container will assume minimum size of 0.
- functui.flex.hbox_flex(children: Iterable[Flex | Layout], /)[source]¶
A container node that allows children to expand on the x axis.
Modeled of the CSS flexbox layout model. By default acts as a regular
hbox. Wrap children inflex()orflex_custom()wrapper nodes to allow them to use leftover space if there is any.Examples
- Usage with flex:
>>> from functui import Rect, layout_to_str >>> from functui.common import border, text >>> from functui.flex import flex, hbox_flex, flex_custom >>> layout = hbox_flex([ ... text("Flex.") | border | flex, ... text("No flex.") | border, ... ]) | border >>> print(layout_to_str(layout, Rect(40, 5))) ┌──────────────────────────────────────┐ │┌──────────────────────────┐┌────────┐│ ││Flex. ││No flex.││ │└──────────────────────────┘└────────┘│ └──────────────────────────────────────┘
- Usage with flex_custom grow argument:
>>> layout = hbox_flex([ ... text("grow 1") | border | flex_custom(grow=1), ... text("grow 2") | border | flex_custom(grow=2), ... text("grow 1") | border | flex, # flex same as flex_custom(1) ... ]) | border >>> print(layout_to_str(layout, Rect(40, 5))) ┌──────────────────────────────────────┐ │┌───────┐┌─────────────────┐┌────────┐│ ││grow 1 ││grow 2 ││grow 1 ││ │└───────┘└─────────────────┘└────────┘│ └──────────────────────────────────────┘
- Usage with flex_custom grow and basis arguments:
>>> layout = hbox_flex([ ... text("basis and grow") | border | flex_custom(grow=1, basis=True), ... text("grow") | border | flex, # flex is same as flex_custom(grow=1) ... ]) | border >>> print(layout_to_str(layout, Rect(40, 5))) ┌──────────────────────────────────────┐ │┌─────────────────────────┐┌─────────┐│ ││basis and grow ││grow ││ │└─────────────────────────┘└─────────┘│ └──────────────────────────────────────┘
- functui.flex.hbox_flex_wrap(children: Iterable[Flex | Layout]) Layout[source]¶
A container node that allows children to wrap vertically.
Modeled of the CSS flexbox layout model. If all children can’t fit into the available horizontal space, wrap them. Wrap children in
flex()orflex_custom()wrapper nodes to allow them to use leftover space if there is any.
- functui.flex.vbox_flex(children: Iterable[Flex | Layout]) Layout[source]¶
A container node that allows children to expand on the y axis.
Modeled of the CSS flexbox layout model. By default acts as a regular
vbox. Wrap children inflex()orflex_custom()wrapper nodes to allow them to use leftover space if there is any.