1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 21:00:03 -04:00
Files
egui/examples/serial_windows/src/main.rs
Emil Ernerfeldt 27559ef3fd Rename Panel methods (#8192)
The three methods for showing a `Panel` are now:

* `panel.show`: always show the panel.
* `panel.show_collapsible`: show or hide the panel, with a slide
animation in between.
* `Panel::show_switched`: animate between two different panels: a
thin/collapsed one and a thick/expanded one.
2026-05-24 12:22:32 +02:00

62 lines
1.8 KiB
Rust

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
#![expect(rustdoc::missing_crate_level_docs)] // it's an example
use eframe::egui;
fn main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
run_and_return: true,
viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
..Default::default()
};
log::info!("Starting first window…");
eframe::run_native(
"First Window",
options.clone(),
Box::new(|_cc| Ok(Box::new(MyApp { has_next: true }))),
)?;
std::thread::sleep(std::time::Duration::from_secs(2));
log::info!("Starting second window…");
eframe::run_native(
"Second Window",
options.clone(),
Box::new(|_cc| Ok(Box::new(MyApp { has_next: true }))),
)?;
std::thread::sleep(std::time::Duration::from_secs(2));
log::info!("Starting third window…");
eframe::run_native(
"Third Window",
options,
Box::new(|_cc| Ok(Box::new(MyApp { has_next: false }))),
)
}
struct MyApp {
pub(crate) has_next: bool,
}
impl eframe::App for MyApp {
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ui, |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() {
log::info!("Pressed Close button");
ui.send_viewport_cmd(egui::ViewportCommand::Close);
}
});
}
}