Struct CanvasDisplay

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

This display is based on a HTML Canvas and is used as draw target for the embedded graphics crate.

§Example

use canvas_display::prelude::*;
use embedded_graphics::{
    image::{Image, ImageRaw, ImageRawLE},
    pixelcolor::Rgb565,
    prelude::*,
    primitives::rectangle::Rectangle,
    style::PrimitiveStyleBuilder,
    };

let mut display = CanvasDisplay::new(160, 128, "canvas").unwrap();

let style = PrimitiveStyleBuilder::new().fill_color(Rgb565::BLACK).build();
let black_backdrop = Rectangle::new(Point::new(0, 0), Point::new(160, 128)).into_styled(style);
black_backdrop.draw(&mut display).unwrap();

// draw ferris
let image_raw: ImageRawLE<Rgb565> = ImageRaw::new(include_bytes!("../../../assets/ferris.raw"), 86, 64);
let image: Image<_, Rgb565> = Image::new(&image_raw, Point::new(34, 8));
image.draw(&mut display).unwrap();

Implementations§

Source§

impl CanvasDisplay

Source

pub fn new(width: u32, height: u32, canvas: &str) -> Result<Self, String>

Creates a new canvas display with the given. The canvas get the given with and height and will be referenced by the given canvas css id. If no canvas with this id exists a canvas will be created.

Source

pub fn context(&self) -> &CanvasRenderingContext2d

Gets the current rendering context 2d.

Trait Implementations§

Source§

impl Clone for CanvasDisplay

Source§

fn clone(&self) -> CanvasDisplay

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CanvasDisplay

Source§

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

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

impl DrawTarget<Rgb565> for CanvasDisplay

Source§

type Error = String

Error type to return when a drawing operation fails. Read more
Source§

fn draw_pixel(&mut self, pixel: Pixel<Rgb565>) -> Result<(), Self::Error>

Draws a pixel on the display.
Source§

fn draw_line( &mut self, item: &Styled<Line, PrimitiveStyle<Rgb565>>, ) -> Result<(), Self::Error>

Draws a styled line primitive. Read more
Source§

fn draw_rectangle( &mut self, item: &Styled<Rectangle, PrimitiveStyle<Rgb565>>, ) -> Result<(), Self::Error>

Draws a styled rectangle primitive. Read more
Source§

fn draw_circle( &mut self, item: &Styled<Circle, PrimitiveStyle<Rgb565>>, ) -> Result<(), Self::Error>

Draws a styled circle primitive. Read more
Source§

fn draw_image<'a, 'b, I>( &mut self, item: &'a Image<'b, I, Rgb565>, ) -> Result<(), Self::Error>

Draws an image with known size Read more
Source§

fn size(&self) -> Size

Returns the dimensions of the DrawTarget in pixels.
Source§

fn draw_iter<T>(&mut self, item: T) -> Result<(), Self::Error>
where T: IntoIterator<Item = Pixel<C>>,

Draws an object from an iterator over its pixels.
Source§

fn clear(&mut self, color: C) -> Result<(), Self::Error>
where Self: Sized,

Clears the display with the supplied color. Read more
Source§

fn draw_triangle( &mut self, item: &Styled<Triangle, PrimitiveStyle<C>>, ) -> Result<(), Self::Error>

Draws a styled triangle primitive. Read more
Source§

impl PartialEq for CanvasDisplay

Source§

fn eq(&self, other: &CanvasDisplay) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for CanvasDisplay

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.