pub struct Model {
pub type_: Type,
pub page: usize,
pub per_page: usize,
pub total_pages: usize,
pub active_dot: String,
pub inactive_dot: String,
pub arabic_format: String,
pub key_map: KeyMap,
}Expand description
Model is the Bubble Tea model for this user interface.
Fields§
§type_: TypeType configures how the pagination is rendered (Arabic, Dots).
page: usizePage is the current page number.
per_page: usizePerPage is the number of items per page.
total_pages: usizeTotalPages is the total number of pages.
active_dot: StringActiveDot is used to mark the current page under the Dots display type.
inactive_dot: StringInactiveDot is used to mark inactive pages under the Dots display type.
arabic_format: StringArabicFormat is the printf-style format to use for the Arabic display type.
key_map: KeyMapKeyMap encodes the keybindings recognized by the widget.
Implementations§
Source§impl Model
impl Model
Sourcepub fn set_total_pages(&mut self, items: usize) -> usize
pub fn set_total_pages(&mut self, items: usize) -> usize
SetTotalPages is a helper function for calculating the total number of pages from a given number of items. Its use is optional since this pager can be used for other things beyond navigating sets. Note that it both returns the number of total pages and alters the model.
Sourcepub fn items_on_page(&self, total_items: usize) -> usize
pub fn items_on_page(&self, total_items: usize) -> usize
ItemsOnPage is a helper function for returning the number of items on the current page given the total number of items passed as an argument.
Sourcepub fn get_slice_bounds(&self, length: usize) -> (usize, usize)
pub fn get_slice_bounds(&self, length: usize) -> (usize, usize)
GetSliceBounds is a helper function for paginating slices. Pass the length of the slice you’re rendering and you’ll receive the start and end bounds corresponding to the pagination. For example:
let bunch_of_stuff = vec![1, 2, 3, 4, 5];
let (start, end) = model.get_slice_bounds(bunch_of_stuff.len());
let slice_to_render = &bunch_of_stuff[start..end];Sourcepub fn prev_page(&mut self)
pub fn prev_page(&mut self)
PrevPage is a helper function for navigating one page backward. It will not page beyond the first page (i.e. page 0).
Sourcepub fn next_page(&mut self)
pub fn next_page(&mut self)
NextPage is a helper function for navigating one page forward. It will not page beyond the last page (i.e. totalPages - 1).
Sourcepub fn on_last_page(&self) -> bool
pub fn on_last_page(&self) -> bool
OnLastPage returns whether or not we’re on the last page.
Sourcepub fn on_first_page(&self) -> bool
pub fn on_first_page(&self) -> bool
OnFirstPage returns whether or not we’re on the first page.