-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eframe: several windows in series (#1919)
* Add example of opening several eframe windows in series * Reuse the same winit event loop * Ignore events to the wrong window * Run run_return again
- Loading branch information
Showing
6 changed files
with
124 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[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.61" | ||
publish = false | ||
|
||
|
||
[dependencies] | ||
eframe = { path = "../../eframe" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Demonstrates how to open several windows after each other. | ||
|
||
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release | ||
|
||
use eframe::egui; | ||
|
||
fn main() { | ||
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, | ||
..Default::default() | ||
}; | ||
|
||
eprintln!("Starting first window…"); | ||
eframe::run_native( | ||
"First Window", | ||
options.clone(), | ||
Box::new(|_cc| Box::new(MyApp::default())), | ||
); | ||
|
||
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::default())), | ||
); | ||
|
||
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::default())), | ||
); | ||
} | ||
|
||
#[derive(Default)] | ||
struct MyApp {} | ||
|
||
impl eframe::App for MyApp { | ||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { | ||
egui::CentralPanel::default().show(ctx, |ui| { | ||
if ui.button("Close").clicked() { | ||
eprintln!("Pressed Close button"); | ||
frame.quit(); | ||
} | ||
}); | ||
} | ||
} |