Skip to content

pagino/pagino-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pagino

Handle pagination's logic

A lightweight, flexible Rust library for generating pagination UI elements. Pagino calculates which page numbers to display in a pagination component, including navigation controls (first, previous, next, last) and ellipsis indicators for gaps between page ranges.

Perfect for web applications, APIs, and any system that needs smart pagination UI generation.

Usage

Add this to your Cargo.toml:

[dependencies]
pagino = "1.0.7"

Quick Start

Quick Start

use pagino::Pagino;

fn main(){
  // Create a paginator with:
  // - All navigation controls enabled (first, previous, next, last)
  // - Currently on page 1
  // - 10 total pages
  // - 1 page shown on each side of current page (sibling_count)
  // - 1 page shown at start and end (boundary_count)
  let mut pagino = Pagino::new(true, true, true, true, 1, 10, 1, 1);

  let pages: Vec<i32> = pagino.get_pages();
  /*
    pages: [-1, -2, 1, 2, 3, 4, 5, -4, 10, -5, -6];
    
    Breakdown:
    -1: First button
    -2: Previous button
    1-5: Pages to display
    -4: End ellipsis (...)
    10: Last page
    -5: Next button
    -6: Last button
  */

  // Navigate to page 10
  pagino.set_page(10);
  let pages: Vec<i32> = pagino.get_pages();
  /*
    pages: [-1, -2, 1, -3, 6, 7, 8, 9, 10, -5, -6];
    -3: Start ellipsis (...) - indicating gap between page 1 and 6
  */

  // Navigate to page 5
  pagino.set_page(5);
  let pages: Vec<i32> = pagino.get_pages();
  /*
    pages: [-1, -2, 1, -3, 4, 5, 6, -4, 10, -5, -6];
  */
}

Methods:

pagino.get_pages() -> Vec<i32>              // Returns the calculated page numbers to display
pagino.set_page(page: i32)                  // Navigate to a specific page (validates against count)
pagino.set_count(count: i32)                // Update the total number of pages

pagino.first()                              // Navigate to the first page
pagino.previous()                           // Navigate to the previous page
pagino.next()                               // Navigate to the next page
pagino.last()                               // Navigate to the last page

What are negative numbers?

All negative numbers represent navigation elements and UI controls, not actual page numbers:

-1  First           // Go to first page button
-2  Previous        // Go to previous page button
-3  Start ellipsis  // "..." indicator for hidden pages at the beginning
-4  End ellipsis    // "..." indicator for hidden pages at the end
-5  Next            // Go to next page button
-6  Last            // Go to last page button

Positive numbers are actual page numbers to display.

Configuration

Create a Pagino instance with these parameters:

show_first: bool          // Display "first page" navigation button
show_previous: bool       // Display "previous page" navigation button
show_next: bool           // Display "next page" navigation button
show_last: bool           // Display "last page" navigation button
page: i32                 // Current page number (1-indexed, must be between 1 and count)
count: i32                // Total number of pages available
sibling_count: i32        // Number of pages to show around the current page (left and right)
boundary_count: i32       // Number of pages to always show at the start and end

Example Configuration:

With sibling_count=1 and boundary_count=1:

  • Always show page 1 and the last page (boundary)
  • Show 1 page before and after the current page (siblings)
  • Show ellipsis (...) for gaps

Links:

https://github.com/pagino/pagino-rust

https://crates.io/crates/pagino

Packages

No packages published

Languages