From d7459bc13d409afe70d560ff8c6b6c135198d04a Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 29 Dec 2020 14:15:46 +0100 Subject: [PATCH] Move `egui::app` into new `epi` crate --- Cargo.lock | 15 ++++++- Cargo.toml | 1 + TODO.md | 2 +- egui/Cargo.toml | 1 - egui/src/lib.rs | 1 - egui_demo/Cargo.toml | 3 +- egui_demo_lib/Cargo.toml | 1 + egui_demo_lib/src/app.rs | 18 ++++---- egui_demo_lib/src/color_test.rs | 8 ++-- egui_demo_lib/src/demo_windows.rs | 6 +-- egui_glium/Cargo.toml | 3 +- egui_glium/src/backend.rs | 31 ++++++------- egui_glium/src/storage.rs | 2 +- egui_web/Cargo.toml | 1 + egui_web/src/backend.rs | 23 +++++----- egui_web/src/lib.rs | 2 +- epi/Cargo.toml | 20 +++++++++ epi/README.md | 7 +++ egui/src/app.rs => epi/src/lib.rs | 75 +++++++++++++++++++++++++------ example_web/Cargo.toml | 1 + example_web/src/example_app.rs | 8 ++-- 21 files changed, 157 insertions(+), 72 deletions(-) create mode 100644 epi/Cargo.toml create mode 100644 epi/README.md rename egui/src/app.rs => epi/src/lib.rs (69%) diff --git a/Cargo.lock b/Cargo.lock index 0b89f630..d9e23665 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -629,7 +629,6 @@ dependencies = [ "parking_lot", "rusttype", "serde", - "serde_json", ] [[package]] @@ -640,6 +639,7 @@ dependencies = [ "egui_demo_lib", "egui_glium", "egui_web", + "epi", "js-sys", "serde", "wasm-bindgen", @@ -651,6 +651,7 @@ version = "0.6.0" dependencies = [ "criterion", "egui", + "epi", ] [[package]] @@ -661,6 +662,7 @@ dependencies = [ "clipboard", "directories-next", "egui", + "epi", "glium", "serde", "serde_json", @@ -672,6 +674,7 @@ name = "egui_web" version = "0.6.0" dependencies = [ "egui", + "epi", "js-sys", "serde", "serde_json", @@ -686,12 +689,22 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "epi" +version = "0.6.0" +dependencies = [ + "egui", + "serde", + "serde_json", +] + [[package]] name = "example_web" version = "0.1.0" dependencies = [ "egui", "egui_web", + "epi", "image", "js-sys", "serde", diff --git a/Cargo.toml b/Cargo.toml index 5e1d2cd9..381775ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ members = [ "egui_glium", "egui_web", "egui", + "epi", "example_web", ] diff --git a/TODO.md b/TODO.md index 4de6c8a1..6724780a 100644 --- a/TODO.md +++ b/TODO.md @@ -151,4 +151,4 @@ Ability to do a search for any widget. The search works even for collapsed regio * [x] Use HW clip rects * [x] Image support * [x] Show user textures - * [x] API for creating a texture managed by `egui::app::Backend` + * [x] API for creating a texture managed by `epi` backend diff --git a/egui/Cargo.toml b/egui/Cargo.toml index c6ec14a7..7cfc65d8 100644 --- a/egui/Cargo.toml +++ b/egui/Cargo.toml @@ -24,7 +24,6 @@ atomic_refcell = { version = "0.1", optional = true } # Used instead of parking_ parking_lot = { version = "0.11", optional = true } # Using parking_lot over std::sync::Mutex gives 50% speedups in some real-world scenarios rusttype = "0.9" serde = { version = "1", features = ["derive"], optional = true } -serde_json = { version = "1", optional = true } [features] default = ["atomic_refcell", "default_fonts"] diff --git a/egui/src/lib.rs b/egui/src/lib.rs index 568e1fec..1970f07e 100644 --- a/egui/src/lib.rs +++ b/egui/src/lib.rs @@ -79,7 +79,6 @@ pub mod align; mod animation_manager; -pub mod app; pub mod containers; mod context; mod id; diff --git a/egui_demo/Cargo.toml b/egui_demo/Cargo.toml index 24ced141..eeadf9af 100644 --- a/egui_demo/Cargo.toml +++ b/egui_demo/Cargo.toml @@ -9,8 +9,9 @@ edition = "2018" crate-type = ["cdylib", "rlib"] [dependencies] -egui = { path = "../egui", features = ["serde", "serde_json"] } +egui = { version = "0.6.0", path = "../egui", features = ["serde"] } egui_demo_lib = { path = "../egui_demo_lib" } +epi = { version = "0.6.0", path = "../epi", features = ["serde", "serde_json"] } serde = { version = "1", features = ["derive"] } # For compiling natively: diff --git a/egui_demo_lib/Cargo.toml b/egui_demo_lib/Cargo.toml index 2ead51b2..22217ee3 100644 --- a/egui_demo_lib/Cargo.toml +++ b/egui_demo_lib/Cargo.toml @@ -16,6 +16,7 @@ include = [ "**/*.rs", "Cargo.toml"] [dependencies] egui = { version = "0.6.0", path = "../egui" } +epi = { version = "0.6.0", path = "../epi" } [dev-dependencies] criterion = { version = "0.3", default-features = false } diff --git a/egui_demo_lib/src/app.rs b/egui_demo_lib/src/app.rs index 0baf03c3..abe79996 100644 --- a/egui_demo_lib/src/app.rs +++ b/egui_demo_lib/src/app.rs @@ -171,7 +171,7 @@ impl FrameHistory { /// Demonstrates how to make an app using Egui. /// -/// Implements `egui::app::App` so it can be used with +/// Implements `epi::App` so it can be used with /// [`egui_glium`](https://crates.io/crates/egui_glium) and [`egui_web`](https://crates.io/crates/egui_web). #[derive(Default)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] @@ -192,7 +192,7 @@ pub struct DemoApp { } impl DemoApp { - fn backend_ui(&mut self, ui: &mut Ui, integration_context: &mut app::IntegrationContext<'_>) { + fn backend_ui(&mut self, ui: &mut Ui, integration_context: &mut epi::IntegrationContext<'_>) { let is_web = integration_context.info.web_info.is_some(); if is_web { @@ -227,7 +227,7 @@ impl DemoApp { } } - fn pixels_per_point_ui(&mut self, ui: &mut Ui, info: &app::IntegrationInfo) -> Option { + fn pixels_per_point_ui(&mut self, ui: &mut Ui, info: &epi::IntegrationInfo) -> Option { self.pixels_per_point = self .pixels_per_point .or(info.native_pixels_per_point) @@ -278,22 +278,22 @@ impl DemoApp { } } -impl app::App for DemoApp { +impl epi::App for DemoApp { fn name(&self) -> &str { "Egui Demo" } #[cfg(feature = "serde_json")] - fn load(&mut self, storage: &dyn egui::app::Storage) { - *self = egui::app::get_value(storage, egui::app::APP_KEY).unwrap_or_default() + fn load(&mut self, storage: &dyn epi::Storage) { + *self = epi::get_value(storage, epi::APP_KEY).unwrap_or_default() } #[cfg(feature = "serde_json")] - fn save(&mut self, storage: &mut dyn egui::app::Storage) { - egui::app::set_value(storage, egui::app::APP_KEY, self); + fn save(&mut self, storage: &mut dyn epi::Storage) { + epi::set_value(storage, epi::APP_KEY, self); } - fn ui(&mut self, ctx: &CtxRef, integration_context: &mut egui::app::IntegrationContext<'_>) { + fn ui(&mut self, ctx: &CtxRef, integration_context: &mut epi::IntegrationContext<'_>) { self.frame_history .on_new_frame(ctx.input().time, integration_context.info.cpu_usage); diff --git a/egui_demo_lib/src/color_test.rs b/egui_demo_lib/src/color_test.rs index f4854c0c..c7dde4d8 100644 --- a/egui_demo_lib/src/color_test.rs +++ b/egui_demo_lib/src/color_test.rs @@ -25,7 +25,7 @@ impl ColorTest { pub fn ui( &mut self, ui: &mut Ui, - mut tex_allocator: &mut Option<&mut dyn app::TextureAllocator>, + mut tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>, ) { ui.label("This is made to test if your Egui painter backend is set up correctly"); ui.label("It is meant to ensure you do proper sRGBA decoding of both texture and vertex colors, and blend using premultiplied alpha."); @@ -132,7 +132,7 @@ impl ColorTest { fn show_gradients( &mut self, ui: &mut Ui, - tex_allocator: &mut Option<&mut dyn app::TextureAllocator>, + tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>, bg_fill: Srgba, (left, right): (Srgba, Srgba), ) { @@ -226,7 +226,7 @@ impl ColorTest { fn tex_gradient( &mut self, ui: &mut Ui, - tex_allocator: &mut Option<&mut dyn app::TextureAllocator>, + tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>, label: &str, bg_fill: Srgba, gradient: &Gradient, @@ -358,7 +358,7 @@ struct TextureManager(HashMap); impl TextureManager { fn get( &mut self, - tex_allocator: &mut dyn app::TextureAllocator, + tex_allocator: &mut dyn epi::TextureAllocator, gradient: &Gradient, ) -> TextureId { *self.0.entry(gradient.clone()).or_insert_with(|| { diff --git a/egui_demo_lib/src/demo_windows.rs b/egui_demo_lib/src/demo_windows.rs index 8b2252df..4416d5f2 100644 --- a/egui_demo_lib/src/demo_windows.rs +++ b/egui_demo_lib/src/demo_windows.rs @@ -1,4 +1,4 @@ -use egui::{app, CtxRef, Resize, ScrollArea, Ui, Window}; +use egui::{CtxRef, Resize, ScrollArea, Ui, Window}; // ---------------------------------------------------------------------------- @@ -84,7 +84,7 @@ impl DemoWindows { &mut self, ctx: &CtxRef, env: &DemoEnvironment, - tex_allocator: &mut Option<&mut dyn app::TextureAllocator>, + tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>, sidebar_ui: impl FnOnce(&mut Ui), ) { if self.previous_link != env.link { @@ -144,7 +144,7 @@ impl DemoWindows { &mut self, ctx: &CtxRef, env: &DemoEnvironment, - tex_allocator: &mut Option<&mut dyn app::TextureAllocator>, + tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>, ) { let Self { open_windows, diff --git a/egui_glium/Cargo.toml b/egui_glium/Cargo.toml index 4c83d0d1..38b0684d 100644 --- a/egui_glium/Cargo.toml +++ b/egui_glium/Cargo.toml @@ -16,7 +16,8 @@ include = [ "**/*.rs", "Cargo.toml"] chrono = { version = "0.4" } clipboard = "0.5" directories-next = "2" -egui = { version = "0.6.0", path = "../egui", features = ["serde", "serde_json"] } +egui = { version = "0.6.0", path = "../egui", features = ["serde"] } +epi = { version = "0.6.0", path = "../epi", features = ["serde", "serde_json"] } glium = "0.29" serde = "1" serde_json = "1" diff --git a/egui_glium/src/backend.rs b/egui_glium/src/backend.rs index c2cb9f7b..c224607d 100644 --- a/egui_glium/src/backend.rs +++ b/egui_glium/src/backend.rs @@ -2,15 +2,12 @@ use std::time::Instant; use crate::{storage::WindowSettings, *}; -pub use egui::{ - app::{self, App, Storage}, - Srgba, -}; +pub use egui::Srgba; const EGUI_MEMORY_KEY: &str = "egui"; const WINDOW_KEY: &str = "window"; -impl egui::app::TextureAllocator for Painter { +impl epi::TextureAllocator for Painter { fn alloc(&mut self) -> egui::TextureId { self.alloc_user_texture() } @@ -35,7 +32,7 @@ struct GliumRepaintSignal( std::sync::Mutex>, ); -impl egui::app::RepaintSignal for GliumRepaintSignal { +impl epi::RepaintSignal for GliumRepaintSignal { fn request_repaint(&self) { self.0.lock().unwrap().send_event(RequestRepaintEvent).ok(); } @@ -72,7 +69,7 @@ fn create_display( display } -fn create_storage(app_name: &str) -> Option> { +fn create_storage(app_name: &str) -> Option> { if let Some(proj_dirs) = directories_next::ProjectDirs::from("", "", app_name) { let data_dir = proj_dirs.data_dir().to_path_buf(); if let Err(err) = std::fs::create_dir_all(&data_dir) { @@ -94,7 +91,7 @@ fn create_storage(app_name: &str) -> Option> { } /// Run an egui app -pub fn run(mut app: Box) -> ! { +pub fn run(mut app: Box) -> ! { let mut storage = create_storage(app.name()); if let Some(storage) = &mut storage { @@ -103,7 +100,7 @@ pub fn run(mut app: Box) -> ! { let window_settings: Option = storage .as_mut() - .and_then(|storage| egui::app::get_value(storage.as_ref(), WINDOW_KEY)); + .and_then(|storage| epi::get_value(storage.as_ref(), WINDOW_KEY)); let event_loop = glutin::event_loop::EventLoop::with_user_event(); let display = create_display(app.name(), window_settings, app.is_resizable(), &event_loop); @@ -114,7 +111,7 @@ pub fn run(mut app: Box) -> ! { let mut ctx = egui::CtxRef::default(); *ctx.memory() = storage .as_mut() - .and_then(|storage| egui::app::get_value(storage.as_ref(), EGUI_MEMORY_KEY)) + .and_then(|storage| epi::get_value(storage.as_ref(), EGUI_MEMORY_KEY)) .unwrap_or_default(); app.setup(&ctx); @@ -137,8 +134,8 @@ pub fn run(mut app: Box) -> ! { )); ctx.begin_frame(input_state.raw.take()); - let mut integration_context = egui::app::IntegrationContext { - info: egui::app::IntegrationInfo { + let mut integration_context = epi::IntegrationContext { + info: epi::IntegrationInfo { web_info: None, cpu_usage: previous_frame_time, seconds_since_midnight: Some(seconds_since_midnight()), @@ -164,7 +161,7 @@ pub fn run(mut app: Box) -> ! { ); { - let egui::app::AppOutput { + let epi::AppOutput { quit, window_size, pixels_per_point, @@ -200,12 +197,12 @@ pub fn run(mut app: Box) -> ! { if let Some(storage) = &mut storage { let now = Instant::now(); if now - last_auto_save > app.auto_save_interval() { - egui::app::set_value( + epi::set_value( storage.as_mut(), WINDOW_KEY, &WindowSettings::from_display(&display), ); - egui::app::set_value(storage.as_mut(), EGUI_MEMORY_KEY, &*ctx.memory()); + epi::set_value(storage.as_mut(), EGUI_MEMORY_KEY, &*ctx.memory()); app.save(storage.as_mut()); storage.flush(); last_auto_save = now; @@ -227,12 +224,12 @@ pub fn run(mut app: Box) -> ! { glutin::event::Event::LoopDestroyed => { app.on_exit(); if let Some(storage) = &mut storage { - egui::app::set_value( + epi::set_value( storage.as_mut(), WINDOW_KEY, &WindowSettings::from_display(&display), ); - egui::app::set_value(storage.as_mut(), EGUI_MEMORY_KEY, &*ctx.memory()); + epi::set_value(storage.as_mut(), EGUI_MEMORY_KEY, &*ctx.memory()); app.save(storage.as_mut()); storage.flush(); } diff --git a/egui_glium/src/storage.rs b/egui_glium/src/storage.rs index 55c57903..31bfef81 100644 --- a/egui_glium/src/storage.rs +++ b/egui_glium/src/storage.rs @@ -24,7 +24,7 @@ impl FileStorage { } } -impl egui::app::Storage for FileStorage { +impl epi::Storage for FileStorage { fn get_string(&self, key: &str) -> Option { self.kv.get(key).cloned() } diff --git a/egui_web/Cargo.toml b/egui_web/Cargo.toml index 26cca06b..25ae9c75 100644 --- a/egui_web/Cargo.toml +++ b/egui_web/Cargo.toml @@ -17,6 +17,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] egui = { version = "0.6.0", path = "../egui", features = ["serde"] } +epi = { version = "0.6.0", path = "../epi", features = ["serde", "serde_json"] } js-sys = "0.3" serde = "1" serde_json = "1" diff --git a/egui_web/src/backend.rs b/egui_web/src/backend.rs index 977bc53d..b3ae6def 100644 --- a/egui_web/src/backend.rs +++ b/egui_web/src/backend.rs @@ -1,9 +1,6 @@ use crate::*; -pub use egui::{ - app::{App, WebInfo}, - pos2, Srgba, -}; +pub use egui::{pos2, Srgba}; // ---------------------------------------------------------------------------- @@ -68,7 +65,7 @@ impl WebBackend { } } -impl egui::app::TextureAllocator for webgl::Painter { +impl epi::TextureAllocator for webgl::Painter { fn alloc(&mut self) -> egui::TextureId { self.alloc_user_texture() } @@ -131,7 +128,7 @@ impl NeedRepaint { } } -impl egui::app::RepaintSignal for NeedRepaint { +impl epi::RepaintSignal for NeedRepaint { fn request_repaint(&self) { self.0.store(true, SeqCst); } @@ -142,14 +139,14 @@ impl egui::app::RepaintSignal for NeedRepaint { pub struct AppRunner { pub web_backend: WebBackend, pub input: WebInput, - pub app: Box, + pub app: Box, pub needs_repaint: std::sync::Arc, pub storage: LocalStorage, pub last_save_time: f64, } impl AppRunner { - pub fn new(web_backend: WebBackend, mut app: Box) -> Result { + pub fn new(web_backend: WebBackend, mut app: Box) -> Result { load_memory(&web_backend.ctx); let storage = LocalStorage::default(); app.load(&storage); @@ -185,9 +182,9 @@ impl AppRunner { let raw_input = self.input.new_frame(canvas_size); self.web_backend.begin_frame(raw_input); - let mut integration_context = egui::app::IntegrationContext { - info: egui::app::IntegrationInfo { - web_info: Some(WebInfo { + let mut integration_context = epi::IntegrationContext { + info: epi::IntegrationInfo { + web_info: Some(epi::WebInfo { web_location_hash: location_hash().unwrap_or_default(), }), cpu_usage: self.web_backend.previous_frame_time, @@ -206,7 +203,7 @@ impl AppRunner { handle_output(&egui_output); { - let egui::app::AppOutput { + let epi::AppOutput { quit: _, // Can't quit a web page window_size: _, // Can't resize a web page pixels_per_point: _, // Can't zoom from within the app (we respect the web browser's zoom level) @@ -223,7 +220,7 @@ impl AppRunner { /// Install event listeners to register different input events /// and starts running the given app. -pub fn start(canvas_id: &str, app: Box) -> Result { +pub fn start(canvas_id: &str, app: Box) -> Result { let backend = WebBackend::new(canvas_id)?; let runner = AppRunner::new(backend, app)?; start_runner(runner) diff --git a/egui_web/src/lib.rs b/egui_web/src/lib.rs index 67ce1a68..0084f37e 100644 --- a/egui_web/src/lib.rs +++ b/egui_web/src/lib.rs @@ -172,7 +172,7 @@ pub fn save_memory(ctx: &egui::Context) { #[derive(Default)] pub struct LocalStorage {} -impl egui::app::Storage for LocalStorage { +impl epi::Storage for LocalStorage { fn get_string(&self, key: &str) -> Option { local_storage_get(key) } diff --git a/epi/Cargo.toml b/epi/Cargo.toml new file mode 100644 index 00000000..6db6b133 --- /dev/null +++ b/epi/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "epi" +version = "0.6.0" +authors = ["Emil Ernerfeldt "] +description = "Backend-agnostic interface for writing apps using Egui" +edition = "2018" +homepage = "https://github.com/emilk/egui" +license = "MIT OR Apache-2.0" +readme = "README.md" +repository = "https://github.com/emilk/egui" +categories = ["gui", "graphics"] +keywords = ["glium", "egui", "gui", "gamedev"] +include = [ "**/*.rs", "Cargo.toml"] + +[lib] + +[dependencies] +egui = { version = "0.6.0", path = "../egui" } +serde = { version = "1", optional = true } +serde_json = { version = "1", optional = true } diff --git a/epi/README.md b/epi/README.md new file mode 100644 index 00000000..9c2e85d9 --- /dev/null +++ b/epi/README.md @@ -0,0 +1,7 @@ +# Egui app Programming Interface + +Backend-agnostic interface for writing apps using Egui. + +Egui is a GUI library, which can be plugged in to e.g. a game engine. + +This crate provides a common interface for programming an app, using Egui, so you can then easily plug it in to a backend such as `egui_web` or `egui_glium`. diff --git a/egui/src/app.rs b/epi/src/lib.rs similarity index 69% rename from egui/src/app.rs rename to epi/src/lib.rs index 3982fd27..dcb37194 100644 --- a/egui/src/app.rs +++ b/epi/src/lib.rs @@ -1,11 +1,56 @@ -//! Traits and helper for writing Egui apps. +//! Backend-agnostic interface for writing apps using Egui. //! -//! This module is very experimental, and you don't need to use it. +//! Egui is a GUI library, which can be plugged in to e.g. a game engine. //! -//! Egui can be used as a library, but you can also use it as a framework to write apps in. -//! This module defined the `App` trait that can be implemented and used with the `egui_web` and `egui_glium` crates. +//! This crate provides a common interface for programming an app, using Egui, +//! so you can then easily plug it in to a backend such as `egui_web` or `egui_glium`. +//! +//! This crate is primarily used by the `egui_web` and `egui_glium` crates. -// TODO: move egui/src/app.rs to own crate, e.g. egui_framework ? +#![cfg_attr(not(debug_assertions), deny(warnings))] // Forbid warnings in release builds +#![forbid(unsafe_code)] +#![warn( + clippy::all, + clippy::await_holding_lock, + clippy::dbg_macro, + clippy::doc_markdown, + clippy::empty_enum, + clippy::enum_glob_use, + clippy::exit, + clippy::filter_map_next, + clippy::fn_params_excessive_bools, + clippy::if_let_mutex, + clippy::imprecise_flops, + clippy::inefficient_to_string, + clippy::linkedlist, + clippy::lossy_float_literal, + clippy::macro_use_imports, + clippy::match_on_vec_items, + clippy::match_wildcard_for_single_variants, + clippy::mem_forget, + clippy::mismatched_target_os, + clippy::missing_errors_doc, + clippy::missing_safety_doc, + clippy::needless_borrow, + clippy::needless_continue, + clippy::needless_pass_by_value, + clippy::option_option, + clippy::pub_enum_variant_names, + clippy::rest_pat_in_fully_bound_structs, + clippy::todo, + clippy::unimplemented, + clippy::unnested_or_patterns, + clippy::verbose_file_reads, + future_incompatible, + missing_crate_level_docs, + missing_doc_code_examples, + // missing_docs, + nonstandard_style, + rust_2018_idioms, + unused_doc_comments, +)] + +// ---------------------------------------------------------------------------- /// Implement this trait to write apps that can be compiled both natively using the [`egui_glium`](https://crates.io/crates/egui_glium) crate, /// and deployed as a web site using the [`egui_web`](https://crates.io/crates/egui_web) crate. @@ -15,9 +60,9 @@ pub trait App { /// Background color for the app, e.g. what is sent to `gl.clearColor`. /// This is the background of your windows if you don't set a central panel. - fn clear_color(&self) -> crate::Rgba { + fn clear_color(&self) -> egui::Rgba { // NOTE: a bright gray makes the shadows of the windows look weird. - crate::Srgba::from_rgb(12, 12, 12).into() + egui::Srgba::from_rgb(12, 12, 12).into() } /// Called once on start. Allows you to restore state. @@ -37,7 +82,7 @@ pub trait App { /// Called once before the first frame. /// Allows you to do setup code and to call `ctx.set_fonts()`. /// Optional. - fn setup(&mut self, _ctx: &crate::CtxRef) {} + fn setup(&mut self, _ctx: &egui::CtxRef) {} /// Returns true if this app window should be resizable. fn is_resizable(&self) -> bool { @@ -46,7 +91,7 @@ pub trait App { /// Called each time the UI needs repainting, which may be many times per second. /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. - fn ui(&mut self, ctx: &crate::CtxRef, integration_context: &mut IntegrationContext<'_>); + fn ui(&mut self, ctx: &egui::CtxRef, integration_context: &mut IntegrationContext<'_>); } pub struct IntegrationContext<'a> { @@ -92,7 +137,7 @@ pub struct AppOutput { pub quit: bool, /// Set to some size to resize the outer window (e.g. glium window) to this size. - pub window_size: Option, + pub window_size: Option, /// If the app sets this, change the `pixels_per_point` of Egui to this next frame. pub pixels_per_point: Option, @@ -100,18 +145,18 @@ pub struct AppOutput { pub trait TextureAllocator { /// A.locate a new user texture. - fn alloc(&mut self) -> crate::TextureId; + fn alloc(&mut self) -> egui::TextureId; /// Set or change the pixels of a user texture. fn set_srgba_premultiplied( &mut self, - id: crate::TextureId, + id: egui::TextureId, size: (usize, usize), - srgba_pixels: &[crate::Srgba], + srgba_pixels: &[egui::Srgba], ); /// Free the given texture. - fn free(&mut self, id: crate::TextureId); + fn free(&mut self, id: egui::TextureId); } pub trait RepaintSignal: Send + Sync { @@ -120,6 +165,8 @@ pub trait RepaintSignal: Send + Sync { fn request_repaint(&self); } +// ---------------------------------------------------------------------------- + /// A place where you can store custom data in a way that persists when you restart the app. /// /// On the web this is backed by [local storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage). diff --git a/example_web/Cargo.toml b/example_web/Cargo.toml index a091021e..f44e9851 100644 --- a/example_web/Cargo.toml +++ b/example_web/Cargo.toml @@ -11,6 +11,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] egui = { path = "../egui", features = ["serde"] } egui_web = { path = "../egui_web" } +epi = { version = "0.6.0", path = "../epi", features = ["serde", "serde_json"] } image = { version = "0.23", default_features = false, features = ["jpeg", "png"] } js-sys = "0.3" serde = { version = "1", features = ["derive"] } diff --git a/example_web/src/example_app.rs b/example_web/src/example_app.rs index f4a580c3..e14ab145 100644 --- a/example_web/src/example_app.rs +++ b/example_web/src/example_app.rs @@ -48,14 +48,14 @@ impl Default for ExampleApp { } } -impl egui::app::App for ExampleApp { +impl epi::App for ExampleApp { fn name(&self) -> &str { "Egui Fetch Example" } /// Called each time the UI needs repainting, which may be many times per second. /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. - fn ui(&mut self, ctx: &egui::CtxRef, integration_context: &mut egui::app::IntegrationContext) { + fn ui(&mut self, ctx: &egui::CtxRef, integration_context: &mut epi::IntegrationContext) { if let Some(receiver) = &mut self.in_progress { // Are we there yet? if let Ok(result) = receiver.try_recv() { @@ -137,7 +137,7 @@ fn ui_url(ui: &mut egui::Ui, url: &mut String) -> Option { fn ui_resouce( ui: &mut egui::Ui, - integration_context: &mut egui::app::IntegrationContext, + integration_context: &mut epi::IntegrationContext, tex_mngr: &mut TexMngr, resource: &Resource, ) { @@ -250,7 +250,7 @@ struct TexMngr { impl TexMngr { fn texture( &mut self, - integration_context: &mut egui::app::IntegrationContext, + integration_context: &mut epi::IntegrationContext, url: &str, image: &Image, ) -> Option {