pub struct SimulatorDisplay<C> { /* private fields */ }
Expand description
Simulator display.
Implementations§
Source§impl<C: PixelColor> SimulatorDisplay<C>
impl<C: PixelColor> SimulatorDisplay<C>
Sourcepub fn with_default_color(size: Size, default_color: C) -> Self
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.
Sourcepub fn diff(
&self,
other: &SimulatorDisplay<C>,
) -> Option<SimulatorDisplay<BinaryColor>>
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>
impl<C> SimulatorDisplay<C>
Sourcepub fn new(size: Size) -> Self
pub fn new(size: Size) -> Self
Creates a new display.
The display is filled with C::from(BinaryColor::Off)
.
Examples found in repository?
9fn main() {
10 let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
11
12 let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
13 let centered = TextStyleBuilder::new()
14 .baseline(Baseline::Middle)
15 .alignment(Alignment::Center)
16 .build();
17
18 Text::with_text_style(
19 "embedded-graphics",
20 display.bounding_box().center(),
21 large_text,
22 centered,
23 )
24 .draw(&mut display)
25 .unwrap();
26
27 let output_settings = OutputSettingsBuilder::new().scale(2).build();
28 let output_image = display.to_grayscale_output_image(&output_settings);
29
30 println!(
31 "<img src=\"data:image/png;base64,{}\">",
32 output_image.to_base64_png().unwrap()
33 );
34}
More examples
9fn main() {
10 let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
11
12 let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
13 let centered = TextStyleBuilder::new()
14 .baseline(Baseline::Middle)
15 .alignment(Alignment::Center)
16 .build();
17
18 Text::with_text_style(
19 "embedded-graphics",
20 display.bounding_box().center(),
21 large_text,
22 centered,
23 )
24 .draw(&mut display)
25 .unwrap();
26
27 let output_settings = OutputSettingsBuilder::new().scale(2).build();
28 let output_image = display.to_rgb_output_image(&output_settings);
29
30 let path = std::env::args_os()
31 .nth(1)
32 .expect("expected PNG file name argument");
33 output_image.save_png(path).unwrap();
34}
11fn main() {
12 let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
13
14 let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
15 let centered = TextStyleBuilder::new()
16 .baseline(Baseline::Middle)
17 .alignment(Alignment::Center)
18 .build();
19
20 Text::with_text_style(
21 "embedded-graphics",
22 display.bounding_box().center(),
23 large_text,
24 centered,
25 )
26 .draw(&mut display)
27 .unwrap();
28
29 // Uncomment one of the `theme` lines to use a different theme.
30 let output_settings = OutputSettingsBuilder::new()
31 //.theme(BinaryColorTheme::LcdGreen)
32 //.theme(BinaryColorTheme::LcdWhite)
33 .theme(BinaryColorTheme::LcdBlue)
34 //.theme(BinaryColorTheme::OledBlue)
35 //.theme(BinaryColorTheme::OledWhite)
36 .build();
37
38 let mut window = Window::new("Themes", &output_settings);
39 window.show_static(&display);
40}
42fn main() -> Result<(), core::convert::Infallible> {
43 let mut display: SimulatorDisplay<Rgb888> = SimulatorDisplay::new(Size::new(800, 480));
44 let mut window = Window::new("Click to move circle", &OutputSettings::default());
45
46 let mut position = Point::new(200, 200);
47 Circle::with_center(position, 200)
48 .into_styled(PrimitiveStyle::with_fill(FOREGROUND_COLOR))
49 .draw(&mut display)?;
50
51 'running: loop {
52 window.update(&display);
53
54 for event in window.events() {
55 match event {
56 SimulatorEvent::Quit => break 'running,
57 SimulatorEvent::KeyDown { keycode, .. } => {
58 let delta = match keycode {
59 Keycode::Left => Point::new(-KEYBOARD_DELTA, 0),
60 Keycode::Right => Point::new(KEYBOARD_DELTA, 0),
61 Keycode::Up => Point::new(0, -KEYBOARD_DELTA),
62 Keycode::Down => Point::new(0, KEYBOARD_DELTA),
63 _ => Point::zero(),
64 };
65 let new_position = position + delta;
66 move_circle(&mut display, position, new_position)?;
67 position = new_position;
68 }
69 SimulatorEvent::MouseButtonUp { point, .. } => {
70 move_circle(&mut display, position, point)?;
71 position = point;
72 }
73 _ => {}
74 }
75 }
76 }
77
78 Ok(())
79}
Source§impl<C> SimulatorDisplay<C>
impl<C> SimulatorDisplay<C>
Sourcepub fn to_rgb_output_image(
&self,
output_settings: &OutputSettings,
) -> OutputImage<Rgb888>
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?
9fn main() {
10 let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
11
12 let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
13 let centered = TextStyleBuilder::new()
14 .baseline(Baseline::Middle)
15 .alignment(Alignment::Center)
16 .build();
17
18 Text::with_text_style(
19 "embedded-graphics",
20 display.bounding_box().center(),
21 large_text,
22 centered,
23 )
24 .draw(&mut display)
25 .unwrap();
26
27 let output_settings = OutputSettingsBuilder::new().scale(2).build();
28 let output_image = display.to_rgb_output_image(&output_settings);
29
30 let path = std::env::args_os()
31 .nth(1)
32 .expect("expected PNG file name argument");
33 output_image.save_png(path).unwrap();
34}
Sourcepub fn to_grayscale_output_image(
&self,
output_settings: &OutputSettings,
) -> OutputImage<Gray8>
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?
9fn main() {
10 let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
11
12 let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
13 let centered = TextStyleBuilder::new()
14 .baseline(Baseline::Middle)
15 .alignment(Alignment::Center)
16 .build();
17
18 Text::with_text_style(
19 "embedded-graphics",
20 display.bounding_box().center(),
21 large_text,
22 centered,
23 )
24 .draw(&mut display)
25 .unwrap();
26
27 let output_settings = OutputSettingsBuilder::new().scale(2).build();
28 let output_image = display.to_grayscale_output_image(&output_settings);
29
30 println!(
31 "<img src=\"data:image/png;base64,{}\">",
32 output_image.to_base64_png().unwrap()
33 );
34}
Source§impl<C> SimulatorDisplay<C>
impl<C> SimulatorDisplay<C>
Sourcepub fn to_be_bytes(&self) -> Vec<u8> ⓘ
pub fn to_be_bytes(&self) -> Vec<u8> ⓘ
Converts the display content to big endian raw data.
Sourcepub fn to_le_bytes(&self) -> Vec<u8> ⓘ
pub fn to_le_bytes(&self) -> Vec<u8> ⓘ
Converts the display content to little endian raw data.
Sourcepub fn to_ne_bytes(&self) -> Vec<u8> ⓘ
pub fn to_ne_bytes(&self) -> Vec<u8> ⓘ
Converts the display content to native endian raw data.
Source§impl<C> SimulatorDisplay<C>
impl<C> SimulatorDisplay<C>
Sourcepub fn load_png<P: AsRef<Path>>(path: P) -> ImageResult<Self>
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>
impl<C: Clone> Clone for SimulatorDisplay<C>
Source§fn clone(&self) -> SimulatorDisplay<C>
fn clone(&self) -> SimulatorDisplay<C>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more