Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Box the app creator #1373

Merged
merged 1 commit into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion eframe/examples/confirm_exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 5 additions & 3 deletions eframe/examples/custom_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions eframe/examples/custom_font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion eframe/examples/download_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
);
}

Expand Down
2 changes: 1 addition & 1 deletion eframe/examples/file_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
);
}

Expand Down
6 changes: 5 additions & 1 deletion eframe/examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions eframe/examples/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion eframe/examples/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions eframe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -54,7 +54,7 @@
//! #[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(MyApp::new(cc)))
//! eframe::start_web(canvas_id, Box::new(|cc| Box::new(MyApp::new(cc))))
//! }
//! ```

Expand Down Expand Up @@ -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")]
Expand All @@ -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)]
Expand Down
5 changes: 4 additions & 1 deletion egui_demo_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> {
// Redirect tracing to console.log and friends:
tracing_wasm::set_as_global_default();

eframe::start_web(canvas_id, |cc| Box::new(egui_demo_lib::WrapApp::new(cc)))
eframe::start_web(
canvas_id,
Box::new(|cc| Box::new(egui_demo_lib::WrapApp::new(cc))),
)
}
8 changes: 5 additions & 3 deletions egui_demo_app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
);
}
2 changes: 1 addition & 1 deletion epi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn App>;
pub type AppCreator = Box<dyn FnOnce(&CreationContext<'_>) -> Box<dyn App>>;

/// Data that is passed to [`AppCreator`] that can be used to setup and initialize your app.
pub struct CreationContext<'s> {
Expand Down