From 3e0bedd96d1a9f0dafe37db7440ef7a4cab7716a Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 2 Jan 2021 00:13:34 +0100 Subject: [PATCH] [demo] Move color test to WrapApp --- egui_demo_lib/benches/benchmark.rs | 6 ++-- .../src/apps/{demo => }/color_test.rs | 23 ++++++++++++ egui_demo_lib/src/apps/demo/app.rs | 4 +-- egui_demo_lib/src/apps/demo/demo_windows.rs | 35 ++----------------- egui_demo_lib/src/apps/demo/mod.rs | 7 ++-- egui_demo_lib/src/apps/http_app.rs | 2 +- egui_demo_lib/src/apps/mod.rs | 2 ++ egui_demo_lib/src/lib.rs | 2 +- egui_demo_lib/src/wrap_app.rs | 2 ++ 9 files changed, 40 insertions(+), 43 deletions(-) rename egui_demo_lib/src/apps/{demo => }/color_test.rs (95%) diff --git a/egui_demo_lib/benches/benchmark.rs b/egui_demo_lib/benches/benchmark.rs index f2d0959d..a00cec18 100644 --- a/egui_demo_lib/benches/benchmark.rs +++ b/egui_demo_lib/benches/benchmark.rs @@ -10,7 +10,7 @@ pub fn criterion_benchmark(c: &mut Criterion) { c.bench_function("demo_windows_minimal", |b| { b.iter(|| { ctx.begin_frame(raw_input.clone()); - demo_windows.ui(&ctx, &mut None, |_ui| {}); + demo_windows.ui(&ctx, |_ui| {}); ctx.end_frame() }) }); @@ -24,7 +24,7 @@ pub fn criterion_benchmark(c: &mut Criterion) { c.bench_function("demo_windows_full", |b| { b.iter(|| { ctx.begin_frame(raw_input.clone()); - demo_windows.ui(&ctx, &mut None, |_ui| {}); + demo_windows.ui(&ctx, |_ui| {}); ctx.end_frame() }) }); @@ -35,7 +35,7 @@ pub fn criterion_benchmark(c: &mut Criterion) { ctx.memory().all_collpasing_are_open = true; // expand the demo window with everything let mut demo_windows = egui_demo_lib::DemoWindows::default(); ctx.begin_frame(raw_input.clone()); - demo_windows.ui(&ctx, &mut None, |_ui| {}); + demo_windows.ui(&ctx, |_ui| {}); let (_, paint_commands) = ctx.end_frame(); c.bench_function("tessellate", |b| { diff --git a/egui_demo_lib/src/apps/demo/color_test.rs b/egui_demo_lib/src/apps/color_test.rs similarity index 95% rename from egui_demo_lib/src/apps/demo/color_test.rs rename to egui_demo_lib/src/apps/color_test.rs index c7dde4d8..c30086ff 100644 --- a/egui_demo_lib/src/apps/demo/color_test.rs +++ b/egui_demo_lib/src/apps/color_test.rs @@ -3,7 +3,9 @@ use std::collections::HashMap; const GRADIENT_SIZE: Vec2 = vec2(256.0, 24.0); +#[derive(serde::Deserialize, serde::Serialize)] pub struct ColorTest { + #[serde(skip)] tex_mngr: TextureManager, vertex_gradients: bool, texture_gradients: bool, @@ -21,6 +23,27 @@ impl Default for ColorTest { } } +impl epi::App for ColorTest { + fn name(&self) -> &str { + "🎨 Color test" + } + + fn update(&mut self, ctx: &egui::CtxRef, frame: &mut epi::Frame<'_>) { + egui::CentralPanel::default().show(ctx, |ui| { + if frame.is_web() { + ui.colored_label( + egui::color::RED, + "NOTE: The current WebGL backend does NOT pass the color test!", + ); + ui.separator(); + } + ScrollArea::auto_sized().show(ui, |ui| { + self.ui(ui, frame.tex_allocator()); + }); + }); + } +} + impl ColorTest { pub fn ui( &mut self, diff --git a/egui_demo_lib/src/apps/demo/app.rs b/egui_demo_lib/src/apps/demo/app.rs index ade75e69..10dd55db 100644 --- a/egui_demo_lib/src/apps/demo/app.rs +++ b/egui_demo_lib/src/apps/demo/app.rs @@ -282,7 +282,7 @@ impl DemoApp { impl epi::App for DemoApp { fn name(&self) -> &str { - "Egui Demo" + "✨ Egui Demo" } fn load(&mut self, storage: &dyn epi::Storage) { @@ -305,7 +305,7 @@ impl epi::App for DemoApp { .. } = self; - demo_windows.ui(ctx, frame.tex_allocator(), |ui| { + demo_windows.ui(ctx, |ui| { ui.separator(); ui.checkbox(backend_window_open, "💻 Backend"); diff --git a/egui_demo_lib/src/apps/demo/demo_windows.rs b/egui_demo_lib/src/apps/demo/demo_windows.rs index d463de35..4ec216d3 100644 --- a/egui_demo_lib/src/apps/demo/demo_windows.rs +++ b/egui_demo_lib/src/apps/demo/demo_windows.rs @@ -46,9 +46,6 @@ pub struct DemoWindows { demo_window: super::DemoWindow, - #[serde(skip)] - color_test: super::ColorTest, - /// open, title, view demos: Demos, } @@ -56,12 +53,7 @@ pub struct DemoWindows { impl DemoWindows { /// Show the app ui (menu bar and windows). /// `sidebar_ui` can be used to optionally show some things in the sidebar - pub fn ui( - &mut self, - ctx: &CtxRef, - tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>, - sidebar_ui: impl FnOnce(&mut Ui), - ) { + pub fn ui(&mut self, ctx: &CtxRef, sidebar_ui: impl FnOnce(&mut Ui)) { egui::SidePanel::left("side_panel", 190.0).show(ctx, |ui| { ui.heading("✒ Egui Demo"); @@ -97,19 +89,14 @@ impl DemoWindows { show_menu_bar(ui); }); - self.windows(ctx, tex_allocator); + self.windows(ctx); } /// Show the open windows. - fn windows( - &mut self, - ctx: &CtxRef, - tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>, - ) { + fn windows(&mut self, ctx: &CtxRef) { let Self { open_windows, demo_window, - color_test, demos, .. } = self; @@ -141,14 +128,6 @@ impl DemoWindows { ctx.memory_ui(ui); }); - Window::new("🎨 Color Test") - .default_size([800.0, 1024.0]) - .scroll(true) - .open(&mut open_windows.color_test) - .show(ctx, |ui| { - color_test.ui(ui, tex_allocator); - }); - demos.show(ctx); self.resize_windows(ctx); @@ -219,9 +198,6 @@ struct OpenWindows { inspection: bool, memory: bool, resize: bool, - - // debug stuff: - color_test: bool, } impl Default for OpenWindows { @@ -242,8 +218,6 @@ impl OpenWindows { inspection: false, memory: false, resize: false, - - color_test: false, } } @@ -254,7 +228,6 @@ impl OpenWindows { inspection, memory, resize, - color_test, } = self; ui.label("Egui:"); ui.checkbox(settings, "🔧 Settings"); @@ -264,8 +237,6 @@ impl OpenWindows { ui.checkbox(demo, "✨ Demo"); ui.separator(); ui.checkbox(resize, "↔ Resize examples"); - ui.checkbox(color_test, "🎨 Color test") - .on_hover_text("For testing the integrations painter"); ui.separator(); ui.label("Misc:"); } diff --git a/egui_demo_lib/src/apps/demo/mod.rs b/egui_demo_lib/src/apps/demo/mod.rs index 9298aa42..4045a3d0 100644 --- a/egui_demo_lib/src/apps/demo/mod.rs +++ b/egui_demo_lib/src/apps/demo/mod.rs @@ -5,7 +5,6 @@ // ---------------------------------------------------------------------------- mod app; -mod color_test; mod dancing_strings; pub mod demo_window; mod demo_windows; @@ -21,9 +20,9 @@ pub mod toggle_switch; mod widgets; pub use { - app::*, color_test::ColorTest, dancing_strings::DancingStrings, demo_window::DemoWindow, - demo_windows::*, drag_and_drop::*, font_book::FontBook, painting::Painting, scrolls::Scrolls, - sliders::Sliders, tests::Tests, widgets::Widgets, + app::*, dancing_strings::DancingStrings, demo_window::DemoWindow, demo_windows::*, + drag_and_drop::*, font_book::FontBook, painting::Painting, scrolls::Scrolls, sliders::Sliders, + tests::Tests, widgets::Widgets, }; // ---------------------------------------------------------------------------- diff --git a/egui_demo_lib/src/apps/http_app.rs b/egui_demo_lib/src/apps/http_app.rs index 3a67afa6..4feea806 100644 --- a/egui_demo_lib/src/apps/http_app.rs +++ b/egui_demo_lib/src/apps/http_app.rs @@ -57,7 +57,7 @@ impl Default for HttpApp { impl epi::App for HttpApp { fn name(&self) -> &str { - "HTTP Fetch" + "⬇ HTTP" } /// Called each time the UI needs repainting, which may be many times per second. diff --git a/egui_demo_lib/src/apps/mod.rs b/egui_demo_lib/src/apps/mod.rs index 6be76f95..15abcf05 100644 --- a/egui_demo_lib/src/apps/mod.rs +++ b/egui_demo_lib/src/apps/mod.rs @@ -1,7 +1,9 @@ +mod color_test; mod demo; mod fractal_clock; mod http_app; +pub use color_test::ColorTest; pub use demo::DemoApp; pub use fractal_clock::FractalClock; pub use http_app::HttpApp; diff --git a/egui_demo_lib/src/lib.rs b/egui_demo_lib/src/lib.rs index ea018ee3..10dc2fbe 100644 --- a/egui_demo_lib/src/lib.rs +++ b/egui_demo_lib/src/lib.rs @@ -96,7 +96,7 @@ fn test_egui_e2e() { const NUM_FRAMES: usize = 5; for _ in 0..NUM_FRAMES { ctx.begin_frame(raw_input.clone()); - demo_windows.ui(&ctx, &mut None, |_ui| {}); + demo_windows.ui(&ctx, |_ui| {}); let (_output, paint_commands) = ctx.end_frame(); let paint_jobs = ctx.tessellate(paint_commands); assert!(!paint_jobs.is_empty()); diff --git a/egui_demo_lib/src/wrap_app.rs b/egui_demo_lib/src/wrap_app.rs index fb4d216c..322af2d0 100644 --- a/egui_demo_lib/src/wrap_app.rs +++ b/egui_demo_lib/src/wrap_app.rs @@ -12,6 +12,7 @@ pub struct Apps { demo: crate::apps::DemoApp, http: crate::apps::HttpApp, clock: crate::apps::FractalClock, + color_test: crate::apps::ColorTest, } impl Apps { @@ -20,6 +21,7 @@ impl Apps { ("demo", &mut self.demo as &mut dyn epi::App), ("http", &mut self.http as &mut dyn epi::App), ("clock", &mut self.clock as &mut dyn epi::App), + ("colors", &mut self.color_test as &mut dyn epi::App), ] .into_iter() }