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>where
C: PixelColor + From<BinaryColor>,
impl<C> SimulatorDisplay<C>where C: PixelColor + From<BinaryColor>,
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?
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
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();
}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);
}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>,
impl<C> SimulatorDisplay<C>where C: PixelColor + Into<Rgb888>,
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?
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();
}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?
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]>,
impl<C> SimulatorDisplay<C>where C: PixelColor + ToBytes, <C as ToBytes>::Bytes: AsRef<[u8]>,
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>where
C: PixelColor + From<Rgb888>,
impl<C> SimulatorDisplay<C>where C: PixelColor + From<Rgb888>,
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 moresource§impl<C: Debug> Debug for SimulatorDisplay<C>
impl<C: Debug> Debug for SimulatorDisplay<C>
source§impl<C: PixelColor> DrawTarget for SimulatorDisplay<C>
impl<C: PixelColor> DrawTarget for SimulatorDisplay<C>
§type Error = Infallible
type Error = Infallible
source§fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>where
I: IntoIterator<Item = Pixel<Self::Color>>,
fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>where I: IntoIterator<Item = Pixel<Self::Color>>,
§fn fill_contiguous<I>(
&mut self,
area: &Rectangle,
colors: I
) -> Result<(), Self::Error>where
I: IntoIterator<Item = Self::Color>,
fn fill_contiguous<I>( &mut self, area: &Rectangle, colors: I ) -> Result<(), Self::Error>where I: IntoIterator<Item = Self::Color>,
§fn fill_solid(
&mut self,
area: &Rectangle,
color: Self::Color
) -> Result<(), Self::Error>
fn fill_solid( &mut self, area: &Rectangle, color: Self::Color ) -> Result<(), Self::Error>
source§impl<C: Hash> Hash for SimulatorDisplay<C>
impl<C: Hash> Hash for SimulatorDisplay<C>
source§impl<C: Ord> Ord for SimulatorDisplay<C>
impl<C: Ord> Ord for SimulatorDisplay<C>
source§fn cmp(&self, other: &SimulatorDisplay<C>) -> Ordering
fn cmp(&self, other: &SimulatorDisplay<C>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl<C> OriginDimensions for SimulatorDisplay<C>
impl<C> OriginDimensions for SimulatorDisplay<C>
source§impl<C: PartialEq> PartialEq<SimulatorDisplay<C>> for SimulatorDisplay<C>
impl<C: PartialEq> PartialEq<SimulatorDisplay<C>> for SimulatorDisplay<C>
source§fn eq(&self, other: &SimulatorDisplay<C>) -> bool
fn eq(&self, other: &SimulatorDisplay<C>) -> bool
self and other values to be equal, and is used
by ==.source§impl<C: PartialOrd> PartialOrd<SimulatorDisplay<C>> for SimulatorDisplay<C>
impl<C: PartialOrd> PartialOrd<SimulatorDisplay<C>> for SimulatorDisplay<C>
source§fn partial_cmp(&self, other: &SimulatorDisplay<C>) -> Option<Ordering>
fn partial_cmp(&self, other: &SimulatorDisplay<C>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more