Skip to main content

Grid

Struct Grid 

Source
pub struct Grid { /* private fields */ }
Expand description

A layout widget that arranges children in a grid specified by rows and columns. A layout widget that arranges children in a grid specified by rows and columns.

Each row and column is defined by a Unit, which you can read more about in its documentation.

Children can be placed by specifying their zero-based column and row indices.

§Example

let mut grid = Grid::new(
    vec![Unit::Length(3), Unit::Length(5), Unit::Fill(1)],
    vec![Unit::Fill(1), Unit::Length(1), Unit::Fill(1)],
);
grid.push("Grid", 1, 1);

let mut term = Term::default();
term.render(grid)?;

Implementations§

Source§

impl Grid

Source

pub fn new<T1, T2>(cols: T1, rows: T2) -> Self
where T1: IntoIterator, T1::Item: Into<Unit>, T2: IntoIterator, T2::Item: Into<Unit>,

Creates a new Grid from columns and rows specifications.

Both cols and rows accept any iterable of types convertible into Unit.

§Example
let mut grid = Grid::new([3, 5, 3], [3, 1, 1]);
Source

pub fn empty() -> Self

Creates an new empty Grid with no rows or columns.

Source

pub fn row(&mut self, row: Unit)

Adds a new row definition to the Grid.

Source

pub fn col(&mut self, col: Unit)

Adds given column to current columns

Source

pub fn add_child<T>(&mut self, child: T, col: usize, row: usize)
where T: Into<Element>,

👎Deprecated since 0.6.0: Kept for compatibility purposes; use push function instead

Adds child to the grid to given row and column

Source

pub fn push<T>(&mut self, child: T, col: usize, row: usize)
where T: Into<Element>,

Adds a child widget at the specified column and row.

§Parameters
  • child: The widget to add (any type convertible to Element)
  • col: Zero-based column index (x)
  • row: Zero-based row index (y)

Trait Implementations§

Source§

impl Debug for Grid

Source§

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

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

impl Default for Grid

Source§

fn default() -> Grid

Returns the “default value” for a type. Read more
Source§

impl From<Grid> for Box<dyn Widget>

Source§

fn from(value: Grid) -> Self

Converts to this type from the input type.
Source§

impl From<Grid> for Element

Source§

fn from(value: Grid) -> Self

Converts to this type from the input type.
Source§

impl Widget for Grid

Source§

fn render(&self, buffer: &mut Buffer, rect: Rect, cache: &mut Cache)

Renders the widget into the given Buffer within the provided Rect bounds.
Source§

fn height(&self, size: &Vec2) -> usize

Returns the height of the Widget based on the width of the given size.
Source§

fn width(&self, size: &Vec2) -> usize

Returns the width of the Widget based on the height of the given size.
Source§

fn children(&self) -> Vec<&Element>

Gets widget’s children

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> 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> Scale<T> for T

Source§

fn scale(self) -> T

Scale this type to the given other type.
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.