mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Support returning errors when creating the app (#4565)
The closure passed to `eframe::run_native` now returns a `Result`, allowing you to return an error during app creation, which will be returned to the caller of `run_native`. This means you need to wrap your `Box::new(MyApp::new(…))` in an `Ok(…)`. * Closes https://github.com/emilk/egui/issues/4474
This commit is contained in:
@@ -12,7 +12,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"Confirm exit",
|
||||
options,
|
||||
Box::new(|_cc| Box::<MyApp>::default()),
|
||||
Box::new(|_cc| Ok(Box::<MyApp>::default())),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"Custom 3D painting in eframe using glow",
|
||||
options,
|
||||
Box::new(|cc| Box::new(MyApp::new(cc))),
|
||||
Box::new(|cc| Ok(Box::new(MyApp::new(cc)))),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"egui example: custom font",
|
||||
options,
|
||||
Box::new(|cc| Box::new(MyApp::new(cc))),
|
||||
Box::new(|cc| Ok(Box::new(MyApp::new(cc)))),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"egui example: global font style",
|
||||
options,
|
||||
Box::new(|cc| Box::new(MyApp::new(cc))),
|
||||
Box::new(|cc| Ok(Box::new(MyApp::new(cc)))),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
// This gives us image support:
|
||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||
|
||||
Box::<MyApp>::default()
|
||||
Ok(Box::<MyApp>::default())
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"Plot",
|
||||
options,
|
||||
Box::new(|_cc| Box::<PlotExample>::default()),
|
||||
Box::new(|_cc| Ok(Box::<PlotExample>::default())),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"Custom window frame", // unused title
|
||||
options,
|
||||
Box::new(|_cc| Box::<MyApp>::default()),
|
||||
Box::new(|_cc| Ok(Box::<MyApp>::default())),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"Native file dialogs and drag-and-drop files",
|
||||
options,
|
||||
Box::new(|_cc| Box::<MyApp>::default()),
|
||||
Box::new(|_cc| Ok(Box::<MyApp>::default())),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
// This gives us image support:
|
||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||
|
||||
Box::<MyApp>::default()
|
||||
Ok(Box::<MyApp>::default())
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"My parallel egui App",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(MyApp::new())),
|
||||
Box::new(|_cc| Ok(Box::new(MyApp::new()))),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
Box::new(|cc| {
|
||||
// This gives us image support:
|
||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||
Box::<MyApp>::default()
|
||||
Ok(Box::<MyApp>::default())
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"Keyboard events",
|
||||
options,
|
||||
Box::new(|_cc| Box::<Content>::default()),
|
||||
Box::new(|_cc| Ok(Box::<Content>::default())),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"Multiple viewports",
|
||||
options,
|
||||
Box::new(|_cc| Box::<MyApp>::default()),
|
||||
Box::new(|_cc| Ok(Box::<MyApp>::default())),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
|
||||
..Default::default()
|
||||
},
|
||||
Box::new(|_cc| Box::<MyApp>::default()),
|
||||
Box::new(|_cc| Ok(Box::<MyApp>::default())),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"My egui App with a plot",
|
||||
options,
|
||||
Box::new(|_cc| Box::<MyApp>::default()),
|
||||
Box::new(|_cc| Ok(Box::<MyApp>::default())),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"Take screenshots and display with eframe/egui",
|
||||
options,
|
||||
Box::new(|_cc| Box::<MyApp>::default()),
|
||||
Box::new(|_cc| Ok(Box::<MyApp>::default())),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"First Window",
|
||||
options.clone(),
|
||||
Box::new(|_cc| Box::new(MyApp { has_next: true })),
|
||||
Box::new(|_cc| Ok(Box::new(MyApp { has_next: true }))),
|
||||
)?;
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||
@@ -32,7 +32,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"Second Window",
|
||||
options.clone(),
|
||||
Box::new(|_cc| Box::new(MyApp { has_next: true })),
|
||||
Box::new(|_cc| Ok(Box::new(MyApp { has_next: true }))),
|
||||
)?;
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||
@@ -41,7 +41,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"Third Window",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(MyApp { has_next: false })),
|
||||
Box::new(|_cc| Ok(Box::new(MyApp { has_next: false }))),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ fn main() -> eframe::Result<()> {
|
||||
eframe::run_native(
|
||||
"User attention test",
|
||||
native_options,
|
||||
Box::new(|cc| Box::new(Application::new(cc))),
|
||||
Box::new(|cc| Ok(Box::new(Application::new(cc)))),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user