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, Border};
let mut grid = Grid::new(2, 2);
grid.set(
Entity::Global,
Settings::new()
.text("Hello World")
.border(Border {
right: Some(' '),
..Default::default()
})
);
assert_eq!(
grid.to_string(),
"Hello World Hello World \n\
Hello World Hello World "
);
Not empty initialization but empty content
use papergrid::Grid;
let mut grid = Grid::new(2, 2);
assert_eq!(grid.to_string(), "\n");
Empty
use papergrid::Grid;
let mut grid = Grid::new(0, 0);
assert_eq!(grid.to_string(), "");
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, Borders};
let mut grid = Grid::new(2, 2);
grid.set_borders(Borders {
vertical_intersection: Some('|'),
horizontal: Some('-'),
..Default::default()
});
grid.set(Entity::Row(0), Settings::new().text("row 1"));
grid.set(Entity::Row(1), Settings::new().text("row 2"));
assert_eq!(
grid.to_string(),
"row 1|row 1\n\
----- -----\n\
row 2|row 2"
)
sourcepub fn set_margin(&mut self, margin: Margin)
pub fn set_margin(&mut self, margin: Margin)
Set a Margin
value.
sourcepub fn get_margin(&self) -> &Margin
pub fn get_margin(&self) -> &Margin
Returns a Margin
value currently set.
sourcepub fn clear_theme(&mut self)
pub fn clear_theme(&mut self)
Clears all theme changes. And sets it to default.
sourcepub fn set_borders(&mut self, borders: Borders<char>)
pub fn set_borders(&mut self, borders: Borders<char>)
Set the Borders
value as currect one.
sourcepub fn set_tab_width(&mut self, width: usize)
pub fn set_tab_width(&mut self, width: usize)
Set the Borders
value as currect one.
sourcepub fn get_borders(&self) -> &Borders<char>
pub fn get_borders(&self) -> &Borders<char>
Returns a current Borders
structure.
sourcepub fn set_border(&mut self, entity: Entity, border: Border)
pub fn set_border(&mut self, entity: Entity, border: Border)
Set border set a border value to all cells in Entity
.
sourcepub fn remove_border(&mut self, entity: Entity)
pub fn remove_border(&mut self, entity: Entity)
Sets off all borders possible on the Entity
.
It doesn’t changes globaly set borders through Grid::set_borders
.
sourcepub fn set_split_line(&mut self, row: usize, line: Line<char>)
pub fn set_split_line(&mut self, row: usize, line: Line<char>)
Set the border line by row index.
Row 0
means the top row.
Row grid.count_rows()
means the bottom row.
sourcepub fn remove_split_line(&mut self, row: usize)
pub fn remove_split_line(&mut self, row: usize)
Sets off the border line by row index if any were set
Row 0
means the top row.
Row grid.count_rows()
means the bottom row.
sourcepub fn get_split_line(&self, row: usize) -> Option<&Line<char>>
pub fn get_split_line(&self, row: usize) -> Option<&Line<char>>
Gets a overriden line.
Row 0
means the top row.
Row grid.count_rows()
means the bottom row.
sourcepub fn get_settings(&self, row: usize, col: usize) -> Settings
pub fn get_settings(&self, row: usize, col: usize) -> Settings
This function returns a settings of a cell
sourcepub fn get_border(&self, (row, col): Position) -> Border<char>
pub fn get_border(&self, (row, col): Position) -> Border<char>
Returns a border of a cell.
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
This function returns content without any style changes
sourcepub fn get_cell_content_formatted(&self, row: usize, column: usize) -> String
pub fn get_cell_content_formatted(&self, row: usize, column: usize) -> String
This function returns content with style changes
sourcepub fn get_string_width(&self, row: usize, column: usize) -> usize
pub fn get_string_width(&self, row: usize, column: usize) -> usize
This function returns a string width.
sourcepub fn count_rows(&self) -> usize
pub fn count_rows(&self) -> usize
This function returns an amount of rows on the grid
sourcepub fn count_columns(&self) -> usize
pub fn count_columns(&self) -> usize
This function returns an amount of columns on the grid
sourcepub fn resize(&self, count_rows: usize, count_cols: usize) -> Self
pub fn resize(&self, count_rows: usize, count_cols: usize) -> Self
Creates a new Grid from original, Coping the things like styles and borders.
It doesn’t copy styles which were set for specific Entity.
sourcepub fn total_width(&self) -> usize
pub fn total_width(&self) -> usize
Returns a total width of table, including split lines.
sourcepub fn override_split_line(&mut self, row: usize, line: impl Into<String>)
pub fn override_split_line(&mut self, row: usize, line: impl Into<String>)
Override the split line with a custom text.
If borders are not set the string won’t be rendered.
pub fn build_widths(&self) -> Vec<usize>
pub fn estimate_total_width(&self, widths: &[usize]) -> usize
pub fn build_min_widths(&self) -> Vec<usize>
sourcepub fn collect_cells(&self) -> Vec<Vec<Vec<String>>>
pub fn collect_cells(&self) -> Vec<Vec<Vec<String>>>
The function returns all cells by lines.
It’s considered that string_width
on these cells will be the same as the one which will be used in rendering.
sourcepub fn is_cell_visible(&self, pos: Position) -> bool
pub fn is_cell_visible(&self, pos: Position) -> bool
The function returns whether the cells will be rendered or it will be hidden by a cell with a span.
sourcepub fn set_padding(&mut self, entity: Entity, padding: Padding)
pub fn set_padding(&mut self, entity: Entity, padding: Padding)
Set a padding to a given cells.
sourcepub fn get_padding(&self, entity: Entity) -> &Padding
pub fn get_padding(&self, entity: Entity) -> &Padding
Get a padding for a given Entity.
sourcepub fn set_formatting(&mut self, entity: Entity, formatting: Formatting)
pub fn set_formatting(&mut self, entity: Entity, formatting: Formatting)
Set a formatting to a given cells.
sourcepub fn get_formatting(&self, entity: Entity) -> &Formatting
pub fn get_formatting(&self, entity: Entity) -> &Formatting
Get a formatting settings for a given Entity.
sourcepub fn set_alignment_vertical(
&mut self,
entity: Entity,
alignment: AlignmentVertical
)
pub fn set_alignment_vertical(
&mut self,
entity: Entity,
alignment: AlignmentVertical
)
Set a vertical alignment to a given cells.
sourcepub fn get_alignment_vertical(&self, entity: Entity) -> &AlignmentVertical
pub fn get_alignment_vertical(&self, entity: Entity) -> &AlignmentVertical
Get a vertical alignment for a given Entity.
sourcepub fn set_alignment_horizontal(
&mut self,
entity: Entity,
alignment: AlignmentHorizontal
)
pub fn set_alignment_horizontal(
&mut self,
entity: Entity,
alignment: AlignmentHorizontal
)
Set a horizontal alignment to a given cells.
sourcepub fn get_alignment_horizontal(&self, entity: Entity) -> &AlignmentHorizontal
pub fn get_alignment_horizontal(&self, entity: Entity) -> &AlignmentHorizontal
Get a horizontal alignment for a given Entity.
sourcepub fn get_column_span(&self, (row, col): Position) -> Option<usize>
pub fn get_column_span(&self, (row, col): Position) -> Option<usize>
Get a span value of the cell, if any is set.
sourcepub fn iter_column_spans(&self) -> impl Iterator<Item = (Position, usize)> + '_
pub fn iter_column_spans(&self) -> impl Iterator<Item = (Position, usize)> + '_
Get a span value of the cell, if any is set.
sourcepub fn has_column_spans(&self) -> bool
pub fn has_column_spans(&self) -> bool
Verifies if there’s any spans set.
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 · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more