slint
export component Foo inherits Window { width: 200px; height: 100px; HorizontalLayout { spacing: 5px; Rectangle { background: red; width: 10px; } Rectangle { background: blue; min-width: 10px; } Rectangle { background: yellow; horizontal-stretch: 1; } Rectangle { background: green; horizontal-stretch: 2; }}}将各个子元素水平排列。 元素的大小可以通过 width 或 height 属性固定,或者如果未设置, 它们将由布局根据最小和最大尺寸以及拉伸因子计算得出。
间距属性
spacing
length default: 0px
布局中元素之间的距离。
内边距属性
padding
length default: 0px
整个布局的内边距。此单一值应用于所有边。
要为不同的边设置不同的值,请使用以下属性:
padding-left
length default: 0px
padding-right
length default: 0px
padding-top
length default: 0px
padding-bottom
length default: 0px
对齐属性
alignment
enum LayoutAlignment default: the first enum value
设置对齐方式。与 CSS flex box 一致。
LayoutAlignment
表示 HorizontalBox、VerticalBox、 HorizontalLayout 或 VerticalLayout 的 alignment 属性的枚举。
stretch:使用布局中所有元素的最小大小,根据*-stretch在所有元素之间分配剩余空间。center:对所有元素使用首选大小,将剩余空间均匀分布在第一个元素之前和最后一个元素之后。start:对所有元素使用首选大小,将剩余空间放在最后一个元素之后。end:对所有元素使用首选大小,将剩余空间放在第一个元素之前。space-between:对所有元素使用首选大小,将剩余空间均匀分布在元素之间。space-around:对所有元素使用首选大小,将剩余空间均匀分布在元素之间,并在开始和结束处使用一半的间隔。space-evenly:对所有元素使用首选大小,将剩余空间均匀分布在第一个元素之前、最后一个元素之后以及元素之间。