GPUI Box GitHub

Components / navigation

Pagination builder

First, previous, next, and last, plus a numbered range when there is one.

A builder is RenderOnce. Construct and mount it in one expression.

use gpui_kit::navigation::Pagination;

Reviewed in pagination.

Construct
new(ident: impl Into<Ident>) -> Self
Options

Chain onto the value.

page(page: usize) -> Self
total_pages(total: usize) -> Self
unknown_total(has_next: bool) -> Self
total(total: PageTotal) -> Self
siblings(siblings: usize) -> Self
page_size(select: Entity<Select>) -> Self
on_select(handler: impl Fn(usize, &mut Window, &mut App) + 'static) -> Self
Example · pagination
fn pagination(window: &mut Window, cx: &mut App) -> AnyElement {
    if !cx.has_global::<ScenePagination>() {
        let page_size = cx.new(|cx| {
            Select::new("scene.pagination.size", window, cx)
                .name("Rows per page")
                .options([
                    SelectOption::new("25", "25 per page"),
                    SelectOption::new("50", "50 per page"),
                    SelectOption::new("100", "100 per page"),
                ])
                .selected("50")
        });
        cx.set_global(ScenePagination { page_size });
    }
    let page_size = cx.global::<ScenePagination>().page_size.clone();
    let theme = cx.theme().clone();

    stack(&theme)
        .w(px(620.0))
        .child(caption(
            &theme,
            "a known total, with the page size the host offered",
        ))
        .child(
            Pagination::new("scene.pagination.known")
                .page(9)
                .total_pages(20)
                .page_size(page_size)
                .on_select(|_, _, _| {}),
        )
        // A host that only knows there is another page says exactly that: no
        // last-page control, no numbers, and no total.
        .child(caption(
            &theme,
            "an unknown total: no numbers, no last page, and no count invented",
        ))
        .child(
            Pagination::new("scene.pagination.unknown")
                .page(3)
                .unknown_total(true)
                .on_select(|_, _, _| {}),
        )
        .into_any_element()
}

Source: crates/gpui-kit/src/navigation/pagination.rs