Scroll

scroll clips its child to its own box and scrolls it vertically: wheel, or drag with a fling that slows down after release. Give it a bounded height (grow inside a column, or height) so there is something to scroll.

.horizontal() scrolls sideways instead, like the shelf of cards at the top: drag, a sideways touchpad swipe, or shift+wheel. A plain wheel over it still scrolls the page. Its items need .shrink(0.0), or the row squeezes them into the box. .reveal(span) glides to keep a span in view when it changes, e.g. the item with keyboard focus.

use dfui::widgets::{Styled, column, container, row, scroll, text};
use dfui::{Color, Element};

fn view() -> Element {
    // A shelf that scrolls sideways; its cards keep their width.
    let cards = (1..=12).map(|i| {
        container(text(format!("Card {i}")))
            .width(96.0)
            .height(64.0)
            .shrink(0.0)
            .padding(10.0)
            .radius(8.0)
            .bg(Color::hex(0xdde3f0))
            .into()
    });
    let shelf = scroll(row(cards).gap(8.0)).horizontal();
    let rows = (1..=50).map(|i| {
        let bg = if i % 2 == 0 { 0xe9ebf1 } else { 0xffffff };
        container(text(format!("Row {i}")))
            .padding_xy(12.0, 10.0)
            .bg(Color::hex(bg))
            .into()
    });
    column([shelf.into(), scroll(column(rows)).grow(1.0).into()])
        .gap(12.0)
        .padding(16.0)
        .into()
}

fn main() {
    dfui::run(view);
}

Run it natively: cargo run -p dfui-site --example scroll