pub struct SimulatorDisplay<C> { /* private fields */ }
Expand description

Simulator display.

Implementations§

source§

impl<C: PixelColor> SimulatorDisplay<C>

source

pub fn with_default_color(size: Size, default_color: C) -> Self

Creates a new display filled with a color.

This constructor can be used if C doesn’t implement From<BinaryColor> or another default color is wanted.

source

pub fn get_pixel(&self, point: Point) -> C

Returns the color of the pixel at a point.

§Panics

Panics if point is outside the display.

source

pub fn diff( &self, other: &SimulatorDisplay<C>, ) -> Option<SimulatorDisplay<BinaryColor>>

Compares the content of this display with another display.

If both displays are equal None is returned, otherwise a difference image is returned. All pixels that are different will be filled with BinaryColor::On and all equal pixels with BinaryColor::Off.

§Panics

Panics if the both display don’t have the same size.

source§

impl<C> SimulatorDisplay<C>

source

pub fn new(size: Size) -> Self

Creates a new display.

The display is filled with C::from(BinaryColor::Off).

Examples found in repository?
examples/png-base64.rs (line 10)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() {
    let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));

    let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
    let centered = TextStyleBuilder::new()
        .baseline(Baseline::Middle)
        .alignment(Alignment::Center)
        .build();

    Text::with_text_style(
        "embedded-graphics",
        display.bounding_box().center(),
        large_text,
        centered,
    )
    .draw(&mut display)
    .unwrap();

    let output_settings = OutputSettingsBuilder::new().scale(2).build();
    let output_image = display.to_grayscale_output_image(&output_settings);

    println!(
        "<img src=\"data:image/png;base64,{}\">",
        output_image.to_base64_png().unwrap()
    );
}
More examples
Hide additional examples
examples/png-file.rs (line 10)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() {
    let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));

    let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
    let centered = TextStyleBuilder::new()
        .baseline(Baseline::Middle)
        .alignment(Alignment::Center)
        .build();

    Text::with_text_style(
        "embedded-graphics",
        display.bounding_box().center(),
        large_text,
        centered,
    )
    .draw(&mut display)
    .unwrap();

    let output_settings = OutputSettingsBuilder::new().scale(2).build();
    let output_image = display.to_rgb_output_image(&output_settings);

    let path = std::env::args_os()
        .nth(1)
        .expect("expected PNG file name argument");
    output_image.save_png(path).unwrap();
}
examples/themes.rs (line 12)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() {
    let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));

    let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
    let centered = TextStyleBuilder::new()
        .baseline(Baseline::Middle)
        .alignment(Alignment::Center)
        .build();

    Text::with_text_style(
        "embedded-graphics",
        display.bounding_box().center(),
        large_text,
        centered,
    )
    .draw(&mut display)
    .unwrap();

    // Uncomment one of the `theme` lines to use a different theme.
    let output_settings = OutputSettingsBuilder::new()
        //.theme(BinaryColorTheme::LcdGreen)
        //.theme(BinaryColorTheme::LcdWhite)
        .theme(BinaryColorTheme::LcdBlue)
        //.theme(BinaryColorTheme::OledBlue)
        //.theme(BinaryColorTheme::OledWhite)
        .build();

    let mut window = Window::new("Themes", &output_settings);
    window.show_static(&display);
}
examples/input-handling.rs (line 43)
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
fn main() -> Result<(), core::convert::Infallible> {
    let mut display: SimulatorDisplay<Rgb888> = SimulatorDisplay::new(Size::new(800, 480));
    let mut window = Window::new("Click to move circle", &OutputSettings::default());

    let mut position = Point::new(200, 200);
    Circle::with_center(position, 200)
        .into_styled(PrimitiveStyle::with_fill(FOREGROUND_COLOR))
        .draw(&mut display)?;

    'running: loop {
        window.update(&display);

        for event in window.events() {
            match event {
                SimulatorEvent::Quit => break 'running,
                SimulatorEvent::KeyDown { keycode, .. } => {
                    let delta = match keycode {
                        Keycode::Left => Point::new(-KEYBOARD_DELTA, 0),
                        Keycode::Right => Point::new(KEYBOARD_DELTA, 0),
                        Keycode::Up => Point::new(0, -KEYBOARD_DELTA),
                        Keycode::Down => Point::new(0, KEYBOARD_DELTA),
                        _ => Point::zero(),
                    };
                    let new_position = position + delta;
                    move_circle(&mut display, position, new_position)?;
                    position = new_position;
                }
                SimulatorEvent::MouseButtonUp { point, .. } => {
                    move_circle(&mut display, position, point)?;
                    position = point;
                }
                _ => {}
            }
        }
    }

    Ok(())
}
source§

impl<C> SimulatorDisplay<C>
where C: PixelColor + Into<Rgb888>,

source

pub fn to_rgb_output_image( &self, output_settings: &OutputSettings, ) -> OutputImage<Rgb888>

Converts the display contents into a RGB output image.

§Examples
use embedded_graphics::{pixelcolor::Rgb888, prelude::*};
use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay};

let output_settings = OutputSettingsBuilder::new().scale(2).build();

let display = SimulatorDisplay::<Rgb888>::new(Size::new(128, 64));

// draw something to the display

let output_image = display.to_rgb_output_image(&output_settings);
assert_eq!(output_image.size(), Size::new(256, 128));

