diff --git a/Cargo.lock b/Cargo.lock index e55307e93..8ec5953b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1116,9 +1116,16 @@ dependencies = [ name = "egui_demo_app" version = "0.17.0" dependencies = [ + "chrono", "console_error_panic_hook", "eframe", + "egui", "egui_demo_lib", + "egui_extras", + "ehttp", + "image", + "poll-promise", + "serde", "tracing-subscriber", "tracing-wasm", ] @@ -1131,11 +1138,7 @@ dependencies = [ "criterion", "egui", "egui_extras", - "ehttp", "enum-map", - "epi", - "image", - "poll-promise", "serde", "syntect", "tracing", diff --git a/egui_demo_app/Cargo.toml b/egui_demo_app/Cargo.toml index e937764b0..f0f47b703 100644 --- a/egui_demo_app/Cargo.toml +++ b/egui_demo_app/Cargo.toml @@ -16,21 +16,44 @@ crate-type = ["cdylib", "rlib"] [features] default = ["persistence"] -http = ["egui_demo_lib/http"] -persistence = ["eframe/persistence", "egui_demo_lib/persistence"] -screen_reader = ["eframe/screen_reader"] # experimental + +http = ["ehttp", "image", "poll-promise", "egui_extras/image"] +persistence = [ + "eframe/persistence", + "egui/persistence", + "serde", +] +screen_reader = ["eframe/screen_reader"] # experimental +serde = [ + "dep:serde", + "egui_demo_lib/serde", + "egui_extras/serde", + "egui/serde", +] syntax_highlighting = ["egui_demo_lib/syntax_highlighting"] [dependencies] +chrono = { version = "0.4", features = ["js-sys", "wasmbind"] } eframe = { version = "0.17.0", path = "../eframe" } +egui = { version = "0.17.0", path = "../egui", features = ["extra_debug_asserts"] } +egui_demo_lib = { version = "0.17.0", path = "../egui_demo_lib", features = ["chrono"] } + +# Optional dependencies: -# To use the old glium backend instead: -# eframe = { version = "0.17.0", path = "../eframe", default-features = false, features = ["default_fonts", "egui_glium"] } +egui_extras = { version = "0.17.0", optional = true, path = "../egui_extras" } -egui_demo_lib = { version = "0.17.0", path = "../egui_demo_lib", features = [ - "extra_debug_asserts", +# feature "http": +ehttp = { version = "0.2.0", optional = true } +image = { version = "0.24", optional = true, default-features = false, features = [ + "jpeg", + "png", ] } +poll-promise = { version = "0.1", optional = true, default-features = false } + +# feature "persistence": +serde = { version = "1", optional = true, features = ["derive"] } + # native: [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/egui_demo_app/README.md b/egui_demo_app/README.md new file mode 100644 index 000000000..0eb6d8315 --- /dev/null +++ b/egui_demo_app/README.md @@ -0,0 +1,15 @@ +# egui demo app +This app demonstrates [`egui`](https://github.com/emilk/egui/) and [`eframe`](https://github.com/emilk/egui/tree/master/eframe). + +View the demo app online at . + +Run it locally with `cargo run --release -p egui_demo_app`. + +`egui_demo_app` can be compiled to WASM and viewed in a browser locally with: + +```sh +./sh/start_server.sh & +./sh/build_demo_web.sh --fast --open +``` + +`egui_demo_app` uses [`egui_demo_lib`](https://github.com/emilk/egui/tree/master/egui_demo_lib). diff --git a/egui_demo_lib/src/apps/fractal_clock.rs b/egui_demo_app/src/apps/fractal_clock.rs similarity index 95% rename from egui_demo_lib/src/apps/fractal_clock.rs rename to egui_demo_app/src/apps/fractal_clock.rs index eedb9d037..fc2af9a2b 100644 --- a/egui_demo_lib/src/apps/fractal_clock.rs +++ b/egui_demo_app/src/apps/fractal_clock.rs @@ -32,14 +32,6 @@ impl Default for FractalClock { } } -impl epi::App for FractalClock { - fn update(&mut self, ctx: &egui::Context, _frame: &mut epi::Frame) { - egui::CentralPanel::default() - .frame(Frame::dark_canvas(&ctx.style())) - .show(ctx, |ui| self.ui(ui, crate::seconds_since_midnight())); - } -} - impl FractalClock { pub fn ui(&mut self, ui: &mut Ui, seconds_since_midnight: Option) { if !self.paused { @@ -93,7 +85,7 @@ impl FractalClock { "Inspired by a screensaver by Rob Mayoff", "http://www.dqd.com/~mayoff/programs/FractalClock/", ); - ui.add(crate::egui_github_link_file!()); + ui.add(egui_demo_lib::egui_github_link_file!()); } fn paint(&mut self, painter: &Painter) { diff --git a/egui_demo_lib/src/apps/http_app.rs b/egui_demo_app/src/apps/http_app.rs similarity index 97% rename from egui_demo_lib/src/apps/http_app.rs rename to egui_demo_app/src/apps/http_app.rs index e858ae49f..cd551de5b 100644 --- a/egui_demo_lib/src/apps/http_app.rs +++ b/egui_demo_app/src/apps/http_app.rs @@ -53,12 +53,12 @@ impl Default for HttpApp { } } -impl epi::App for HttpApp { - fn update(&mut self, ctx: &egui::Context, frame: &mut epi::Frame) { +impl eframe::App for HttpApp { + fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { egui::TopBottomPanel::bottom("http_bottom").show(ctx, |ui| { let layout = egui::Layout::top_down(egui::Align::Center).with_main_justify(true); ui.allocate_ui_with_layout(ui.available_size(), layout, |ui| { - ui.add(crate::egui_github_link_file!()) + ui.add(egui_demo_lib::egui_github_link_file!()) }) }); @@ -108,7 +108,7 @@ impl epi::App for HttpApp { } } -fn ui_url(ui: &mut egui::Ui, frame: &mut epi::Frame, url: &mut String) -> bool { +fn ui_url(ui: &mut egui::Ui, frame: &mut eframe::Frame, url: &mut String) -> bool { let mut trigger_fetch = false; ui.horizontal(|ui| { diff --git a/egui_demo_lib/src/apps/mod.rs b/egui_demo_app/src/apps/mod.rs similarity index 54% rename from egui_demo_lib/src/apps/mod.rs rename to egui_demo_app/src/apps/mod.rs index f801529f3..4476d06b2 100644 --- a/egui_demo_lib/src/apps/mod.rs +++ b/egui_demo_app/src/apps/mod.rs @@ -1,13 +1,9 @@ -mod color_test; -mod demo; mod fractal_clock; + #[cfg(feature = "http")] mod http_app; -pub use color_test::ColorTest; -pub use demo::DemoApp; pub use fractal_clock::FractalClock; + #[cfg(feature = "http")] pub use http_app::HttpApp; - -pub use demo::DemoWindows; // used for tests diff --git a/egui_demo_lib/src/backend_panel.rs b/egui_demo_app/src/backend_panel.rs similarity index 98% rename from egui_demo_lib/src/backend_panel.rs rename to egui_demo_app/src/backend_panel.rs index 100d5de8b..3401417bb 100644 --- a/egui_demo_lib/src/backend_panel.rs +++ b/egui_demo_app/src/backend_panel.rs @@ -62,7 +62,7 @@ pub struct BackendPanel { } impl BackendPanel { - pub fn update(&mut self, ctx: &egui::Context, frame: &mut epi::Frame) { + pub fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { self.frame_history .on_new_frame(ctx.input().time, frame.info().cpu_usage); @@ -76,7 +76,7 @@ impl BackendPanel { self.egui_windows.windows(ctx); } - pub fn ui(&mut self, ui: &mut egui::Ui, frame: &mut epi::Frame) { + pub fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) { egui::trace!(ui); ui.vertical_centered(|ui| { ui.heading("💻 Backend"); @@ -131,7 +131,7 @@ impl BackendPanel { } } - fn integration_ui(&mut self, ui: &mut egui::Ui, frame: &mut epi::Frame) { + fn integration_ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) { if frame.is_web() { ui.label("egui is an immediate mode GUI written in Rust, compiled to WebAssembly, rendered with WebGL."); ui.label( @@ -172,7 +172,7 @@ impl BackendPanel { fn pixels_per_point_ui( &mut self, ui: &mut egui::Ui, - info: &epi::IntegrationInfo, + info: &eframe::IntegrationInfo, ) -> Option { let pixels_per_point = self.pixels_per_point.get_or_insert_with(|| { info.native_pixels_per_point @@ -234,7 +234,7 @@ impl BackendPanel { // ---------------------------------------------------------------------------- -fn show_integration_name(ui: &mut egui::Ui, integration_info: &epi::IntegrationInfo) { +fn show_integration_name(ui: &mut egui::Ui, integration_info: &eframe::IntegrationInfo) { let name = integration_info.name; ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 0.0; diff --git a/egui_demo_lib/src/frame_history.rs b/egui_demo_app/src/frame_history.rs similarity index 100% rename from egui_demo_lib/src/frame_history.rs rename to egui_demo_app/src/frame_history.rs diff --git a/egui_demo_app/src/lib.rs b/egui_demo_app/src/lib.rs index e81aba48f..cc7bf65d4 100644 --- a/egui_demo_app/src/lib.rs +++ b/egui_demo_app/src/lib.rs @@ -1,5 +1,23 @@ //! Demo app for egui +mod apps; +mod backend_panel; +pub(crate) mod frame_history; +mod wrap_app; + +pub use wrap_app::WrapApp; + +/// Time of day as seconds since midnight. Used for clock in demo app. +pub(crate) fn seconds_since_midnight() -> Option { + use chrono::Timelike; + let time = chrono::Local::now().time(); + let seconds_since_midnight = + time.num_seconds_from_midnight() as f64 + 1e-9 * (time.nanosecond() as f64); + Some(seconds_since_midnight) +} + +// ---------------------------------------------------------------------------- + #[cfg(target_arch = "wasm32")] use eframe::wasm_bindgen::{self, prelude::*}; @@ -16,8 +34,5 @@ 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, - Box::new(|cc| Box::new(egui_demo_lib::WrapApp::new(cc))), - ) + eframe::start_web(canvas_id, Box::new(|cc| Box::new(WrapApp::new(cc)))) } diff --git a/egui_demo_app/src/main.rs b/egui_demo_app/src/main.rs index 6d747f0fe..4a2ca7e65 100644 --- a/egui_demo_app/src/main.rs +++ b/egui_demo_app/src/main.rs @@ -16,6 +16,6 @@ fn main() { eframe::run_native( "egui demo app", options, - Box::new(|cc| Box::new(egui_demo_lib::WrapApp::new(cc))), + Box::new(|cc| Box::new(egui_demo_app::WrapApp::new(cc))), ); } diff --git a/egui_demo_lib/src/wrap_app.rs b/egui_demo_app/src/wrap_app.rs similarity index 70% rename from egui_demo_lib/src/wrap_app.rs rename to egui_demo_app/src/wrap_app.rs index 699d7e195..958ab84e6 100644 --- a/egui_demo_lib/src/wrap_app.rs +++ b/egui_demo_app/src/wrap_app.rs @@ -1,36 +1,105 @@ +#[derive(Default)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] +struct EasyMarkApp { + editor: egui_demo_lib::easy_mark::EasyMarkEditor, +} + +impl eframe::App for EasyMarkApp { + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + self.editor.panels(ctx); + } +} + +// ---------------------------------------------------------------------------- + +#[derive(Default)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] +pub struct DemoApp { + demo_windows: egui_demo_lib::DemoWindows, +} + +impl eframe::App for DemoApp { + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + self.demo_windows.ui(ctx); + } +} + +// ---------------------------------------------------------------------------- + +#[derive(Default)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] +pub struct FractalClockApp { + fractal_clock: crate::apps::FractalClock, +} + +impl eframe::App for FractalClockApp { + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + egui::CentralPanel::default() + .frame(egui::Frame::dark_canvas(&ctx.style())) + .show(ctx, |ui| { + self.fractal_clock.ui(ui, crate::seconds_since_midnight()); + }); + } +} +// ---------------------------------------------------------------------------- + +#[derive(Default)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] +pub struct ColorTestApp { + color_test: egui_demo_lib::ColorTest, +} + +impl eframe::App for ColorTestApp { + fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { + egui::CentralPanel::default().show(ctx, |ui| { + if frame.is_web() { + ui.label( + "NOTE: Some old browsers stuck on WebGL1 without sRGB support will not pass the color test.", + ); + ui.separator(); + } + egui::ScrollArea::both().auto_shrink([false; 2]).show(ui, |ui| { + self.color_test.ui(ui); + }); + }); + } +} + +// ---------------------------------------------------------------------------- + /// All the different demo apps. #[derive(Default)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", serde(default))] pub struct Apps { - demo: crate::apps::DemoApp, - easy_mark_editor: crate::easy_mark::EasyMarkEditor, + demo: DemoApp, + easy_mark_editor: EasyMarkApp, #[cfg(feature = "http")] http: crate::apps::HttpApp, - clock: crate::apps::FractalClock, - color_test: crate::apps::ColorTest, + clock: FractalClockApp, + color_test: ColorTestApp, } impl Apps { - fn iter_mut(&mut self) -> impl Iterator { + fn iter_mut(&mut self) -> impl Iterator { vec![ - ("✨ Demos", "demo", &mut self.demo as &mut dyn epi::App), + ("✨ Demos", "demo", &mut self.demo as &mut dyn eframe::App), ( "🖹 EasyMark editor", "easymark", - &mut self.easy_mark_editor as &mut dyn epi::App, + &mut self.easy_mark_editor as &mut dyn eframe::App, ), #[cfg(feature = "http")] - ("⬇ HTTP", "http", &mut self.http as &mut dyn epi::App), + ("⬇ HTTP", "http", &mut self.http as &mut dyn eframe::App), ( "🕑 Fractal Clock", "clock", - &mut self.clock as &mut dyn epi::App, + &mut self.clock as &mut dyn eframe::App, ), ( "🎨 Color test", "colors", - &mut self.color_test as &mut dyn epi::App, + &mut self.color_test as &mut dyn eframe::App, ), ] .into_iter() @@ -50,26 +119,26 @@ pub struct WrapApp { } impl WrapApp { - pub fn new(_cc: &epi::CreationContext<'_>) -> Self { + pub fn new(_cc: &eframe::CreationContext<'_>) -> Self { #[cfg(feature = "persistence")] if let Some(storage) = _cc.storage { - return epi::get_value(storage, epi::APP_KEY).unwrap_or_default(); + return eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default(); } Self::default() } } -impl epi::App for WrapApp { +impl eframe::App for WrapApp { #[cfg(feature = "persistence")] - fn save(&mut self, storage: &mut dyn epi::Storage) { - epi::set_value(storage, epi::APP_KEY, self); + fn save(&mut self, storage: &mut dyn eframe::Storage) { + eframe::set_value(storage, eframe::APP_KEY, self); } fn clear_color(&self) -> egui::Rgba { egui::Rgba::TRANSPARENT // we set a [`CentralPanel`] fill color in `demo_windows.rs` } - fn update(&mut self, ctx: &egui::Context, frame: &mut epi::Frame) { + fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { if let Some(web_info) = frame.info().web_info.as_ref() { if let Some(anchor) = web_info.location.hash.strip_prefix('#') { self.selected_anchor = anchor.to_owned(); @@ -130,7 +199,7 @@ impl epi::App for WrapApp { } impl WrapApp { - fn bar_contents(&mut self, ui: &mut egui::Ui, frame: &mut epi::Frame) { + fn bar_contents(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) { // A menu-bar is a horizontal layout with some special styles applied. // egui::menu::bar(ui, |ui| { ui.horizontal_wrapped(|ui| { diff --git a/egui_demo_lib/Cargo.toml b/egui_demo_lib/Cargo.toml index 94dd975a9..9260c5ee6 100644 --- a/egui_demo_lib/Cargo.toml +++ b/egui_demo_lib/Cargo.toml @@ -20,57 +20,30 @@ all-features = true [features] -default = ["datetime"] +default = [] -# Enable additional checks if debug assertions are enabled (debug builds). -extra_debug_asserts = ["egui/extra_debug_asserts"] -# Always enable additional checks. -extra_asserts = ["egui/extra_asserts"] - -datetime = ["egui_extras/chrono", "chrono"] -http = ["ehttp", "image", "poll-promise"] -persistence = [ - "egui/persistence", - "epi/persistence", - "egui_extras/persistence", - "serde", -] +chrono = ["egui_extras/datepicker", "dep:chrono"] serde = ["egui/serde", "dep:serde"] syntax_highlighting = ["syntect"] [dependencies] egui = { version = "0.17.0", path = "../egui", default-features = false } -epi = { version = "0.17.0", path = "../epi" } -egui_extras = { version = "0.17.0", path = "../egui_extras", features = [ - "image", - "datepicker", -] } - -chrono = { version = "0.4", optional = true, features = ["js-sys", "wasmbind"] } +egui_extras = { version = "0.17.0", path = "../egui_extras" } enum-map = { version = "2", features = ["serde"] } tracing = "0.1" unicode_names2 = { version = "0.5.0", default-features = false } -# feature "http": -ehttp = { version = "0.2.0", optional = true } -image = { version = "0.24", optional = true, default-features = false, features = [ - "jpeg", - "png", -] } -poll-promise = { version = "0.1", optional = true, default-features = false } - -# feature "syntax_highlighting": -syntect = { version = "4", optional = true, default-features = false, features = [ - "default-fancy", -] } - -# feature "persistence": +# Optional: +chrono = { version = "0.4", optional = true, features = ["js-sys", "wasmbind"] } serde = { version = "1", optional = true, features = ["derive"] } +syntect = { version = "4", optional = true, default-features = false, features = ["default-fancy"] } + [dev-dependencies] criterion = { version = "0.3", default-features = false } + [[bench]] name = "benchmark" harness = false diff --git a/egui_demo_lib/README.md b/egui_demo_lib/README.md index 3772c953d..43ca0a0f3 100644 --- a/egui_demo_lib/README.md +++ b/egui_demo_lib/README.md @@ -12,4 +12,5 @@ The demo library is a separate crate for three reasons: * To ensure it only uses the public `egui` api. * To remove the amount of code in `egui` proper. -* To make it easy for other integrations to use the egui demos a test. +* To make it easy for 3rd party egui integrations to use it for tests. + - See for instance https://github.com/not-fl3/egui-miniquad/blob/master/examples/demo.rs diff --git a/egui_demo_lib/src/apps/demo/app.rs b/egui_demo_lib/src/apps/demo/app.rs deleted file mode 100644 index 5a74e1ab4..000000000 --- a/egui_demo_lib/src/apps/demo/app.rs +++ /dev/null @@ -1,12 +0,0 @@ -#[derive(Default)] -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] -#[cfg_attr(feature = "serde", serde(default))] -pub struct DemoApp { - demo_windows: super::DemoWindows, -} - -impl epi::App for DemoApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut epi::Frame) { - self.demo_windows.ui(ctx); - } -} diff --git a/egui_demo_lib/src/apps/color_test.rs b/egui_demo_lib/src/color_test.rs similarity index 96% rename from egui_demo_lib/src/apps/color_test.rs rename to egui_demo_lib/src/color_test.rs index 4e05b27c9..bef78c393 100644 --- a/egui_demo_lib/src/apps/color_test.rs +++ b/egui_demo_lib/src/color_test.rs @@ -9,6 +9,7 @@ const RED: Color32 = Color32::RED; const TRANSPARENT: Color32 = Color32::TRANSPARENT; const WHITE: Color32 = Color32::WHITE; +/// A test for sanity-checking and diagnosing egui rendering backends. #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct ColorTest { #[cfg_attr(feature = "serde", serde(skip))] @@ -29,22 +30,6 @@ impl Default for ColorTest { } } -impl epi::App for ColorTest { - fn update(&mut self, ctx: &egui::Context, frame: &mut epi::Frame) { - egui::CentralPanel::default().show(ctx, |ui| { - if frame.is_web() { - ui.label( - "NOTE: Some old browsers stuck on WebGL1 without sRGB support will not pass the color test.", - ); - ui.separator(); - } - ScrollArea::both().auto_shrink([false; 2]).show(ui, |ui| { - self.ui(ui); - }); - }); - } -} - impl ColorTest { pub fn ui(&mut self, ui: &mut Ui) { ui.set_max_width(680.0); diff --git a/egui_demo_lib/src/apps/demo/code_editor.rs b/egui_demo_lib/src/demo/code_editor.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/code_editor.rs rename to egui_demo_lib/src/demo/code_editor.rs diff --git a/egui_demo_lib/src/apps/demo/code_example.rs b/egui_demo_lib/src/demo/code_example.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/code_example.rs rename to egui_demo_lib/src/demo/code_example.rs diff --git a/egui_demo_lib/src/apps/demo/context_menu.rs b/egui_demo_lib/src/demo/context_menu.rs similarity index 97% rename from egui_demo_lib/src/apps/demo/context_menu.rs rename to egui_demo_lib/src/demo/context_menu.rs index e04588537..65b532a21 100644 --- a/egui_demo_lib/src/apps/demo/context_menu.rs +++ b/egui_demo_lib/src/demo/context_menu.rs @@ -1,5 +1,5 @@ #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] enum Plot { Sin, Bell, @@ -15,7 +15,7 @@ fn sigmoid(x: f64) -> f64 { } #[derive(Clone, PartialEq)] -#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct ContextMenus { plot: Plot, show_axes: [bool; 2], diff --git a/egui_demo_lib/src/apps/demo/dancing_strings.rs b/egui_demo_lib/src/demo/dancing_strings.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/dancing_strings.rs rename to egui_demo_lib/src/demo/dancing_strings.rs diff --git a/egui_demo_lib/src/apps/demo/demo_app_windows.rs b/egui_demo_lib/src/demo/demo_app_windows.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/demo_app_windows.rs rename to egui_demo_lib/src/demo/demo_app_windows.rs diff --git a/egui_demo_lib/src/apps/demo/drag_and_drop.rs b/egui_demo_lib/src/demo/drag_and_drop.rs similarity index 98% rename from egui_demo_lib/src/apps/demo/drag_and_drop.rs rename to egui_demo_lib/src/demo/drag_and_drop.rs index 556a38057..bc5fe4b47 100644 --- a/egui_demo_lib/src/apps/demo/drag_and_drop.rs +++ b/egui_demo_lib/src/demo/drag_and_drop.rs @@ -76,7 +76,7 @@ pub fn drop_target( InnerResponse::new(ret, response) } #[derive(Clone, PartialEq)] -#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct DragAndDropDemo { /// columns with items columns: Vec>, diff --git a/egui_demo_lib/src/apps/demo/font_book.rs b/egui_demo_lib/src/demo/font_book.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/font_book.rs rename to egui_demo_lib/src/demo/font_book.rs diff --git a/egui_demo_lib/src/apps/demo/layout_test.rs b/egui_demo_lib/src/demo/layout_test.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/layout_test.rs rename to egui_demo_lib/src/demo/layout_test.rs diff --git a/egui_demo_lib/src/apps/demo/misc_demo_window.rs b/egui_demo_lib/src/demo/misc_demo_window.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/misc_demo_window.rs rename to egui_demo_lib/src/demo/misc_demo_window.rs diff --git a/egui_demo_lib/src/apps/demo/mod.rs b/egui_demo_lib/src/demo/mod.rs similarity index 89% rename from egui_demo_lib/src/apps/demo/mod.rs rename to egui_demo_lib/src/demo/mod.rs index 76ee6e12e..ec78696da 100644 --- a/egui_demo_lib/src/apps/demo/mod.rs +++ b/egui_demo_lib/src/demo/mod.rs @@ -4,7 +4,6 @@ // ---------------------------------------------------------------------------- -mod app; pub mod code_editor; pub mod code_example; pub mod context_menu; @@ -31,8 +30,7 @@ pub mod window_options; pub mod window_with_panels; pub use { - app::DemoApp, demo_app_windows::DemoWindows, misc_demo_window::MiscDemoWindow, - widget_gallery::WidgetGallery, + demo_app_windows::DemoWindows, misc_demo_window::MiscDemoWindow, widget_gallery::WidgetGallery, }; // ---------------------------------------------------------------------------- diff --git a/egui_demo_lib/src/apps/demo/multi_touch.rs b/egui_demo_lib/src/demo/multi_touch.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/multi_touch.rs rename to egui_demo_lib/src/demo/multi_touch.rs diff --git a/egui_demo_lib/src/apps/demo/paint_bezier.rs b/egui_demo_lib/src/demo/paint_bezier.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/paint_bezier.rs rename to egui_demo_lib/src/demo/paint_bezier.rs diff --git a/egui_demo_lib/src/apps/demo/painting.rs b/egui_demo_lib/src/demo/painting.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/painting.rs rename to egui_demo_lib/src/demo/painting.rs diff --git a/egui_demo_lib/src/apps/demo/password.rs b/egui_demo_lib/src/demo/password.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/password.rs rename to egui_demo_lib/src/demo/password.rs diff --git a/egui_demo_lib/src/apps/demo/plot_demo.rs b/egui_demo_lib/src/demo/plot_demo.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/plot_demo.rs rename to egui_demo_lib/src/demo/plot_demo.rs diff --git a/egui_demo_lib/src/apps/demo/scrolling.rs b/egui_demo_lib/src/demo/scrolling.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/scrolling.rs rename to egui_demo_lib/src/demo/scrolling.rs diff --git a/egui_demo_lib/src/apps/demo/sliders.rs b/egui_demo_lib/src/demo/sliders.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/sliders.rs rename to egui_demo_lib/src/demo/sliders.rs diff --git a/egui_demo_lib/src/apps/demo/strip_demo.rs b/egui_demo_lib/src/demo/strip_demo.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/strip_demo.rs rename to egui_demo_lib/src/demo/strip_demo.rs diff --git a/egui_demo_lib/src/apps/demo/table_demo.rs b/egui_demo_lib/src/demo/table_demo.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/table_demo.rs rename to egui_demo_lib/src/demo/table_demo.rs diff --git a/egui_demo_lib/src/apps/demo/tests.rs b/egui_demo_lib/src/demo/tests.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/tests.rs rename to egui_demo_lib/src/demo/tests.rs diff --git a/egui_demo_lib/src/apps/demo/text_edit.rs b/egui_demo_lib/src/demo/text_edit.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/text_edit.rs rename to egui_demo_lib/src/demo/text_edit.rs diff --git a/egui_demo_lib/src/apps/demo/toggle_switch.rs b/egui_demo_lib/src/demo/toggle_switch.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/toggle_switch.rs rename to egui_demo_lib/src/demo/toggle_switch.rs diff --git a/egui_demo_lib/src/apps/demo/widget_gallery.rs b/egui_demo_lib/src/demo/widget_gallery.rs similarity index 98% rename from egui_demo_lib/src/apps/demo/widget_gallery.rs rename to egui_demo_lib/src/demo/widget_gallery.rs index fb7f8b2a5..c9045fef1 100644 --- a/egui_demo_lib/src/apps/demo/widget_gallery.rs +++ b/egui_demo_lib/src/demo/widget_gallery.rs @@ -18,7 +18,7 @@ pub struct WidgetGallery { color: egui::Color32, animate_progress_bar: bool, - #[cfg(feature = "datetime")] + #[cfg(feature = "chrono")] #[cfg_attr(feature = "serde", serde(skip))] date: Option>, @@ -37,7 +37,7 @@ impl Default for WidgetGallery { string: Default::default(), color: egui::Color32::LIGHT_BLUE.linear_multiply(0.5), animate_progress_bar: false, - #[cfg(feature = "datetime")] + #[cfg(feature = "chrono")] date: None, texture: None, } @@ -109,7 +109,7 @@ impl WidgetGallery { string, color, animate_progress_bar, - #[cfg(feature = "datetime")] + #[cfg(feature = "chrono")] date, texture, } = self; @@ -216,7 +216,7 @@ impl WidgetGallery { } ui.end_row(); - #[cfg(feature = "datetime")] + #[cfg(feature = "chrono")] { let date = date.get_or_insert_with(|| chrono::offset::Utc::now().date()); ui.add(doc_link_label("DatePickerButton", "DatePickerButton")); diff --git a/egui_demo_lib/src/apps/demo/window_options.rs b/egui_demo_lib/src/demo/window_options.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/window_options.rs rename to egui_demo_lib/src/demo/window_options.rs diff --git a/egui_demo_lib/src/apps/demo/window_with_panels.rs b/egui_demo_lib/src/demo/window_with_panels.rs similarity index 100% rename from egui_demo_lib/src/apps/demo/window_with_panels.rs rename to egui_demo_lib/src/demo/window_with_panels.rs diff --git a/egui_demo_lib/src/easy_mark/easy_mark_editor.rs b/egui_demo_lib/src/easy_mark/easy_mark_editor.rs index 63957f155..5355d9a06 100644 --- a/egui_demo_lib/src/easy_mark/easy_mark_editor.rs +++ b/egui_demo_lib/src/easy_mark/easy_mark_editor.rs @@ -29,8 +29,8 @@ impl Default for EasyMarkEditor { } } -impl epi::App for EasyMarkEditor { - fn update(&mut self, ctx: &egui::Context, _frame: &mut epi::Frame) { +impl EasyMarkEditor { + pub fn panels(&mut self, ctx: &egui::Context) { egui::TopBottomPanel::bottom("easy_mark_bottom").show(ctx, |ui| { let layout = egui::Layout::top_down(egui::Align::Center).with_main_justify(true); ui.allocate_ui_with_layout(ui.available_size(), layout, |ui| { @@ -42,10 +42,8 @@ impl epi::App for EasyMarkEditor { self.ui(ui); }); } -} -impl EasyMarkEditor { - fn ui(&mut self, ui: &mut egui::Ui) { + pub fn ui(&mut self, ui: &mut egui::Ui) { egui::Grid::new("controls").show(ui, |ui| { ui.checkbox(&mut self.highlight_editor, "Highlight editor"); egui::reset_button(ui, self); diff --git a/egui_demo_lib/src/lib.rs b/egui_demo_lib/src/lib.rs index 90f542eed..e1964533e 100644 --- a/egui_demo_lib/src/lib.rs +++ b/egui_demo_lib/src/lib.rs @@ -1,27 +1,27 @@ //! Demo-code for showing how egui is used. //! -//! The demo-code is also used in benchmarks and tests. +//! This library can be used to test 3rd party egui integrations (see for instance ). +//! +//! The demo is also used in benchmarks and tests. #![allow(clippy::float_cmp)] #![allow(clippy::manual_range_contains)] -mod apps; -mod backend_panel; +mod color_test; +mod demo; pub mod easy_mark; -pub(crate) mod frame_history; pub mod syntax_highlighting; -mod wrap_app; -pub use apps::ColorTest; // used for tests -pub use apps::DemoWindows; // used for tests -pub use wrap_app::WrapApp; +pub use color_test::ColorTest; +pub use demo::DemoWindows; // ---------------------------------------------------------------------------- -/// Create a [`Hyperlink`](crate::Hyperlink) to this egui source code file on github. +/// Create a [`Hyperlink`](egui::Hyperlink) to this egui source code file on github. +#[macro_export] macro_rules! egui_github_link_file { () => { - crate::egui_github_link_file!("(source code)") + $crate::egui_github_link_file!("(source code)") }; ($label: expr) => { egui::github_link_file!( @@ -30,12 +30,12 @@ macro_rules! egui_github_link_file { ) }; } -pub(crate) use egui_github_link_file; -/// Create a [`Hyperlink`](crate::Hyperlink) to this egui source code file and line on github. +/// Create a [`Hyperlink`](egui::Hyperlink) to this egui source code file and line on github. +#[macro_export] macro_rules! egui_github_link_file_line { () => { - crate::egui_github_link_file_line!("(source code)") + $crate::egui_github_link_file_line!("(source code)") }; ($label: expr) => { egui::github_link_file_line!( @@ -44,7 +44,6 @@ macro_rules! egui_github_link_file_line { ) }; } -pub(crate) use egui_github_link_file_line; // ---------------------------------------------------------------------------- @@ -93,19 +92,3 @@ fn test_egui_zero_window_size() { ); } } - -// ---------------------------------------------------------------------------- - -/// Time of day as seconds since midnight. Used for clock in demo app. -pub(crate) fn seconds_since_midnight() -> Option { - #[cfg(feature = "datetime")] - { - use chrono::Timelike; - let time = chrono::Local::now().time(); - let seconds_since_midnight = - time.num_seconds_from_midnight() as f64 + 1e-9 * (time.nanosecond() as f64); - Some(seconds_since_midnight) - } - #[cfg(not(feature = "datetime"))] - None -} diff --git a/egui_extras/CHANGELOG.md b/egui_extras/CHANGELOG.md index 11da8bab3..7abee68a9 100644 --- a/egui_extras/CHANGELOG.md +++ b/egui_extras/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to the `egui_extras` integration will be noted in this file. ## Unreleased * Added `Strip`, `Table` and `DatePicker` ([#963](https://github.com/emilk/egui/pull/963)). * MSRV (Minimum Supported Rust Version) is now `1.60.0` ([#1467](https://github.com/emilk/egui/pull/1467)). +* Renamed feature "persistence" to "serde" ([#1540](https://github.com/emilk/egui/pull/1540)). ## 0.17.0 - 2022-02-22 diff --git a/egui_extras/Cargo.toml b/egui_extras/Cargo.toml index c2b809c0c..fdbabc598 100644 --- a/egui_extras/Cargo.toml +++ b/egui_extras/Cargo.toml @@ -26,14 +26,13 @@ all-features = true [features] default = [] -# Support loading svg images -svg = ["resvg", "tiny-skia", "usvg"] - # Datepicker widget datepicker = ["chrono"] -# Persistence -persistence = ["serde"] +serde = ["dep:serde"] + +# Support loading svg images +svg = ["resvg", "tiny-skia", "usvg"] # Log warnings using `tracing` crate tracing = ["dep:tracing", "egui/tracing"] @@ -57,7 +56,7 @@ resvg = { version = "0.22", optional = true } tiny-skia = { version = "0.6", optional = true } usvg = { version = "0.22", optional = true } -# feature "persistence": +# feature "serde": serde = { version = "1", features = ["derive"], optional = true } # feature "tracing" diff --git a/egui_extras/src/datepicker/button.rs b/egui_extras/src/datepicker/button.rs index a017a850c..043b83fbf 100644 --- a/egui_extras/src/datepicker/button.rs +++ b/egui_extras/src/datepicker/button.rs @@ -3,7 +3,7 @@ use chrono::{Date, Utc}; use egui::{Area, Button, Frame, Key, Order, RichText, Ui, Widget}; #[derive(Default, Clone)] -#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub(crate) struct DatePickerButtonState { pub picker_visible: bool, } diff --git a/egui_extras/src/datepicker/popup.rs b/egui_extras/src/datepicker/popup.rs index 0a280100d..5b2141943 100644 --- a/egui_extras/src/datepicker/popup.rs +++ b/egui_extras/src/datepicker/popup.rs @@ -4,7 +4,7 @@ use chrono::{Date, Datelike, NaiveDate, Utc, Weekday}; use egui::{Align, Button, Color32, ComboBox, Direction, Id, Layout, RichText, Ui, Vec2}; #[derive(Default, Clone)] -#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] struct DatePickerPopupState { year: i32, month: u32,