limn
    ↑↓ ChooseEnter OpenEsc Close
    GitHub

    Components/Navigation

    Pager

    Two arrows around a position label such as "3 / 12", for stepping through a sequence: pages, search matches, changes.

    Native componentGuide source

    Preview

    CodeSource
    fn view(state: &State, palette: ComponentPalette) -> Element {
        Pager::new(format!("{} / {}", state.page, state.pages), palette)
            .previous("page-previous", state.page > 1)
            .next("page-next", state.page < state.pages)
            .render()
    }
    
    fn update(state: &mut State, action: &UiAction) {
        if let UiAction::Clicked { id } = action {
            match id.as_str() {
                "page-previous" => state.page -= 1,
                "page-next" => state.page += 1,
                _ => {}
            }
        }
    }

    Examples

    Each one is the library drawing it. Press, type and hover.

    Pager2 / 2
    CodeSource
    row(vec![Pager::new("PDF", palette)
        .previous("panel-pager-off-prev", false)
        .next("panel-pager-off-next", false)
        .label_width(52.0)
        .render()])

    Pager

    Two arrows around a position label such as “3 / 12”, for stepping through a sequence: pages, search matches, changes.

    Import

    use limn::{Component, Icon, Pager, PagerSizing, TooltipSpec};

    Usage

    The host owns the position: it writes the label and says which ends can be taken. Each arrow reports UiAction::Clicked with the ID it was given.

    fn view(state: &State, palette: ComponentPalette) -> Element {
        Pager::new(format!("{} / {}", state.page, state.pages), palette)
            .previous("page-previous", state.page > 1)
            .next("page-next", state.page < state.pages)
            .render()
    }
    
    fn update(state: &mut State, action: &UiAction) {
        if let UiAction::Clicked { id } = action {
            match id.as_str() {
                "page-previous" => state.page -= 1,
                "page-next" => state.page += 1,
                _ => {}
            }
        }
    }

    Pager::new is the label alone; previous and next each add one arrow. An arrow passed false is passive: it has no hit target and keeps its hint.

    Label width

    Pager::new("3 / 12", palette)
        .previous("page-previous", true)
        .next("page-next", true)
        .label_width(52.0)
        .render()

    label_width holds the label, centered, in a slot of that width, so the arrows do not move as the position changes. A label that does not fit is cut with an ellipsis.

    Icons

    Pager::new("3 / 12", palette)
        .previous("change-previous", true)
        .next("change-next", true)
        .icons(Icon::ArrowUp, Icon::ArrowDown)
        .render()

    The arrows point left and right. icons gives other glyphs to the arrows already added, such as up and down for a sequence that runs down the page, so call it after previous and next.

    Hints

    Pager::new("3 / 12", palette)
        .previous("page-previous", true)
        .next("page-next", true)
        .tooltips(
            TooltipSpec::new("Previous page").shortcut("Shift+F7"),
            TooltipSpec::new("Next page").shortcut("F7"),
        )
        .label_tooltip("page-where", TooltipSpec::new("Page 3 of 12"))
        .render()

    tooltips takes one TooltipSpec per arrow and, like icons, applies to the arrows already added. label_tooltip puts a hint on the label; its ID must be unique in the window.

    Sizing

    Pager::new("3 / 12", palette)
        .previous("page-previous", true)
        .next("page-next", true)
        .sizing(PagerSizing { gap: 0.0 })
        .render()

    PagerSizing has one field, gap: the space between each arrow and the label. PagerSizing::DEFAULT is 4.

    Actions

    ActionWhen
    UiAction::Clicked { id }An enabled arrow is activated, with the ID passed to previous or next.

    Accessibility

    Each arrow is a button named by the title of its hint, so give the arrows tooltips: without them they have no name. An end that cannot be taken is there and says it cannot be used.

    API reference

    The guide covers composition, options and actions. Generate the complete Rust type and builder reference from the checkout:

    cargo doc -p limn --open

    Component API overview · State and actions

    The example is drawn by crates/limn-gallery/src/pages/panels.rs.