1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
#![doc = include_str!("../readme.md")]
mod cellselection;
mod noselection;
mod rowselection;
mod rowsetselection;
mod table;
pub mod textdata;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::style::Style;
///
/// Trait for accessing the table-data by the FTable.
///
/// This trait is suitable if the underlying data is random access.
pub trait TableData<'a> {
/// Size of the data.
fn rows(&self) -> usize;
/// Row height.
#[allow(unused_variables)]
fn row_height(&self, row: usize) -> u16 {
1
}
/// Row style.
#[allow(unused_variables)]
fn row_style(&self, row: usize) -> Style {
Style::default()
}
/// Render the cell given by column/row.
fn render_cell(&self, column: usize, row: usize, area: Rect, buf: &mut Buffer);
}
/// Trait for accessing the table-data by the FTable.
///
/// This trait is suitable if the underlying data is an iterator.
/// It uses internal iteration which allows much more leeway with
/// borrowing & lifetimes.
///
pub trait TableDataIter<'a> {
/// Returns the number of rows, if known.
///
/// If they are not known, all items will be iterated to
/// calculate things as the length of the table. Which will
/// be slower if you have many items.
fn rows(&self) -> Option<usize>;
/// Skips to the nth item, returns true if such an item exists.
fn nth(&mut self, n: usize) -> bool;
/// Reads the next item, returns true if such an item exists.
fn next(&mut self) -> bool;
/// Row height for the current item.
fn row_height(&self) -> u16;
/// Row style for the current line.
fn row_style(&self) -> Style;
/// Render the cell for the current line.
fn render_cell(&self, column: usize, area: Rect, buf: &mut Buffer);
}
/// Trait for the different selection models used by FTable.
pub trait TableSelection {
/// Row is selected. This can be separate from `is_selected_cell`.
fn is_selected_row(&self, row: usize) -> bool;
/// Column is selected. This can be separate from `is_selected_cell`.
fn is_selected_column(&self, column: usize) -> bool;
/// Specific cell is selected.
fn is_selected_cell(&self, column: usize, row: usize) -> bool;
/// Selection lead.
fn lead_selection(&self) -> Option<(usize, usize)>;
}
pub use table::{FTable, FTableState, FTableStyle};
pub mod selection {
//! Different selection models for FTable.
pub use crate::cellselection::CellSelection;
pub use crate::noselection::NoSelection;
pub use crate::rowselection::RowSelection;
pub use crate::rowsetselection::RowSetSelection;
}
pub mod event {
//! Rexported eventhandling traits.
pub use rat_event::{
crossterm, ct_event, util, ConsumedEvent, FocusKeys, HandleEvent, MouseOnly, Outcome,
};
}
mod _private {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NonExhaustive;
}