pub struct Grid { /* private fields */ }
Expand description
Grid provides a set of methods for building a text-based table
Implementations
sourceimpl Grid
impl Grid
sourcepub fn new(rows: usize, columns: usize) -> Self
pub fn new(rows: usize, columns: usize) -> Self
The new method creates a grid instance with default styles.
The size of the grid can not be changed after the instance is created.
Example
use papergrid::{Grid, Entity, Settings, DEFAULT_CELL_STYLE};
let mut grid = Grid::new(2, 2);
grid.set_cell_borders(DEFAULT_CELL_STYLE.clone());
let str = grid.to_string();
assert_eq!(
str,
"+++\n\
|||\n\
+++\n\
|||\n\
+++\n"
)
sourcepub fn set(&mut self, entity: &Entity, settings: Settings)
pub fn set(&mut self, entity: &Entity, settings: Settings)
Set method is responsible for modification of cell/row/column.
The method panics if incorrect cell/row/column index is given.
Example
use papergrid::{Grid, Entity, Settings, DEFAULT_CELL_STYLE};
let mut grid = Grid::new(2, 2);
grid.set_cell_borders(DEFAULT_CELL_STYLE.clone());
grid.set(&Entity::Row(0), Settings::new().text("row 1"));
grid.set(&Entity::Row(1), Settings::new().text("row 2"));
let str = grid.to_string();
assert_eq!(
str,
"+-----+-----+\n\
|row 1|row 1|\n\
+-----+-----+\n\
|row 2|row 2|\n\
+-----+-----+\n"
)
pub fn add_horizontal_split(&mut self, row: usize)
pub fn add_vertical_split(&mut self, column: usize)
pub fn add_grid_split(&mut self)
pub fn clear_split_grid(&mut self)
pub fn clear_overide_split_lines(&mut self)
sourcepub fn get_settings(&self, row: usize, column: usize) -> Settings
pub fn get_settings(&self, row: usize, column: usize) -> Settings
get_cell_settings returns a settings of a cell
pub fn get_border(&mut self, row: usize, column: usize) -> Border
pub fn style(&self, entity: &Entity) -> &Style
sourcepub fn get_cell_content(&self, row: usize, column: usize) -> &str
pub fn get_cell_content(&self, row: usize, column: usize) -> &str
get_cell_content returns content without any style changes
sourcepub fn count_rows(&self) -> usize
pub fn count_rows(&self) -> usize
Count_rows returns an amount of rows on the grid
sourcepub fn count_columns(&self) -> usize
pub fn count_columns(&self) -> usize
Count_rows returns an amount of columns on the grid
pub fn set_text<S: Into<String>>(&mut self, entity: &Entity, text: S)
pub fn set_cell_borders(&mut self, border: Border)
pub fn extract<R, C>(&self, rows: R, columns: C) -> Self where
R: RangeBounds<usize>,
C: RangeBounds<usize>,
pub fn override_split_line(&mut self, row: usize, line: impl Into<String>)
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Grid
impl Send for Grid
impl Sync for Grid
impl Unpin for Grid
impl UnwindSafe for Grid
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more