Struct embedded_graphics_simulator::Window
source · pub struct Window { /* private fields */ }
Expand description
Simulator window
Implementations§
source§impl Window
impl Window
sourcepub fn new(title: &str, output_settings: &OutputSettings) -> Self
pub fn new(title: &str, output_settings: &OutputSettings) -> Self
Creates a new simulator window.
Examples found in repository?
examples/themes.rs (line 38)
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);
}
More examples
examples/input-handling.rs (line 44)
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(())
}
sourcepub fn update<C>(&mut self, display: &SimulatorDisplay<C>)
pub fn update<C>(&mut self, display: &SimulatorDisplay<C>)
Updates the window.
Examples found in repository?
examples/input-handling.rs (line 52)
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(())
}
sourcepub fn show_static<C>(&mut self, display: &SimulatorDisplay<C>)
pub fn show_static<C>(&mut self, display: &SimulatorDisplay<C>)
Shows a static display.
This methods updates the window once and loops until the simulator window is closed.
Examples found in repository?
examples/themes.rs (line 39)
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);
}
sourcepub fn events(&mut self) -> impl Iterator<Item = SimulatorEvent> + '_
pub fn events(&mut self) -> impl Iterator<Item = SimulatorEvent> + '_
Returns an iterator of all captured SimulatorEvents.
Panics
Panics if called before update
is called at least once.
Examples found in repository?
examples/input-handling.rs (line 54)
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(())
}
Auto Trait Implementations§
impl RefUnwindSafe for Window
impl !Send for Window
impl !Sync for Window
impl Unpin for Window
impl UnwindSafe for Window
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.