Layout Builder
Layout Builder is used to configure display mode, size, spacing, positioning, Flex/Grid and other layout properties when creating views. Basic writing is calling .layout(|layout| { ... }) after view, continuously calling layout methods in closure, finally returning modified layout.
Basic Writing
After importing LayoutBuilder, all views can call .layout(...). Also need to import LayoutResolverExt, so layout in closure can use display, size, flex_grow and other layout methods.
Following example uses flex related types, assuming you already enabled layout-flex feature.
Closure must return modified layout. If closure captures external signal or variable, usually needs to write as move |layout| { ... }.
Flor currently doesn't have direct .width(100), .height(40), .x(10), .y(20) — these kinds of layout builder methods. Size, position, margin are all expressed through size, inset, margin and other layout parameters.
Chain Writing and set Writing
Most times directly chain calling is enough:
Each layout method also has a same-named set_ version, for example display(...) corresponds to set_display(...), flex_grow(...) corresponds to set_flex_grow(...). This group of set_ methods is suitable for branch modifying same layout in if, match.
These methods are automatically generated by Flor, so naming stays unified: layout item name written as snake_case method name, set_ version adds set_ in front. You just use method names in following table.
set_methods are mainly used when view development, parsing atomic class assignment
State Layout
Layout can also be set separately by view state. After calling hover(), focus(), active() and other state methods, subsequent layout settings will write to corresponding state; calling normal() or base() can switch back to normal state.
How to Read Unit Parameters
Layout values mainly come from flor::taffy, unit types come from flor::view::resolver::Unit.
Unit is length unit. It only participates in conversion when layout value is length, finally resolves to px and hands to layout system.
Whenever layout value and Unit appear together in method, rule is: layout value is responsible for expressing length, percent or auto, Unit only decides how to parse this number when value is length. For example Dimension::Length(12.0) paired with Unit::Px means 12px; Dimension::Percent(0.5) and Dimension::Auto don't depend on unit.
Core Layout Parameters
These methods are not affected by layout-flex, layout-grid, layout-block feature.
Example:
Flex and Grid Shared Parameters
These methods are available after enabling either layout-flex or layout-grid feature.
Block Parameters
These methods require enabling layout-block feature.
Flex Parameters
These methods require enabling layout-flex feature.
Example:
Grid Parameters
These methods require enabling layout-grid feature.

