Struct ruscii::terminal::Canvas

source ·
pub struct Canvas { /* private fields */ }
Expand description

An object that holds the data for a grid of VisualElements for a single frame.

Implementations§

source§

impl Canvas

source

pub fn new(dimension: Vec2, default_element: &VisualElement) -> Canvas

Constructs a Canvas with the given dimension and each cell set to the given VisualElement as a default.

source

pub fn default_element(&self) -> &VisualElement

source

pub fn set_default_element(&mut self, element: &VisualElement)

Sets the current Canvas’s default element, to which every cell is reset when Canvas::clear is called.

source

pub fn dimension(&self) -> Vec2

source

pub fn contains(&self, pos: Vec2) -> bool

Checks if the point represented by the given pos would be within the dimensions of the Canvas.

The dimensions are sizes while the pos are indices.

let canvas = Canvas::new(Vec2::xy(10, 20), &VisualElement::default());
let a = Vec2::xy(10, 20);
let b = Vec2::xy(9, 19);

assert!(!canvas.contains(a));
assert!(canvas.contains(b));

A Vec2 with any negative components will always evaluate false.

let canvas = Canvas::new(Vec2::xy(10, 20), &VisualElement::default());
let p = Vec2::xy(-1, -3);

assert!(!canvas.contains(p));
source

pub fn elem(&self, pos: Vec2) -> Option<&VisualElement>

Returns a reference to the Canvas cell at the given pos if that pos is within the Canvas dimensions, None otherwise.

source

pub fn elem_mut(&mut self, pos: Vec2) -> Option<&mut VisualElement>

Returns a mutable reference to the Canvas cell at the given pos if that pos is within the Canvas dimensions, None otherwise.

source

pub fn clear(&mut self)

Clears all of the VisualElement cells in the grid by setting them to clones of the default element.

source

pub fn fill(&mut self, elem: &VisualElement)

Sets every cell to the given elem.

source

pub fn data(&self) -> &Vec<VisualElement>

Returns a reference to all the data the Canvas holds.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.