This commit is contained in:
nora 2023-04-18 15:38:14 +02:00
parent 12163d1338
commit 550b1644cb
363 changed files with 84081 additions and 16 deletions

View file

@ -0,0 +1,14 @@
[package]
name = "serial_windows"
version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
publish = false
[dependencies]
eframe = { path = "../../crates/eframe", features = [
"__screenshot", # __screenshot is so we can dump a screenshot using EFRAME_SCREENSHOT_TO
] }

View file

@ -0,0 +1,17 @@
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>.
```sh
cargo run -p serial_windows
```
![](screenshot.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

View file

@ -0,0 +1,61 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use eframe::egui;
fn main() -> Result<(), eframe::Error> {
if cfg!(target_os = "macos") {
eprintln!("WARNING: this example does not work on Mac! See https://github.com/emilk/egui/issues/1918");
}
let options = eframe::NativeOptions {
run_and_return: true,
initial_window_size: Some(egui::vec2(320.0, 240.0)),
..Default::default()
};
eprintln!("Starting first window…");
eframe::run_native(
"First Window",
options.clone(),
Box::new(|_cc| Box::new(MyApp { has_next: true })),
)?;
std::thread::sleep(std::time::Duration::from_secs(2));
eprintln!("Starting second window…");
eframe::run_native(
"Second Window",
options.clone(),
Box::new(|_cc| Box::new(MyApp { has_next: true })),
)?;
std::thread::sleep(std::time::Duration::from_secs(2));
eprintln!("Starting third window…");
eframe::run_native(
"Third Window",
options,
Box::new(|_cc| Box::new(MyApp { has_next: false })),
)
}
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();
}
});
}
}