Grid

Struct Grid 

Source
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

Source

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);
Source

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());
Source

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);

Trait Implementations§

Source§

impl Clone for Grid

Source§

fn clone(&self) -> Grid

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Grid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Grid

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Grid

Source§

fn eq(&self, other: &Grid) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Grid

Source§

impl StructuralPartialEq for Grid

Auto Trait Implementations§

§

impl Freeze for Grid

§

impl RefUnwindSafe for Grid

§

impl Send for Grid

§

impl Sync for Grid

§

impl Unpin for Grid

§

impl UnwindSafe for Grid

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.