[go: up one dir, main page]

Canvas

Struct Canvas 

Source
pub struct Canvas<'a> {
    pub buffer: &'a mut [u8],
    pub width: usize,
    pub height: usize,
    pub stride: usize,
    pub pixel_size: usize,
    pub endianness: Endian,
}
Expand description

The canvas object acts as a wrapper around a buffer, providing information and functions for drawing

Fields§

§buffer: &'a mut [u8]

A buffer for the canvas to draw to

§width: usize

The width in pixels of the canvas

§height: usize

The height in pixels of the canvas

§stride: usize

The number of bytes between each line of pixels on the canvas

§pixel_size: usize

The number of bytes contained in each pixel

§endianness: Endian

The endianness of the canvas

Implementations§

Source§

impl<'a> Canvas<'a>

Source

pub fn new( buffer: &'a mut [u8], width: usize, height: usize, stride: usize, endianness: Endian, ) -> Canvas<'a>

Creates a new canvas object

Source

pub fn draw<D: Drawable>(&mut self, drawable: &D)

Draws an object that implements the Drawable trait to the buffer

Source

pub fn draw_point(&mut self, x: usize, y: usize, color: [u8; 4])

Draws a pixel at the x and y coordinate

Source

pub fn clear(&mut self)

Clears the entire canvas buffer by zeroing it

Auto Trait Implementations§

§

impl<'a> Freeze for Canvas<'a>

§

impl<'a> RefUnwindSafe for Canvas<'a>

§

impl<'a> Send for Canvas<'a>

§

impl<'a> Sync for Canvas<'a>

§

impl<'a> Unpin for Canvas<'a>

§

impl<'a> !UnwindSafe for Canvas<'a>

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.