Skip to content
FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    Build layouts that adapt

    Layout has two phases: measure asks children how much space they need; arrange assigns their final bounds. The parent determines the constraints a child sees. Understand that relationship before adding fixed widths or margins to compensate for unexpected behavior.

    This layout keeps the search field at its desired height and gives the remaining space to a scrolling list:

    <Grid xmlns="https://github.com/ferroui" RowDefinitions="Auto,*"
    Height="320" Margin="16">
    <TextBox PlaceholderText="Search records" Margin="0,0,0,12" />
    <ListBox Grid.Row="1">
    <ListBoxItem Content="Ada" />
    <ListBoxItem Content="Grace" />
    <ListBoxItem Content="Margaret" />
    </ListBox>
    </Grid>

    The fixed height makes this fragment easy to test. In a real resizable screen, let the window or parent supply the available height. Add enough items to overflow and reduce the height: the list should scroll while the search field remains visible. Compare the live Grid example at different preview widths.

    Use Grid for forms and resizable regions. Use StackPanel for a short flow in one direction. Use WrapPanel when items should continue on another line. Use DockPanel for edges around a remaining content region. Use Canvas when positioning is intrinsically coordinate-based.

    <Grid xmlns="https://github.com/ferroui"
    ColumnDefinitions="Auto,*" RowDefinitions="Auto,Auto" Margin="24">
    <TextBlock Text="Name" Margin="0,0,12,8" />
    <TextBox Grid.Column="1" PlaceholderText="Display name" />
    <Button Grid.Row="1" Grid.Column="1"
    HorizontalAlignment="Left" Content="Save" />
    </Grid>

    The same form in declarative Rust: grid rows and columns take the XAML notation, attached properties use their owner’s name, and a tuple or a number converts to a Thickness:

    use ferroui_base::layout::HorizontalAlignment;
    use ferroui_view::prelude::*;
    let form = rsx! {
    Grid { column_definitions: "Auto,*", row_definitions: "Auto,Auto", margin: 24.0,
    TextBlock { text: "Name", margin: (0.0, 0.0, 12.0, 8.0) }
    TextBox { Grid.column: 1, placeholder_text: "Display name" }
    Button { Grid.row: 1, Grid.column: 1, horizontal_alignment: HorizontalAlignment::Left, "Save" }
    }
    };

    A StackPanel can offer effectively unbounded space along its stacking direction. A virtualizing list needs a bounded viewport to know which containers to realize. Put the list in a constrained Grid row instead of an outer scrolling StackPanel.

    Use MinWidth, MaxWidth, and alignment to express intent. Fixed pixel coordinates are fragile when text changes, localization makes labels longer, or a user increases the font size.

    Margin reserves space outside a control; padding reserves space around its content. Alignment positions the control within its allocation. A stretched control with a fixed width remains constrained by that width.

    Inspect actual bounds in the developer tools when something appears clipped. Check the parent first, then the child, and look for an earlier fixed-size constraint rather than adding more clipping exceptions.

    Result Check
    The list grows instead of scrolling Does its parent give it a finite height?
    A field will not stretch Is a fixed Width or parent column constraining it?
    Text clips after localization Is a fixed height preventing wrapping?
    Spacing doubles unexpectedly Are both adjacent margins reserving space?

    Change the column definitions and preview width. Compare the result with the sizing rules above.

    A responsive formFerroUI · 0.5.0
    Try it for yourself

    Real controls, running in WebAssembly.
    The runtime downloads when you press Run.

    Shared runtime · 9.8 MB compressed · cached across examples
    Download project
    <Grid xmlns="https://github.com/ferroui" ColumnDefinitions="Auto,*" RowDefinitions="Auto,Auto" Margin="12">
    <TextBlock Text="Name" Margin="0,0,16,12" />
    <TextBox Grid.Column="1" PlaceholderText="Your name" />
    <TextBlock Grid.Row="1" Text="Team" Margin="0,0,16,0" />
    <TextBox Grid.Row="1" Grid.Column="1" PlaceholderText="Your team" />
    </Grid>
    Ready to explore