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§
Sourcefn pixel(&self, x: Self::A, y: Self::A) -> Result<S::U, String>
fn pixel(&self, x: Self::A, y: Self::A) -> Result<S::U, String>
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.