From bebca372ba23b899cdceaaa2eeacb78fed7a8048 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 14 Mar 2022 17:27:12 +0100 Subject: [PATCH] eframe: re-export epi::* so users don't need to care about what epi is --- eframe/examples/confirm_exit.rs | 6 +++--- eframe/examples/custom_3d.rs | 8 ++++---- eframe/examples/custom_font.rs | 8 ++++---- eframe/examples/download_image.rs | 6 +++--- eframe/examples/file_dialog.rs | 6 +++--- eframe/examples/hello_world.rs | 6 +++--- eframe/examples/image.rs | 6 +++--- eframe/examples/svg.rs | 6 +++--- eframe/src/lib.rs | 32 +++++++++++++------------------ 9 files changed, 39 insertions(+), 45 deletions(-) diff --git a/eframe/examples/confirm_exit.rs b/eframe/examples/confirm_exit.rs index 4a8049ceb46..1e9035fa4fa 100644 --- a/eframe/examples/confirm_exit.rs +++ b/eframe/examples/confirm_exit.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::{egui, epi}; +use eframe::egui; fn main() { let options = eframe::NativeOptions::default(); @@ -13,13 +13,13 @@ struct MyApp { is_exiting: bool, } -impl epi::App for MyApp { +impl eframe::App for MyApp { fn on_exit_event(&mut self) -> bool { self.is_exiting = true; self.can_exit } - fn update(&mut self, ctx: &egui::Context, frame: &epi::Frame) { + fn update(&mut self, ctx: &egui::Context, frame: &eframe::Frame) { egui::CentralPanel::default().show(ctx, |ui| { ui.heading("Try to close the window"); }); diff --git a/eframe/examples/custom_3d.rs b/eframe/examples/custom_3d.rs index 35efc852c3a..8b14f130dc3 100644 --- a/eframe/examples/custom_3d.rs +++ b/eframe/examples/custom_3d.rs @@ -8,7 +8,7 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::{egui, epi}; +use eframe::egui; use parking_lot::Mutex; use std::sync::Arc; @@ -27,7 +27,7 @@ struct MyApp { } impl MyApp { - fn new(cc: &epi::CreationContext<'_>) -> Self { + fn new(cc: &eframe::CreationContext<'_>) -> Self { Self { rotating_triangle: Arc::new(Mutex::new(RotatingTriangle::new(&cc.gl))), angle: 0.0, @@ -35,8 +35,8 @@ impl MyApp { } } -impl epi::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) { +impl eframe::App for MyApp { + fn update(&mut self, ctx: &egui::Context, _frame: &eframe::Frame) { egui::CentralPanel::default().show(ctx, |ui| { ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 0.0; diff --git a/eframe/examples/custom_font.rs b/eframe/examples/custom_font.rs index df0adb939b7..dc74fe0d0b4 100644 --- a/eframe/examples/custom_font.rs +++ b/eframe/examples/custom_font.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::{egui, epi}; +use eframe::egui; fn main() { let options = eframe::NativeOptions::default(); @@ -43,7 +43,7 @@ struct MyApp { } impl MyApp { - fn new(cc: &epi::CreationContext<'_>) -> Self { + fn new(cc: &eframe::CreationContext<'_>) -> Self { setup_custom_fonts(&cc.egui_ctx); Self { text: "Edit this text field if you want".to_owned(), @@ -51,8 +51,8 @@ impl MyApp { } } -impl epi::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) { +impl eframe::App for MyApp { + fn update(&mut self, ctx: &egui::Context, _frame: &eframe::Frame) { egui::CentralPanel::default().show(ctx, |ui| { ui.heading("egui using custom fonts"); ui.text_edit_multiline(&mut self.text); diff --git a/eframe/examples/download_image.rs b/eframe/examples/download_image.rs index 707a921a98d..92dd98f72e0 100644 --- a/eframe/examples/download_image.rs +++ b/eframe/examples/download_image.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::{egui, epi}; +use eframe::egui; use egui_extras::RetainedImage; use poll_promise::Promise; @@ -19,8 +19,8 @@ struct MyApp { promise: Option>>, } -impl epi::App for MyApp { - fn update(&mut self, ctx: &egui::Context, frame: &epi::Frame) { +impl eframe::App for MyApp { + fn update(&mut self, ctx: &egui::Context, frame: &eframe::Frame) { let promise = self.promise.get_or_insert_with(|| { // Begin download. // We download the image using `ehttp`, a library that works both in WASM and on native. diff --git a/eframe/examples/file_dialog.rs b/eframe/examples/file_dialog.rs index 4a62d1169a2..66d0f3fc62f 100644 --- a/eframe/examples/file_dialog.rs +++ b/eframe/examples/file_dialog.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::{egui, epi}; +use eframe::egui; fn main() { let options = eframe::NativeOptions { @@ -20,8 +20,8 @@ struct MyApp { picked_path: Option, } -impl epi::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) { +impl eframe::App for MyApp { + fn update(&mut self, ctx: &egui::Context, _frame: &eframe::Frame) { egui::CentralPanel::default().show(ctx, |ui| { ui.label("Drag-and-drop files onto the window!"); diff --git a/eframe/examples/hello_world.rs b/eframe/examples/hello_world.rs index 8989016193a..d5a9576f09b 100644 --- a/eframe/examples/hello_world.rs +++ b/eframe/examples/hello_world.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::{egui, epi}; +use eframe::egui; fn main() { let options = eframe::NativeOptions::default(); @@ -21,8 +21,8 @@ impl Default for MyApp { } } -impl epi::App for MyApp { - fn update(&mut self, ctx: &egui::Context, frame: &epi::Frame) { +impl eframe::App for MyApp { + fn update(&mut self, ctx: &egui::Context, frame: &eframe::Frame) { egui::CentralPanel::default().show(ctx, |ui| { ui.heading("My egui Application"); ui.horizontal(|ui| { diff --git a/eframe/examples/image.rs b/eframe/examples/image.rs index 03b11568e24..c91622f3964 100644 --- a/eframe/examples/image.rs +++ b/eframe/examples/image.rs @@ -1,6 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::{egui, epi}; +use eframe::egui; use egui_extras::RetainedImage; fn main() { @@ -26,8 +26,8 @@ impl Default for MyApp { } } -impl epi::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) { +impl eframe::App for MyApp { + fn update(&mut self, ctx: &egui::Context, _frame: &eframe::Frame) { egui::CentralPanel::default().show(ctx, |ui| { ui.heading("This is an image:"); self.image.show(ui); diff --git a/eframe/examples/svg.rs b/eframe/examples/svg.rs index 3dd0c8ba775..a4e71bf74b3 100644 --- a/eframe/examples/svg.rs +++ b/eframe/examples/svg.rs @@ -4,7 +4,7 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use eframe::{egui, epi}; +use eframe::egui; fn main() { let options = eframe::NativeOptions { @@ -30,8 +30,8 @@ impl Default for MyApp { } } -impl epi::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) { +impl eframe::App for MyApp { + fn update(&mut self, ctx: &egui::Context, _frame: &eframe::Frame) { egui::CentralPanel::default().show(ctx, |ui| { ui.heading("SVG example"); ui.label("The SVG is rasterized and displayed as a texture."); diff --git a/eframe/src/lib.rs b/eframe/src/lib.rs index cd641e62020..ffa4f568ee2 100644 --- a/eframe/src/lib.rs +++ b/eframe/src/lib.rs @@ -16,7 +16,7 @@ //! //! ## Usage, native: //! ``` no_run -//! use eframe::{epi, egui}; +//! use eframe::egui; //! //! fn main() { //! let native_options = eframe::NativeOptions::default(); @@ -27,7 +27,7 @@ //! struct MyEguiApp {} //! //! impl MyEguiApp { -//! fn new(cc: &epi::CreationContext<'_>) -> Self { +//! fn new(cc: &eframe::CreationContext<'_>) -> Self { //! // Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_visuals. //! // Restore app state using cc.storage (requires the "persistence" feature). //! // Use the cc.gl (a glow::Context) to create graphics shaders and buffers that you can use @@ -36,8 +36,8 @@ //! } //! } //! -//! impl epi::App for MyEguiApp { -//! fn update(&mut self, ctx: &egui::Context, frame: &epi::Frame) { +//! impl eframe::App for MyEguiApp { +//! fn update(&mut self, ctx: &egui::Context, frame: &eframe::Frame) { //! egui::CentralPanel::default().show(ctx, |ui| { //! ui.heading("Hello World!"); //! }); @@ -69,10 +69,11 @@ )] #![allow(clippy::needless_doctest_main)] +// Re-export all useful libraries: pub use {egui, egui::emath, egui::epaint, epi}; -#[cfg(not(target_arch = "wasm32"))] -pub use epi::NativeOptions; +// Re-export everything in `epi` so `eframe` users don't have to care about what `epi` is: +pub use epi::*; // ---------------------------------------------------------------------------- // When compiling for web @@ -102,10 +103,7 @@ pub use egui_web::wasm_bindgen; /// } /// ``` #[cfg(target_arch = "wasm32")] -pub fn start_web( - canvas_id: &str, - app_creator: epi::AppCreator, -) -> Result<(), wasm_bindgen::JsValue> { +pub fn start_web(canvas_id: &str, app_creator: AppCreator) -> Result<(), wasm_bindgen::JsValue> { egui_web::start(canvas_id, app_creator)?; Ok(()) } @@ -120,7 +118,7 @@ pub fn start_web( /// /// Call from `fn main` like this: /// ``` no_run -/// use eframe::{epi, egui}; +/// use eframe::egui; /// /// fn main() { /// let native_options = eframe::NativeOptions::default(); @@ -131,7 +129,7 @@ pub fn start_web( /// struct MyEguiApp {} /// /// impl MyEguiApp { -/// fn new(cc: &epi::CreationContext<'_>) -> Self { +/// fn new(cc: &eframe::CreationContext<'_>) -> Self { /// // Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_visuals. /// // Restore app state using cc.storage (requires the "persistence" feature). /// // Use the cc.gl (a glow::Context) to create graphics shaders and buffers that you can use @@ -140,8 +138,8 @@ pub fn start_web( /// } /// } /// -/// impl epi::App for MyEguiApp { -/// fn update(&mut self, ctx: &egui::Context, frame: &epi::Frame) { +/// impl eframe::App for MyEguiApp { +/// fn update(&mut self, ctx: &egui::Context, frame: &eframe::Frame) { /// egui::CentralPanel::default().show(ctx, |ui| { /// ui.heading("Hello World!"); /// }); @@ -149,10 +147,6 @@ pub fn start_web( /// } /// ``` #[cfg(not(target_arch = "wasm32"))] -pub fn run_native( - app_name: &str, - native_options: epi::NativeOptions, - app_creator: epi::AppCreator, -) -> ! { +pub fn run_native(app_name: &str, native_options: NativeOptions, app_creator: AppCreator) -> ! { egui_glow::run(app_name, &native_options, app_creator) }