mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
eframe error handling (#2433)
* eframe::run_native: return errors instead of crashing * Detect and handle glutin errors * egui_demo_app: silence wgpu log spam * Add trace logs for why eframe is shutting down * Fix: only save App state once on Mac * Handle Winit failure * Log where we load app state from * Don't panic on zero-sized window * Clamp loaded window size to not be too tiny to see * Simplify code: more shared code in window_builder * Improve code readability * Fix wasm32 build * fix android * Update changelog
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
use eframe::egui;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
let options = eframe::NativeOptions {
|
||||
initial_window_size: Some(egui::vec2(320.0, 240.0)),
|
||||
..Default::default()
|
||||
@@ -11,7 +11,7 @@ fn main() {
|
||||
"Confirm exit",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(MyApp::default())),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
||||
@@ -6,7 +6,7 @@ use eframe::egui;
|
||||
use egui::mutex::Mutex;
|
||||
use std::sync::Arc;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
let options = eframe::NativeOptions {
|
||||
initial_window_size: Some(egui::vec2(350.0, 380.0)),
|
||||
multisampling: 8,
|
||||
@@ -17,7 +17,7 @@ fn main() {
|
||||
"Custom 3D painting in eframe using glow",
|
||||
options,
|
||||
Box::new(|cc| Box::new(MyApp::new(cc))),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
struct MyApp {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use eframe::egui;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
let options = eframe::NativeOptions {
|
||||
initial_window_size: Some(egui::vec2(550.0, 610.0)),
|
||||
multisampling: 8,
|
||||
@@ -16,7 +16,7 @@ fn main() {
|
||||
"Custom 3D painting in eframe!",
|
||||
options,
|
||||
Box::new(|cc| Box::new(MyApp::new(cc))),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
pub struct MyApp {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use eframe::egui;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
let options = eframe::NativeOptions {
|
||||
initial_window_size: Some(egui::vec2(320.0, 240.0)),
|
||||
..Default::default()
|
||||
@@ -11,7 +11,7 @@ fn main() {
|
||||
"egui example: custom font",
|
||||
options,
|
||||
Box::new(|cc| Box::new(MyApp::new(cc))),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
fn setup_custom_fonts(ctx: &egui::Context) {
|
||||
|
||||
@@ -58,14 +58,14 @@ impl eframe::App for MyApp {
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
let options = eframe::NativeOptions::default();
|
||||
|
||||
eframe::run_native(
|
||||
"egui example: global font style",
|
||||
options,
|
||||
Box::new(|cc| Box::new(MyApp::new(cc))),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
pub const LOREM_IPSUM: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
use eframe::egui;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
let options = eframe::NativeOptions {
|
||||
// Hide the OS-specific "chrome" around the window:
|
||||
decorated: false,
|
||||
@@ -18,7 +18,7 @@ fn main() {
|
||||
"Custom window frame", // unused title
|
||||
options,
|
||||
Box::new(|_cc| Box::new(MyApp::default())),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
||||
@@ -4,13 +4,13 @@ use eframe::egui;
|
||||
use egui_extras::RetainedImage;
|
||||
use poll_promise::Promise;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
let options = eframe::NativeOptions::default();
|
||||
eframe::run_native(
|
||||
"Download and show an image with eframe/egui",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(MyApp::default())),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use eframe::egui;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
let options = eframe::NativeOptions {
|
||||
drag_and_drop_support: true,
|
||||
initial_window_size: Some(egui::vec2(320.0, 240.0)),
|
||||
@@ -12,7 +12,7 @@ fn main() {
|
||||
"Native file dialogs and drag-and-drop files",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(MyApp::default())),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use eframe::egui;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
// Log to stdout (if you run with `RUST_LOG=debug`).
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
@@ -14,7 +14,7 @@ fn main() {
|
||||
"My egui App",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(MyApp::default())),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
struct MyApp {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use eframe::egui;
|
||||
use egui::*;
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
// Log to stdout (if you run with `RUST_LOG=debug`).
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
@@ -11,7 +11,7 @@ fn main() {
|
||||
"Keyboard events",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(Content::default())),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use eframe::egui;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
start_puffin_server(); // NOTE: you may only want to call this if the users specifies some flag or clicks a button!
|
||||
|
||||
let options = eframe::NativeOptions::default();
|
||||
@@ -10,7 +10,7 @@ fn main() {
|
||||
"My egui App",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(MyApp::default())),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use eframe::egui;
|
||||
use egui_extras::RetainedImage;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
let options = eframe::NativeOptions {
|
||||
initial_window_size: Some(egui::vec2(300.0, 900.0)),
|
||||
..Default::default()
|
||||
@@ -13,7 +13,7 @@ fn main() {
|
||||
"Show an image with eframe/egui",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(MyApp::default())),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
struct MyApp {
|
||||
|
||||
@@ -6,13 +6,13 @@ use eframe::{
|
||||
};
|
||||
use itertools::Itertools as _;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
let options = eframe::NativeOptions::default();
|
||||
eframe::run_native(
|
||||
"Take screenshots and display with eframe/egui",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(MyApp::default())),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use eframe::egui;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
if cfg!(target_os = "macos") {
|
||||
eprintln!("WARNING: this example does not work on Mac! See https://github.com/emilk/egui/issues/1918");
|
||||
}
|
||||
@@ -18,7 +18,7 @@ fn main() {
|
||||
"First Window",
|
||||
options.clone(),
|
||||
Box::new(|_cc| Box::new(MyApp::default())),
|
||||
);
|
||||
)?;
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||
|
||||
@@ -27,7 +27,7 @@ fn main() {
|
||||
"Second Window",
|
||||
options.clone(),
|
||||
Box::new(|_cc| Box::new(MyApp::default())),
|
||||
);
|
||||
)?;
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||
|
||||
@@ -36,7 +36,7 @@ fn main() {
|
||||
"Third Window",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(MyApp::default())),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
use eframe::egui;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), eframe::EframeError> {
|
||||
let options = eframe::NativeOptions {
|
||||
initial_window_size: Some(egui::vec2(1000.0, 700.0)),
|
||||
..Default::default()
|
||||
@@ -15,7 +15,7 @@ fn main() {
|
||||
"svg example",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(MyApp::default())),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
struct MyApp {
|
||||
|
||||
Reference in New Issue
Block a user