diff --git a/examples/serial_windows/README.md b/examples/serial_windows/README.md index 278023cd..7543f95c 100644 --- a/examples/serial_windows/README.md +++ b/examples/serial_windows/README.md @@ -1,5 +1,12 @@ Demonstrates how to open several windows after each other. +Expected order of execution: + +- When the example runs a first window will be shown. +- Once the first window is closed after a delay a second window will be shown. +- Similarly, when the second window is closed after a delay a third will be shown. +- Once the third is closed the program will stop. + NOTE: this doesn't work on Mac due to . See also . diff --git a/examples/serial_windows/screenshot.png b/examples/serial_windows/screenshot.png index bf9c4360..1f7732c0 100644 Binary files a/examples/serial_windows/screenshot.png and b/examples/serial_windows/screenshot.png differ diff --git a/examples/serial_windows/src/main.rs b/examples/serial_windows/src/main.rs index b7dc7944..e4565517 100644 --- a/examples/serial_windows/src/main.rs +++ b/examples/serial_windows/src/main.rs @@ -17,7 +17,7 @@ fn main() -> Result<(), eframe::Error> { eframe::run_native( "First Window", options.clone(), - Box::new(|_cc| Box::new(MyApp::default())), + Box::new(|_cc| Box::new(MyApp { has_next: true })), )?; std::thread::sleep(std::time::Duration::from_secs(2)); @@ -26,7 +26,7 @@ fn main() -> Result<(), eframe::Error> { eframe::run_native( "Second Window", options.clone(), - Box::new(|_cc| Box::new(MyApp::default())), + Box::new(|_cc| Box::new(MyApp { has_next: true })), )?; std::thread::sleep(std::time::Duration::from_secs(2)); @@ -35,16 +35,23 @@ fn main() -> Result<(), eframe::Error> { eframe::run_native( "Third Window", options, - Box::new(|_cc| Box::new(MyApp::default())), + Box::new(|_cc| Box::new(MyApp { has_next: false })), ) } -#[derive(Default)] -struct MyApp {} +struct MyApp { + pub(crate) has_next: bool, +} impl eframe::App for MyApp { fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { egui::CentralPanel::default().show(ctx, |ui| { + let label_text = if self.has_next { + "When this window is closed the next will be opened after a short delay" + } else { + "This is the last window. Program will end when closed" + }; + ui.label(label_text); if ui.button("Close").clicked() { eprintln!("Pressed Close button"); frame.close();