DynamicCanvas

Trait DynamicCanvas 

Source
pub trait DynamicCanvas<S: Pixel>: DynamicWidget {
    type A: NumCast;

    // Required methods
    fn pixel(&self, x: Self::A, y: Self::A) -> Result<S::U, String>
       where [(); { _ }]:;
    fn set_pixel(
        &mut self,
        x: Self::A,
        y: Self::A,
        value: S::U,
    ) -> Result<(), String>
       where [(); { _ }]:;

    // Provided method
    fn draw<D: DynamicDrawable<N>, const N: usize>(
        &mut self,
        drawable: &D,
        value: S::U,
    )
       where Self: Sized,
             [(); { _ }]: { ... }
}
Expand description

Defines an object that you can draw on and query pixels from.

Required Associated Types§

Required Methods§

Source

fn pixel(&self, x: Self::A, y: Self::A) -> Result<S::U, String>
where [(); { _ }]:,

Returns a bool representing the state of the pixel at the specified coordinate.

§Examples
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

use console_display::{
    console_display::DynamicConsoleDisplay,
    display_driver::DisplayDriver,
    pixel::monochrome_pixel::SinglePixel,
    pixel_display::DynamicPixelDisplay,
    drawing::DynamicCanvas
};

let disp: DisplayDriver<DynamicPixelDisplay<SinglePixel>> = DisplayDriver::new(
    DynamicPixelDisplay::<SinglePixel>::build_from_data(
        6,
        6,
        &vec![
            true, true, true, true,  true, true, // 0
            true, true, true, true,  true, true, // 1
            true, true, true, false, true, true, //-2-
            true, true, true, true,  true, true, // 3
            true, true, true, true,  true, true, // 4
            true, true, true, true,  true, true, // 5
        ] //  0     1     2   --3--    4     5
    ).expect("Could not construct display.")
);
// Replace with actual error handling

let pixel = disp.pixel(3, 2);

assert_eq!(pixel, Ok(false));

let pixel = disp.pixel(5, 6);

assert!(matches!(pixel, Err(_)));
§Errors

Returns an error if the pixel coordinates are out of bounds.

§Panics

If the index of a subpixel is out of bounds. This should not happen and is subject to change in the future.

Source

fn set_pixel( &mut self, x: Self::A, y: Self::A, value: S::U, ) -> Result<(), String>
where [(); { _ }]:,

Set a pixel at the specified coordinate with a given value.

§Errors

Returns an error if the pixel coordinates are out of bounds.

§Panics

If the index of a subpixel is out of bounds. This should not happen and is subject to change in the future.

Provided Methods§

Source

fn draw<D: DynamicDrawable<N>, const N: usize>( &mut self, drawable: &D, value: S::U, )
where Self: Sized, [(); { _ }]:,

Draw a drawable/shape onto a canvas with the specified pixel type/brush. Convenience method for inversing DynamicDrawable::draw by using double dispatch.

Implementors§