From 4922b1912b20f05727c7a76e2ac17dd019078ab2 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 20 Mar 2022 22:53:19 +0100 Subject: [PATCH] Move epi-code from egui_glow into eframe --- Cargo.lock | 2 +- eframe/Cargo.toml | 4 +- eframe/src/lib.rs | 43 ++--------------- .../epi_backend.rs => eframe/src/native.rs | 46 +++++++++++++++++-- egui_glow/Cargo.toml | 9 +--- egui_glow/src/lib.rs | 7 --- 6 files changed, 51 insertions(+), 60 deletions(-) rename egui_glow/src/epi_backend.rs => eframe/src/native.rs (79%) diff --git a/Cargo.lock b/Cargo.lock index 7c1e66bf..626250a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -986,6 +986,7 @@ dependencies = [ "ehttp", "epi", "glow", + "glutin", "image", "parking_lot 0.12.0", "poll-promise", @@ -1082,7 +1083,6 @@ dependencies = [ "bytemuck", "egui", "egui-winit", - "epi", "glow", "glutin", "memoffset", diff --git a/eframe/Cargo.toml b/eframe/Cargo.toml index a502ce46..a50e9399 100644 --- a/eframe/Cargo.toml +++ b/eframe/Cargo.toml @@ -46,16 +46,18 @@ screen_reader = [ [dependencies] egui = { version = "0.17.0", path = "../egui", default-features = false } epi = { version = "0.17.0", path = "../epi" } +glow = "0.11" +parking_lot = "0.12" # native: [target.'cfg(not(target_arch = "wasm32"))'.dependencies] egui_glow = { version = "0.17.0", path = "../egui_glow", default-features = false, features = [ "clipboard", - "epi", "links", "winit", ] } egui-winit = { version = "0.17.0", path = "../egui-winit", default-features = false } +glutin = "0.28.0" # web: [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/eframe/src/lib.rs b/eframe/src/lib.rs index 68b060b0..be17ba15 100644 --- a/eframe/src/lib.rs +++ b/eframe/src/lib.rs @@ -98,43 +98,8 @@ pub fn start_web(canvas_id: &str, app_creator: AppCreator) -> Result<(), wasm_bi // ---------------------------------------------------------------------------- // When compiling natively -/// This is how you start a native (desktop) app. -/// -/// The first argument is name of your app, used for the title bar of the native window -/// and the save location of persistence (see [`epi::App::save`]). -/// -/// Call from `fn main` like this: -/// ``` no_run -/// use eframe::egui; -/// -/// fn main() { -/// let native_options = eframe::NativeOptions::default(); -/// eframe::run_native("MyApp", native_options, Box::new(|cc| Box::new(MyEguiApp::new(cc)))); -/// } -/// -/// #[derive(Default)] -/// struct MyEguiApp {} -/// -/// impl MyEguiApp { -/// 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 -/// // for e.g. egui::PaintCallback. -/// Self::default() -/// } -/// } -/// -/// 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!"); -/// }); -/// } -/// } -/// ``` #[cfg(not(target_arch = "wasm32"))] -#[allow(clippy::needless_pass_by_value)] -pub fn run_native(app_name: &str, native_options: NativeOptions, app_creator: AppCreator) -> ! { - egui_glow::run(app_name, &native_options, app_creator) -} +mod native; + +#[cfg(not(target_arch = "wasm32"))] +pub use native::run_native; diff --git a/egui_glow/src/epi_backend.rs b/eframe/src/native.rs similarity index 79% rename from egui_glow/src/epi_backend.rs rename to eframe/src/native.rs index 72611673..ad0bf5b0 100644 --- a/egui_glow/src/epi_backend.rs +++ b/eframe/src/native.rs @@ -32,18 +32,56 @@ fn create_display( pub use epi::NativeOptions; -/// Run an egui app +/// This is how you start a native (desktop) app. +/// +/// The first argument is name of your app, used for the title bar of the native window +/// and the save location of persistence (see [`epi::App::save`]). +/// +/// Call from `fn main` like this: +/// ``` no_run +/// use eframe::egui; +/// +/// fn main() { +/// let native_options = eframe::NativeOptions::default(); +/// eframe::run_native("MyApp", native_options, |cc| Box::new(MyEguiApp::new(cc))); +/// } +/// +/// #[derive(Default)] +/// struct MyEguiApp {} +/// +/// impl MyEguiApp { +/// 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 +/// // for e.g. egui::PaintCallback. +/// Self::default() +/// } +/// } +/// +/// 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!"); +/// }); +/// } +/// } +/// ``` #[allow(unsafe_code)] -pub fn run(app_name: &str, native_options: &epi::NativeOptions, app_creator: epi::AppCreator) -> ! { +pub fn run_native( + app_name: &str, + native_options: epi::NativeOptions, + app_creator: epi::AppCreator, +) -> ! { let persistence = egui_winit::epi::Persistence::from_app_name(app_name); let window_settings = persistence.load_window_settings(); let window_builder = - egui_winit::epi::window_builder(native_options, &window_settings).with_title(app_name); + egui_winit::epi::window_builder(&native_options, &window_settings).with_title(app_name); let event_loop = winit::event_loop::EventLoop::with_user_event(); let (gl_window, gl) = create_display(window_builder, &event_loop); let gl = std::rc::Rc::new(gl); - let mut painter = crate::Painter::new(gl.clone(), None, "") + let mut painter = egui_glow::Painter::new(gl.clone(), None, "") .unwrap_or_else(|error| panic!("some OpenGL error occurred {}\n", error)); let mut integration = egui_winit::epi::EpiIntegration::new( diff --git a/egui_glow/Cargo.toml b/egui_glow/Cargo.toml index fbf52026..f9edcbb0 100644 --- a/egui_glow/Cargo.toml +++ b/egui_glow/Cargo.toml @@ -38,13 +38,7 @@ default_fonts = ["egui/default_fonts"] links = ["egui-winit/links"] # enable persisting native window options and egui memory -persistence = [ - "egui-winit/persistence", - "egui/persistence", - "epi", # also implied by the lines below, see https://github.com/rust-lang/cargo/issues/8832 - "epi/file_storage", - "epi/persistence", -] +persistence = ["egui-winit/persistence", "egui/persistence"] # experimental support for a screen reader screen_reader = ["egui-winit/screen_reader"] @@ -58,7 +52,6 @@ winit = ["egui-winit", "glutin"] egui = { version = "0.17.0", path = "../egui", default-features = false, features = [ "convert_bytemuck", ] } -epi = { version = "0.17.0", path = "../epi", optional = true } bytemuck = "1.7" glow = "0.11" diff --git a/egui_glow/src/lib.rs b/egui_glow/src/lib.rs index 227b6527..c11ff790 100644 --- a/egui_glow/src/lib.rs +++ b/egui_glow/src/lib.rs @@ -2,7 +2,6 @@ //! //! The main type you want to use is [`EguiGlow`]. //! -//! This library is an [`epi`] backend. //! If you are writing an app, you may want to look at [`eframe`](https://docs.rs/eframe) instead. // Forbid warnings in release builds: @@ -99,9 +98,3 @@ mod vao_emulate; pub mod winit; #[cfg(all(not(target_arch = "wasm32"), feature = "winit"))] pub use winit::*; - -#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))] -mod epi_backend; - -#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))] -pub use epi_backend::{run, NativeOptions};