Struct waow::Canvas

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

Canvas that can be drawn to and gets displayed on the screen

Implementations§

source§

impl Canvas

source

pub fn new(config: &CanvasConfiguration) -> Self

source

pub fn get_size(&self) -> (u32, u32)

Gets the (width, height) of the canvas in pixels

source

pub fn draw_to_buffer(&mut self, frame: &mut [u8])

source§

impl Canvas

source

pub fn draw_shape(&mut self, shape: &(impl Drawable + Clone + 'static))

Draws an arbitrary shape to the canvas

See Drawable for examples

source

pub fn draw_square( &mut self, x: i16, y: i16, size: i16, fill: Color, border: Option<(Color, i16)> )

Draws a square with the specified position, size, and color

§Examples
use waow::*;

struct App {}
impl Run for App {
  fn start(&mut self, _canvas: &mut Canvas) {}
  fn draw(&mut self, canvas: &mut Canvas, _input: &Input) {
    canvas.draw_square(10, 10, 30, Color::from_rgba(0.0, 1.0, 0.5, 1.0), None);
  }
}
use waow::*;

struct App {}
impl Run for App {
  fn start(&mut self, _canvas: &mut Canvas) {}
  fn draw(&mut self, canvas: &mut Canvas, _input: &Input) {
    canvas.draw_square(
      10,
      10,
      30,
      Color::from_rgba(0.0, 1.0, 0.5, 1.0),
      Some((Color::from_rgba(1.0, 1.0, 1.0, 1.0), 3)),
    );
  }
}
source

pub fn draw_rect( &mut self, x: i16, y: i16, width: i16, height: i16, fill: Color, border: Option<(Color, i16)> )

Draws a rectangle with the specified position, width, height, and color

§Examples
use waow::*;

struct App {}
impl Run for App {
  fn start(&mut self, _canvas: &mut Canvas) {}
  fn draw(&mut self, canvas: &mut Canvas, _input: &Input) {
    canvas.draw_rect(50, 10, 20, 50, Color::from_rgba(0.0, 0.5, 1.0, 1.0), None);
  }
}
use waow::*;

struct App {}
impl Run for App {
  fn start(&mut self, _canvas: &mut Canvas) {}
  fn draw(&mut self, canvas: &mut Canvas, _input: &Input) {
    canvas.draw_rect(
      10, 10, 30, 50,
      Color::from_rgba(0.0, 1.0, 0.5, 1.0),
      Some((Color::from_rgba(1.0, 1.0, 1.0, 1.0), 3)),
    );
  }
}
source

pub fn draw_image(&mut self, image: &Image)

Draws an image object to the canvas

§Examples
use waow::*;

struct App {}
impl Run for App {
  fn start(&mut self, _canvas: &mut Canvas) {}
  fn draw(&mut self, canvas: &mut Canvas, _input: &Input) {
    let img = shapes::Image::new(30, 30, 100, 100);

    canvas.draw_image(&img);
  }
}

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

source§

fn downcast(&self) -> &T

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

§

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

§

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.
source§

impl<T> Upcast<T> for T

source§

fn upcast(&self) -> Option<&T>