Struct Window

Source
pub struct Window { /* private fields */ }
Expand description

Simulator window

Implementations§

Source§

impl Window

Source

pub fn new(title: &str, output_settings: &OutputSettings) -> Self

Creates a new simulator window.

Examples found in repository?
examples/themes.rs (line 38)
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}
More examples
Hide additional examples
examples/input-handling.rs (line 44)
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

pub fn update<C>(&mut self, display: &SimulatorDisplay<C>)
where C: PixelColor + Into<Rgb888> + From<Rgb888>,

Updates the window.

Examples found in repository?
examples/input-handling.rs (line 52)
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

pub fn show_static<C>(&mut self, display: &SimulatorDisplay<C>)
where C: PixelColor + Into<Rgb888> + From<Rgb888>,

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)
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}
Source

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)
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}

Auto Trait Implementations§

§

impl Freeze for Window

§

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> 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> 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, 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.