Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update serial window example #2756

Merged
merged 4 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/serial_windows/README.md
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/rust-windowing/winit/issues/2431>.
See also <https://github.com/emilk/egui/issues/1918>.

Expand Down
Binary file modified examples/serial_windows/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 12 additions & 5 deletions examples/serial_windows/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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();
Expand Down