docs/astro/src/content/docs/guide/experimental/flexboxlayout.mdx
import SlintProperty from '@slint/common-files/src/components/SlintProperty.astro'; import CodeSnippetMD from '@slint/common-files/src/components/CodeSnippetMD.astro';
FlexboxLayout is a flexible box layout that arranges its children in rows or columns with automatic wrapping. It implements a CSS Flexbox-like layout model suitable for creating flexible, responsive UIs.
<CodeSnippetMD imagePath="/src/assets/generated/flexboxlayout-example1.png" imageWidth="300" imageHeight="150" imageAlt='flexboxlayout example with row direction'>Note:
FlexboxLayoutis experimental and subject to change. Tracking issue: slint-ui/slint#66.
// This example demonstrates FlexboxLayout with row direction (default)
export component Foo inherits Window {
width: 300px;
height: 200px;
FlexboxLayout {
spacing: 8px;
padding: 8px;
flex-direction: row;
Rectangle { background: red; width: 60px; height: 50px; }
Rectangle { background: blue; width: 60px; height: 50px; }
Rectangle { background: yellow; width: 60px; height: 50px; }
Rectangle { background: green; width: 60px; height: 50px; }
Rectangle { background: purple; width: 60px; height: 50px; }
}
}
// This example demonstrates FlexboxLayout with column direction
export component Foo inherits Window {
width: 300px;
height: 300px;
FlexboxLayout {
spacing: 8px;
padding: 8px;
flex-direction: column;
Rectangle { background: red; width: 50px; height: 60px; }
Rectangle { background: blue; width: 50px; height: 60px; }
Rectangle { background: yellow; width: 50px; height: 60px; }
Rectangle { background: green; width: 50px; height: 60px; }
Rectangle { background: purple; width: 50px; height: 60px; }
}
}
In row direction, items are placed from left to right. When the available width is exceeded, items automatically wrap to the next row. In column direction, items are placed from top to bottom and wrap to the next column when the available height is exceeded.
To target specific directions with different values use the following properties:
To target specific sides with different values use the following properties:
The following properties can be set on individual children of a FlexboxLayout:
The layouting algorithm for FlexboxLayout is entirely implemented by <a href="https://github.com/DioxusLabs/taffy">taffy</a>
You can learn more about the CSS Flexbox specification from