Struct Buffer

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

A screen buffer that can be rendered to, has a size

This is the backbone of ascii-forge

Example

use ascii_forge::prelude::*;

// A 30x30 buffer window
let mut buffer = Buffer::new(30, 30);

// Render Hello World to the top left of the buffer
render!(
    buffer, {
        (0, 0) => "Hello World!"
    }
);

Implementations§

Source§

impl Buffer

Source

pub fn new(size: impl Into<Vec2>) -> Self

Creates a new buffer of empty cells with the given size.

Source

pub fn size(&self) -> Vec2

Returns the current size of the buffer.

Source

pub fn set<C: Into<Cell>>(&mut self, loc: impl Into<Vec2>, cell: C)

Sets a cell at the given location to the given cell

Source

pub fn fill<C: Into<Cell>>(&mut self, cell: C)

Sets all cells at the given location to the given cell

Source

pub fn get(&self, loc: impl Into<Vec2>) -> &Cell

Returns a reverence to the cell at the given location.

Source

pub fn get_mut(&mut self, loc: impl Into<Vec2>) -> &mut Cell

Returns a mutable reference to the cell at the given location.

Source

pub fn clear(&mut self)

Clears the buffer

Source

pub fn diff<'a>(&self, other: &'a Buffer) -> Vec<(Vec2, &'a Cell)>

Returns the cells and locations that are different between the two buffers

Source

pub fn shrink(&mut self)

Shrinks the buffer to the given size by dropping any cells that are only whitespace

Source

pub fn resize(&mut self, new_size: impl Into<Vec2>)

Resizes the buffer while retaining elements that have already been rendered

Source

pub fn sized_element<R: Render>(item: R) -> Self

Creates a Buffer from the given element with the minimum size it could have for that element. Useful for if you want to store any set of render elements in a custom element.

Trait Implementations§

Source§

impl AsMut<Buffer> for Buffer

Source§

fn as_mut(&mut self) -> &mut Buffer

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsMut<Buffer> for Window

Source§

fn as_mut(&mut self) -> &mut Buffer

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl Debug for Buffer

Source§

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

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

impl Render for Buffer

Source§

fn render(&self, loc: Vec2, buffer: &mut Buffer) -> Vec2

Source§

fn size(&self) -> Vec2

Auto Trait Implementations§

§

impl Freeze for Buffer

§

impl RefUnwindSafe for Buffer

§

impl Send for Buffer

§

impl Sync for Buffer

§

impl Unpin for Buffer

§

impl UnwindSafe for Buffer

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, 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.