// use output image:
// example: output_image.save_png("out.png")?;
Examples found in repository?
examples/png-file.rs (line 28)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() {
    let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));

    let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
    let centered = TextStyleBuilder::new()
        .baseline(Baseline::Middle)
        .alignment(Alignment::Center)
        .build();

    Text::with_text_style(
        "embedded-graphics",
        display.bounding_box().center(),
        large_text,
        centered,
    )
    .draw(&mut display)
    .unwrap();

    let output_settings = OutputSettingsBuilder::new().scale(2).build();
    let output_image = display.to_rgb_output_image(&output_settings);

    let path = std::env::args_os()
        .nth(1)
        .expect("expected PNG file name argument");
    output_image.save_png(path).unwrap();
}
source

pub fn to_grayscale_output_image( &self, output_settings: &OutputSettings, ) -> OutputImage<Gray8>

Converts the display contents into a grayscale output image.

§Examples
use embedded_graphics::{pixelcolor::Gray8, prelude::*};
use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay};

let output_settings = OutputSettingsBuilder::new().scale(2).build();

let display = SimulatorDisplay::<Gray8>::new(Size::new(128, 64));

// draw something to the display

let output_image = display.to_grayscale_output_image(&output_settings);
assert_eq!(output_image.size(), Size::new(256, 128));

// use output image:
// example: output_image.save_png("out.png")?;
Examples found in repository?
examples/png-base64.rs (line 28)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() {
    let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));

    let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
    let centered = TextStyleBuilder::new()
        .baseline(Baseline::Middle)
        .alignment(Alignment::Center)
        .build();

    Text::with_text_style(
        "embedded-graphics",
        display.bounding_box().center(),
        large_text,
        centered,
    )
    .draw(&mut display)
    .unwrap();

    let output_settings = OutputSettingsBuilder::new().scale(2).build();
    let output_image = display.to_grayscale_output_image(&output_settings);

    println!(
        "<img src=\"data:image/png;base64,{}\">",
        output_image.to_base64_png().unwrap()
    );
}
source§

impl<C> SimulatorDisplay<C>
where C: PixelColor + ToBytes, <C as ToBytes>::Bytes: AsRef<[u8]>,

source

pub fn to_be_bytes(&self) -> Vec<u8>

Converts the display content to big endian raw data.

source

pub fn to_le_bytes(&self) -> Vec<u8>

Converts the display content to little endian raw data.

source

pub fn to_ne_bytes(&self) -> Vec<u8>

Converts the display content to native endian raw data.

source§

impl<C> SimulatorDisplay<C>
where C: PixelColor + From<Rgb888>,

source

pub fn load_png<P: AsRef<Path>>(path: P) -> ImageResult<Self>

Loads a PNG file.

Trait Implementations§

source§

impl<C: Clone> Clone for SimulatorDisplay<C>

source§

fn clone(&self) -> SimulatorDisplay<C>

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<C: Debug> Debug for SimulatorDisplay<C>

source§

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

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

impl<C: PixelColor> DrawTarget for SimulatorDisplay<C>

source§

type Color = C

The pixel color type the targetted display supports.
source§

type Error = Infallible

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

fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
where I: IntoIterator<Item = Pixel<Self::Color>>,

Draw individual pixels to the display without a defined order. Read more
source§

fn fill_contiguous<I>( &mut self, area: &Rectangle, colors: I, ) -> Result<(), Self::Error>
where I: IntoIterator<Item = Self::Color>,

Fill a given area with an iterator providing a contiguous stream of pixel colors. Read more
source§

fn fill_solid( &mut self, area: &Rectangle, color: Self::Color, ) -> Result<(), Self::Error>

Fill a given area with a solid color. Read more
source§

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

Fill the entire display with a solid color. Read more
source§

impl<C: Hash> Hash for SimulatorDisplay<C>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<C: Ord> Ord for SimulatorDisplay<C>

source§

fn cmp(&self, other: &SimulatorDisplay<C>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<C> OriginDimensions for SimulatorDisplay<C>

source§

fn size(&self) -> Size

Returns the size of the bounding box.
source§

impl<C: PartialEq> PartialEq for SimulatorDisplay<C>

source§

fn eq(&self, other: &SimulatorDisplay<C>) -> 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<C: PartialOrd> PartialOrd for SimulatorDisplay<C>

source§

fn partial_cmp(&self, other: &SimulatorDisplay<C>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<C: Eq> Eq for SimulatorDisplay<C>

source§

impl<C> StructuralPartialEq for SimulatorDisplay<C>

Auto Trait Implementations§

§

impl<C> Freeze for SimulatorDisplay<C>

§

impl<C> RefUnwindSafe for SimulatorDisplay<C>
where C: RefUnwindSafe,

§

impl<C> Send for SimulatorDisplay<C>
where C: Send,

§

impl<C> Sync for SimulatorDisplay<C>
where C: Sync,

§

impl<C> Unpin for SimulatorDisplay<C>

§

impl<C> UnwindSafe for SimulatorDisplay<C>
where C: UnwindSafe,

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

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> Dimensions for T

source§

fn bounding_box(&self) -> Rectangle

Returns the bounding box.
source§

impl<T> DrawTargetExt for T
where T: DrawTarget,

source§

fn translated(&mut self, offset: Point) -> Translated<'_, T>

Creates a translated draw target based on this draw target. Read more
source§

fn cropped(&mut self, area: &Rectangle) -> Cropped<'_, T>

Creates a cropped draw target based on this draw target. Read more
source§

fn clipped(&mut self, area: &Rectangle) -> Clipped<'_, T>

Creates a clipped draw target based on this draw target. Read more
source§

fn color_converted<C>(&mut self) -> ColorConverted<'_, T, C>
where C: PixelColor + Into<<T as DrawTarget>::Color>,

Creates a color conversion draw target. 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> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.