From 3d4dd7a0043b78d68dd0512a970bc54d65047590 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 18 Mar 2022 13:33:09 +0100 Subject: [PATCH] Box the app creator --- eframe/examples/confirm_exit.rs | 6 +++++- eframe/examples/custom_3d.rs | 8 +++++--- eframe/examples/custom_font.rs | 8 +++++--- eframe/examples/download_image.rs | 2 +- eframe/examples/file_dialog.rs | 2 +- eframe/examples/hello_world.rs | 6 +++++- eframe/examples/image.rs | 8 +++++--- eframe/examples/svg.rs | 6 +++++- eframe/src/lib.rs | 6 +++--- egui_demo_app/src/main.rs | 8 +++++--- epi/src/lib.rs | 2 +- 11 files changed, 41 insertions(+), 21 deletions(-) diff --git a/eframe/examples/confirm_exit.rs b/eframe/examples/confirm_exit.rs index 1e9035fa4fa5..8bc9bea3b418 100644 --- a/eframe/examples/confirm_exit.rs +++ b/eframe/examples/confirm_exit.rs @@ -4,7 +4,11 @@ use eframe::egui; fn main() { let options = eframe::NativeOptions::default(); - eframe::run_native("Confirm exit", options, |_cc| Box::new(MyApp::default())); + eframe::run_native( + "Confirm exit", + options, + Box::new(|_cc| Box::new(MyApp::default())), + ); } #[derive(Default)] diff --git a/eframe/examples/custom_3d.rs b/eframe/examples/custom_3d.rs index 8b14f130dc3d..54f9bf8edba6 100644 --- a/eframe/examples/custom_3d.rs +++ b/eframe/examples/custom_3d.rs @@ -15,9 +15,11 @@ use std::sync::Arc; fn main() { let options = eframe::NativeOptions::default(); - eframe::run_native("Custom 3D painting in eframe", options, |cc| { - Box::new(MyApp::new(cc)) - }); + eframe::run_native( + "Custom 3D painting in eframe", + options, + Box::new(|cc| Box::new(MyApp::new(cc))), + ); } struct MyApp { diff --git a/eframe/examples/custom_font.rs b/eframe/examples/custom_font.rs index dc74fe0d0b47..b1408b008fdf 100644 --- a/eframe/examples/custom_font.rs +++ b/eframe/examples/custom_font.rs @@ -4,9 +4,11 @@ use eframe::egui; fn main() { let options = eframe::NativeOptions::default(); - eframe::run_native("egui example: custom font", options, |cc| { - Box::new(MyApp::new(cc)) - }); + eframe::run_native( + "egui example: custom font", + options, + Box::new(|cc| Box::new(MyApp::new(cc))), + ); } fn setup_custom_fonts(ctx: &egui::Context) { diff --git a/eframe/examples/download_image.rs b/eframe/examples/download_image.rs index f79587624346..9cbb51d11705 100644 --- a/eframe/examples/download_image.rs +++ b/eframe/examples/download_image.rs @@ -9,7 +9,7 @@ fn main() { eframe::run_native( "Download and show an image with eframe/egui", options, - |_cc| Box::new(MyApp::default()), + Box::new(|_cc| Box::new(MyApp::default())), ); } diff --git a/eframe/examples/file_dialog.rs b/eframe/examples/file_dialog.rs index 66d0f3fc62f9..1cec45a4eae7 100644 --- a/eframe/examples/file_dialog.rs +++ b/eframe/examples/file_dialog.rs @@ -10,7 +10,7 @@ fn main() { eframe::run_native( "Native file dialogs and drag-and-drop files", options, - |_cc| Box::new(MyApp::default()), + Box::new(|_cc| Box::new(MyApp::default())), ); } diff --git a/eframe/examples/hello_world.rs b/eframe/examples/hello_world.rs index d5a9576f09ba..93156c7359d8 100644 --- a/eframe/examples/hello_world.rs +++ b/eframe/examples/hello_world.rs @@ -4,7 +4,11 @@ use eframe::egui; fn main() { let options = eframe::NativeOptions::default(); - eframe::run_native("My egui App", options, |_cc| Box::new(MyApp::default())); + eframe::run_native( + "My egui App", + options, + Box::new(|_cc| Box::new(MyApp::default())), + ); } struct MyApp { diff --git a/eframe/examples/image.rs b/eframe/examples/image.rs index c91622f39646..5b890220c598 100644 --- a/eframe/examples/image.rs +++ b/eframe/examples/image.rs @@ -5,9 +5,11 @@ use egui_extras::RetainedImage; fn main() { let options = eframe::NativeOptions::default(); - eframe::run_native("Show an image with eframe/egui", options, |_cc| { - Box::new(MyApp::default()) - }); + eframe::run_native( + "Show an image with eframe/egui", + options, + Box::new(|_cc| Box::new(MyApp::default())), + ); } struct MyApp { diff --git a/eframe/examples/svg.rs b/eframe/examples/svg.rs index a4e71bf74b3b..fd3f32f7e617 100644 --- a/eframe/examples/svg.rs +++ b/eframe/examples/svg.rs @@ -11,7 +11,11 @@ fn main() { initial_window_size: Some(egui::vec2(1000.0, 700.0)), ..Default::default() }; - eframe::run_native("svg example", options, |_cc| Box::new(MyApp::default())); + eframe::run_native( + "svg example", + options, + Box::new(|_cc| Box::new(MyApp::default())), + ); } struct MyApp { diff --git a/eframe/src/lib.rs b/eframe/src/lib.rs index ffa4f568ee20..3fa040ec91b6 100644 --- a/eframe/src/lib.rs +++ b/eframe/src/lib.rs @@ -20,7 +20,7 @@ //! //! fn main() { //! let native_options = eframe::NativeOptions::default(); -//! eframe::run_native("My egui App", native_options, |cc| Box::new(MyEguiApp::new(cc))); +//! eframe::run_native("My egui App", native_options, Box::new(|cc| Box::new(MyEguiApp::new(cc)))); //! } //! //! #[derive(Default)] @@ -99,7 +99,7 @@ pub use egui_web::wasm_bindgen; /// #[cfg(target_arch = "wasm32")] /// #[wasm_bindgen] /// pub fn start(canvas_id: &str) -> Result<(), eframe::wasm_bindgen::JsValue> { -/// eframe::start_web(canvas_id, |cc| Box::new(MyEguiApp::new(cc))) +/// eframe::start_web(canvas_id, Box::new(|cc| Box::new(MyEguiApp::new(cc)))) /// } /// ``` #[cfg(target_arch = "wasm32")] @@ -122,7 +122,7 @@ pub fn start_web(canvas_id: &str, app_creator: AppCreator) -> Result<(), wasm_bi /// /// fn main() { /// let native_options = eframe::NativeOptions::default(); -/// eframe::run_native("MyApp", native_options, |cc| Box::new(MyEguiApp::new(cc))); +/// eframe::run_native("MyApp", native_options, Box::new(|cc| Box::new(MyEguiApp::new(cc)))); /// } /// /// #[derive(Default)] diff --git a/egui_demo_app/src/main.rs b/egui_demo_app/src/main.rs index 30425599b38f..43d7010327d1 100644 --- a/egui_demo_app/src/main.rs +++ b/egui_demo_app/src/main.rs @@ -16,7 +16,9 @@ fn main() { drag_and_drop_support: true, ..Default::default() }; - eframe::run_native("egui demo app", options, |cc| { - Box::new(egui_demo_lib::WrapApp::new(cc)) - }); + eframe::run_native( + "egui demo app", + options, + Box::new(|cc| Box::new(egui_demo_lib::WrapApp::new(cc))), + ); } diff --git a/epi/src/lib.rs b/epi/src/lib.rs index ddc1add07623..005b132ca2a7 100644 --- a/epi/src/lib.rs +++ b/epi/src/lib.rs @@ -101,7 +101,7 @@ use std::sync::{Arc, Mutex}; /// The is is how your app is created. /// /// You can use the [`CreationContext`] to setup egui, restore state, setup OpenGL things, etc. -pub type AppCreator = fn(&CreationContext<'_>) -> Box; +pub type AppCreator = Box) -> Box>; /// Data that is passed to [`AppCreator`] that can be used to setup and initialize your app. pub struct CreationContext<'s> {