Struct Canvas

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

Logical clone of Frame that exposes backend functionality for users without breaking the API rules

§Examples

use oxide::Canvas;

let mut canvas = Canvas::new(60, 10);

let (rows, cols) = canvas.size();
// Set the entire canvas to '-' character
for i in 0..cols*rows {
    let y = i / cols;
    let x = i % cols;
    let mut cell = canvas.get_mut(x, y).unwrap();
    cell.set_ch('-');
}

Implementations§

Source§

impl Canvas

Source

pub fn new(cols: usize, rows: usize) -> Canvas

Constructs a new Canvas object cols wide by rows high

§Examples
use oxide::Canvas;

let mut canvas = Canvas::new(60, 10); 
Source

pub fn size(&self) -> Size

Returns the size of the canvas

§Examples
use oxide::Canvas;

let mut canvas = Canvas::new(60, 10);

assert_eq!(canvas.size(), (60, 10));
Source

pub fn cellvec(&self) -> &Vec<Cell>

Returns a reference to the vector of cells that lie within the canvas

Source

pub fn cellvec_mut(&mut self) -> &mut Vec<Cell>

Returns a mutable reference to the vector of cells that lie within the canvas

Source

pub fn clear(&mut self, blank: Cell)

Clears the canvas with a blank Cell

Source

pub fn pos_to_index(&self, x: usize, y: usize) -> Option<usize>

Converts a position on the screen to the relative coordinate within the Canvas cell buffer

Source

pub fn get(&self, x: usize, y: usize) -> Option<&Cell>

Returns a reference to the cell at the specified position (x,y), in the form of an Option. If no cell exists at that position, then None

Source

pub fn get_mut(&mut self, x: usize, y: usize) -> Option<&mut Cell>

Returns a mutable reference to the cell at the specified position (x, y), in the form of an Option. If no cell exists at that position, then None

Source

pub fn origin(&self) -> Pos

The location of the canvas

Source

pub fn set_origin(&mut self, new_origin: Pos)

Mantually sets the location of the canvas

Trait Implementations§

Source§

impl Widget for Canvas

Source§

fn draw(&mut self, parent: &mut dyn CellAccessor)

Draws the widget to the valid CellAccessor passed
Source§

fn pack( &mut self, parent: &dyn HasSize, halign: HorizontalAlign, valign: VerticalAlign, margin: (usize, usize), )

Aligns the widget with the parent as reference
Source§

fn resize(&mut self, new_size: Size)

Resize the given widget to new dimensions given by Size
Source§

fn draw_box(&mut self)

Expose the painter trait draw_box for all widgets, which outlines the space enclosed within the widget
Source§

fn frame(&self) -> &Frame

Return a reference the renderer, Base in general cases
Source§

fn frame_mut(&mut self) -> &mut Frame

Return a mutable reference to the renderer, Base in general cases

Auto Trait Implementations§

§

impl Freeze for Canvas

§

impl RefUnwindSafe for Canvas

§

impl Send for Canvas

§

impl Sync for Canvas

§

impl Unpin for Canvas

§

impl UnwindSafe for Canvas

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.