pub struct Grid {
pub start_x: usize,
pub start_y: usize,
pub end_x: usize,
pub end_y: usize,
}
Expand description
A grid - basically, a square meant to resemble a portion of a terminal. Can be split up into other grids. Cloning a grid is bad practice! Use it only if you must.
Fields§
§start_x: usize
§start_y: usize
§end_x: usize
§end_y: usize
Implementations§
Source§impl Grid
impl Grid
Sourcepub fn split(&mut self, strategy: &SplitStrategy) -> Option<Grid>
pub fn split(&mut self, strategy: &SplitStrategy) -> Option<Grid>
Splits the grid into two others based on a SplitStrategy. With the default split strategy, the entire grid will go into the returned grid, leaving the first one empty. Expect to use this function a lot.
§Return value
Returns None if no new grid can be created - either because the grid is already empty or because it’s below the minimum size.
§Examples
let mut grid = Frame::new(0, 0, 10, 10).next_frame();
let second = grid.split(&SplitStrategy::new().max_y(5, Alignment::Minus));
assert_eq!(second, Some(Grid {start_x: 0, start_y: 0, end_x: 10, end_y: 5}));
assert_eq!(grid, Grid {start_x: 0, start_y: 5, end_x: 10, end_y: 10});
let cant_be_made = grid.split(&SplitStrategy::new().min_y(6));
assert_eq!(cant_be_made, None);
let takes_up_all = grid.split(&SplitStrategy::new());
assert_eq!(takes_up_all, Some(Grid {start_x: 0, start_y: 5, end_x: 10, end_y: 10}));
assert_eq!(grid, Grid {start_x: 10, start_y: 10, end_x: 10, end_y: 10});
let cant_be_made = grid.split(&SplitStrategy::new());
assert_eq!(cant_be_made, None);
Sourcepub fn extend(&mut self, grid: Grid) -> Result<(), Grid>
pub fn extend(&mut self, grid: Grid) -> Result<(), Grid>
Extends the grid in the either direction, either positive or negative, if the input is compatible (ie grids are next to each other and of similar dimensions) If the two grids are incompatible, it returns an error and gives the grid back.
§Example
let mut grid = grid::Frame::new(0, 0, 10, 10).next_frame();
let mut second_grid = grid.split(&grid::SplitStrategy::new().max_y(5, grid::Alignment::Plus)).ok_or(())?;
assert_eq!(grid.end_y, 5);
assert!(grid.extend(second_grid).is_ok());
assert_eq!(grid.end_y, 10);
let incompatible_grid = grid::Frame::new(4, 4, 8, 8).next_frame();
assert!(grid.extend(incompatible_grid).is_err());
Sourcepub fn into_process(self, strategy: DividerStrategy) -> DrawProcess
pub fn into_process(self, strategy: DividerStrategy) -> DrawProcess
Converts the grid into a DrawProcess. The draw process can then be used to draw onto the terminal.
§Examples
let mut grid = Frame::new(0, 0, 10, 10).next_frame();
let mut process = grid.into_process(DividerStrategy::End);
process.add_to_section("Some text".to_string(), &mut Truncate, Alignment::Minus);