Slint · Slint components
This page shows the Slint implementation. Slint components written for native Rust applications and the browser. Browse the catalog, run each live example, and copy the .slint source into your own app.
Pagination
The Pagination component provides page navigation with next and previous links. It displays page numbers and allows users to navigate through multiple pages of content.
#Import
use gpui_kit::component::pagination::Pagination;// Installed in ui/components. That directory is on the Slint include path, so import by file name:
import { Pagination } from "pagination.slint";use iced::widget::{column, container, mouse_area, row, svg, text};
use iced::{Alignment, Element, Length, Task, Theme};import { signal, Text } from "nsh";
import { Pagination } from "./pagination";
import { tokens } from "./theme";#Usage
const usage = <Pagination page={basic()} totalPages={10} onPageChange={(next) => basic.set(next)} labels />;#Pages
// The compact default: icon-only step buttons, the run at page one so the
// trailing ellipsis and the last page are both in view.
let pages = Pagination::new()
.page(app.pages_page)
.pages(12)
.on_change(Message::PagesPage);const pagesOnly = (
<Pagination page={pages()} totalPages={3} onPageChange={(next) => pages.set(next)} />
);By default, the pagination shows up to 5 visible page buttons. You can customize this with visible_pages():
Pagination::new("my-pagination")
.current_page(1)
.total_pages(50)
.visible_pages(10)
.on_click(|page, _, cx| {
// Handle page change
})Pagination {
pages: 12;
page: 1;
}#Basic Pagination
Pagination::new("my-pagination")
.current_page(5)
.total_pages(10)
.on_click(|page, _, cx| {
println!("Navigated to page: {}", page);
})description: "The step buttons carry their labels.";
Pagination {
pages: 10;
page: 5;
compact: false;
}// GPUI's plain `Pagination` labels its step buttons and pairs each label with
// its arrow: "‹ Previous" and "Next ›". The run stays five wide and carries
// the current page at its centre.
let basic = Pagination::new()
.page(app.basic_page)
.pages(10)
.compact(false)
.on_change(Message::BasicPage);const basicPagination = (
<Pagination page={pages()} totalPages={3} onPageChange={(next) => pages.set(next)} labels />
);#Compact Style
const compactStyle = (
<Pagination
page={compact()}
totalPages={10}
onPageChange={(next) => compact.set(next)}
labels
showNumbers={false}
showPageInfo
pageInfoAt="start"
/>
);The compact style only shows the previous and next buttons with icons, without displaying page numbers.
Use compact method to enable compact style:
Pagination::new("my-pagination")
.compact()
.current_page(3)
.total_pages(10)
.on_click(|page, _, cx| {
// Handle page change
})#Different Sizes
// One control at each of the four tiers. `xsmall` keeps the arrows at the
// control height the size gives it, so the whole row shrinks with it.
let sizes = column![
Pagination::new()
.page(app.xsmall_page)
.pages(8)
.size(ControlSize::XSmall)
.on_change(Message::XSmallPage),
Pagination::new()
.page(app.medium_page)
.pages(8)
.size(ControlSize::Medium)
.on_change(Message::MediumPage),
Pagination::new()
.page(app.large_page)
.pages(8)
.size(ControlSize::Large)
.on_change(Message::LargePage),
]
.spacing(theme::SPACING_MD)
.align_x(Alignment::Start);const differentSizes = (
<Pagination
page={sizes()}
totalPages={10}
onPageChange={(next) => sizes.set(next)}
labels
size="large"
showNumbers
/>
);The Pagination supports the Sizable trait for different sizes:
use gpui_kit::component::{Sizable as _, Size};
Pagination::new("my-pagination")
.xsmall()
.current_page(1)
.total_pages(10)
Pagination::new("my-pagination")
.small()
.current_page(1)
.total_pages(10)
Pagination::new("my-pagination")
.current_page(1)
.total_pages(10) // Medium (default)
Pagination::new("my-pagination")
.large()
.current_page(1)
.total_pages(10)Pagination {
pages: 8;
page: 2;
size: ControlSize.xsmall;
}
Pagination {
pages: 8;
page: 3;
size: ControlSize.medium;
}
Pagination {
pages: 8;
page: 4;
size: ControlSize.large;
}#Disabled State
Pagination::new("my-pagination")
.current_page(4)
.total_pages(10)
.disabled(true)
.on_click(|_, _, _| {})VerticalLayout {
spacing: 12px;
alignment: start;
Pagination {
pages: 5;
page: 1;
}
Pagination {
pages: 5;
page: 5;
}
}// The arrow that has nowhere to go is disabled, so a first page cannot step
// back and a last page cannot step on. The page numbers stay live, which is
// the Slint component: only the arrow at the boundary is `enabled: false`.
let disabled = column![
Pagination::new()
.page(app.first_page)
.pages(5)
.on_change(Message::FirstPage),
Pagination::new()
.page(app.last_page)
.pages(5)
.on_change(Message::LastPage),
]
.spacing(theme::SPACING_MD)
.align_x(Alignment::Start);const disabled = <Pagination page={1} totalPages={1} labels disabled />;#Handle Page Change Events
const handleEvents = (
<Pagination page={events()} totalPages={10} onPageChange={(next) => events.set(next)} labels showPageInfo />
);#Ellipsis indicator
const ellipsisIndicator = (
<Pagination page={ellipsis()} totalPages={10} onPageChange={(next) => ellipsis.set(next)} labels />
);#Outline style buttons
const outlineStyle = (
<Pagination page={outline()} totalPages={10} onPageChange={(next) => outline.set(next)} outline showNumbers />
);#Page info on left
const pageInfoLeft = (
<Pagination
page={infoLeft()}
totalPages={10}
onPageChange={(next) => infoLeft.set(next)}
labels
showPageInfo
pageInfoAt="start"
/>
);#Rows per page select with range info
const rowsPerPage = (
<Pagination
page={rowsPage()}
totalPages={4}
totalItems={100}
rowsPerPage={rows()}
rowsPerPageOptions={[10, 25, 50, 100]}
onRowsPerPageChange={(next) => rows.set(next)}
onPageChange={(next) => rowsPage.set(next)}
showNumbers={false}
showFirstLast
align="between"
/>
);#Page select dropdown
const pageSelect = (
<Pagination
page={selector()}
totalPages={10}
onPageChange={(next) => selector.set(next)}
pageSelector
showFirstLast
showNumbers={false}
/>
);#Numbered with go-to-page
const goTo = (
<Pagination page={go()} totalPages={10} onPageChange={(next) => go.set(next)} showNumbers goToPage />
);#Page info on center
const centeredInfo = (
<Pagination
page={centered()}
totalPages={10}
onPageChange={(next) => centered.set(next)}
showNumbers={false}
showPageInfo
pageInfoAt="center"
/>
);#Numbered pagination in card
const cardedPagination = (
<Pagination page={carded()} totalPages={12} onPageChange={(next) => carded.set(next)} card showNumbers />
);#Page info, numbers and per-page select
const comboPagination = (
<Pagination
page={combo()}
totalPages={10}
onPageChange={(next) => combo.set(next)}
totalItems={100}
rowsPerPage={10}
rowsPerPageOptions={[10, 25, 50]}
onRowsPerPageChange={() => {}}
labels
showPageInfo
showNumbers
/>
);#Custom styling
const custom = (
<Pagination
page={centered()}
totalPages={10}
onPageChange={(next) => centered.set(next)}
labels
showPageInfo
pageInfoAt="end"
style={{ padding: 6, borderRadius: 8, backgroundColor: tokens.muted }}
/>
);The on_click callback receives the new page number when users click on page numbers, previous, or next buttons:
Pagination::new("my-pagination")
.current_page(current_page)
.total_pages(total_pages)
.on_click(|page, _, cx| {
// Update your state with the new page
// The page number is 1-based
})#With State Management
let mut current_page = 1;
let total_pages = 20;
Pagination::new("pagination")
.current_page(current_page)
.total_pages(total_pages)
.on_click({
let entity = entity.clone();
move |page, _, cx| {
entity.update(cx, |this, cx| {
this.current_page = *page;
cx.notify();
});
}
})#Large Dataset Pagination
For large datasets, use visible_pages() to show more page options:
Pagination::new("large-pagination")
.current_page(25)
.total_pages(100)
.visible_pages(10)
.on_click(|page, _, cx| {
// Load data for the new page
})#API Reference
#Sizing
Implements Sizable trait:
xsmall()- Extra small sizesmall()- Small sizemedium()- Medium size (default)large()- Large sizewith_size(size)- Set custom size
#Methods
current_page(page: usize)- Set the current page number (1-based). The value will be clamped between 1 and total_pages.total_pages(pages: usize)- Set the total number of pages.visible_pages(max: usize)- Set the maximum number of visible page buttons (default: 5).compact()- Enable compact style (only shows prev/next buttons with icons).disabled(bool)- Set the disabled state.on_click(handler)- Set the handler for page change events.
#Pagination
Page controls. Mirrors GPUI Component's `Pagination`.
| Name | Kind | Type | Default | Description |
|---|---|---|---|---|
page | in-out | int | 1 | |
pages | in | int | 10 | |
size | in | ControlSize | ControlSize.small | |
compact | in | bool | true | Icon-only previous and next buttons, which is how GPUI's `compact()` renders them. Setting it false labels the pair "Previous" and "Next", which is what GPUI's plain `Pagination` shows. |
changed | callback | (page: int) |