[demo] Move color test to WrapApp
This commit is contained in:
parent
4848c171eb
commit
3e0bedd96d
9 changed files with 40 additions and 43 deletions
|
@ -10,7 +10,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||||
c.bench_function("demo_windows_minimal", |b| {
|
c.bench_function("demo_windows_minimal", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
ctx.begin_frame(raw_input.clone());
|
ctx.begin_frame(raw_input.clone());
|
||||||
demo_windows.ui(&ctx, &mut None, |_ui| {});
|
demo_windows.ui(&ctx, |_ui| {});
|
||||||
ctx.end_frame()
|
ctx.end_frame()
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -24,7 +24,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||||
c.bench_function("demo_windows_full", |b| {
|
c.bench_function("demo_windows_full", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
ctx.begin_frame(raw_input.clone());
|
ctx.begin_frame(raw_input.clone());
|
||||||
demo_windows.ui(&ctx, &mut None, |_ui| {});
|
demo_windows.ui(&ctx, |_ui| {});
|
||||||
ctx.end_frame()
|
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
|
ctx.memory().all_collpasing_are_open = true; // expand the demo window with everything
|
||||||
let mut demo_windows = egui_demo_lib::DemoWindows::default();
|
let mut demo_windows = egui_demo_lib::DemoWindows::default();
|
||||||
ctx.begin_frame(raw_input.clone());
|
ctx.begin_frame(raw_input.clone());
|
||||||
demo_windows.ui(&ctx, &mut None, |_ui| {});
|
demo_windows.ui(&ctx, |_ui| {});
|
||||||
let (_, paint_commands) = ctx.end_frame();
|
let (_, paint_commands) = ctx.end_frame();
|
||||||
|
|
||||||
c.bench_function("tessellate", |b| {
|
c.bench_function("tessellate", |b| {
|
||||||
|
|
|
@ -3,7 +3,9 @@ use std::collections::HashMap;
|
||||||
|
|
||||||
const GRADIENT_SIZE: Vec2 = vec2(256.0, 24.0);
|
const GRADIENT_SIZE: Vec2 = vec2(256.0, 24.0);
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
pub struct ColorTest {
|
pub struct ColorTest {
|
||||||
|
#[serde(skip)]
|
||||||
tex_mngr: TextureManager,
|
tex_mngr: TextureManager,
|
||||||
vertex_gradients: bool,
|
vertex_gradients: bool,
|
||||||
texture_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 {
|
impl ColorTest {
|
||||||
pub fn ui(
|
pub fn ui(
|
||||||
&mut self,
|
&mut self,
|
|
@ -282,7 +282,7 @@ impl DemoApp {
|
||||||
|
|
||||||
impl epi::App for DemoApp {
|
impl epi::App for DemoApp {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"Egui Demo"
|
"✨ Egui Demo"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load(&mut self, storage: &dyn epi::Storage) {
|
fn load(&mut self, storage: &dyn epi::Storage) {
|
||||||
|
@ -305,7 +305,7 @@ impl epi::App for DemoApp {
|
||||||
..
|
..
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
demo_windows.ui(ctx, frame.tex_allocator(), |ui| {
|
demo_windows.ui(ctx, |ui| {
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.checkbox(backend_window_open, "💻 Backend");
|
ui.checkbox(backend_window_open, "💻 Backend");
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,6 @@ pub struct DemoWindows {
|
||||||
|
|
||||||
demo_window: super::DemoWindow,
|
demo_window: super::DemoWindow,
|
||||||
|
|
||||||
#[serde(skip)]
|
|
||||||
color_test: super::ColorTest,
|
|
||||||
|
|
||||||
/// open, title, view
|
/// open, title, view
|
||||||
demos: Demos,
|
demos: Demos,
|
||||||
}
|
}
|
||||||
|
@ -56,12 +53,7 @@ pub struct DemoWindows {
|
||||||
impl DemoWindows {
|
impl DemoWindows {
|
||||||
/// Show the app ui (menu bar and windows).
|
/// Show the app ui (menu bar and windows).
|
||||||
/// `sidebar_ui` can be used to optionally show some things in the sidebar
|
/// `sidebar_ui` can be used to optionally show some things in the sidebar
|
||||||
pub fn ui(
|
pub fn ui(&mut self, ctx: &CtxRef, sidebar_ui: impl FnOnce(&mut Ui)) {
|
||||||
&mut self,
|
|
||||||
ctx: &CtxRef,
|
|
||||||
tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>,
|
|
||||||
sidebar_ui: impl FnOnce(&mut Ui),
|
|
||||||
) {
|
|
||||||
egui::SidePanel::left("side_panel", 190.0).show(ctx, |ui| {
|
egui::SidePanel::left("side_panel", 190.0).show(ctx, |ui| {
|
||||||
ui.heading("✒ Egui Demo");
|
ui.heading("✒ Egui Demo");
|
||||||
|
|
||||||
|
@ -97,19 +89,14 @@ impl DemoWindows {
|
||||||
show_menu_bar(ui);
|
show_menu_bar(ui);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.windows(ctx, tex_allocator);
|
self.windows(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show the open windows.
|
/// Show the open windows.
|
||||||
fn windows(
|
fn windows(&mut self, ctx: &CtxRef) {
|
||||||
&mut self,
|
|
||||||
ctx: &CtxRef,
|
|
||||||
tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>,
|
|
||||||
) {
|
|
||||||
let Self {
|
let Self {
|
||||||
open_windows,
|
open_windows,
|
||||||
demo_window,
|
demo_window,
|
||||||
color_test,
|
|
||||||
demos,
|
demos,
|
||||||
..
|
..
|
||||||
} = self;
|
} = self;
|
||||||
|
@ -141,14 +128,6 @@ impl DemoWindows {
|
||||||
ctx.memory_ui(ui);
|
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);
|
demos.show(ctx);
|
||||||
|
|
||||||
self.resize_windows(ctx);
|
self.resize_windows(ctx);
|
||||||
|
@ -219,9 +198,6 @@ struct OpenWindows {
|
||||||
inspection: bool,
|
inspection: bool,
|
||||||
memory: bool,
|
memory: bool,
|
||||||
resize: bool,
|
resize: bool,
|
||||||
|
|
||||||
// debug stuff:
|
|
||||||
color_test: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for OpenWindows {
|
impl Default for OpenWindows {
|
||||||
|
@ -242,8 +218,6 @@ impl OpenWindows {
|
||||||
inspection: false,
|
inspection: false,
|
||||||
memory: false,
|
memory: false,
|
||||||
resize: false,
|
resize: false,
|
||||||
|
|
||||||
color_test: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +228,6 @@ impl OpenWindows {
|
||||||
inspection,
|
inspection,
|
||||||
memory,
|
memory,
|
||||||
resize,
|
resize,
|
||||||
color_test,
|
|
||||||
} = self;
|
} = self;
|
||||||
ui.label("Egui:");
|
ui.label("Egui:");
|
||||||
ui.checkbox(settings, "🔧 Settings");
|
ui.checkbox(settings, "🔧 Settings");
|
||||||
|
@ -264,8 +237,6 @@ impl OpenWindows {
|
||||||
ui.checkbox(demo, "✨ Demo");
|
ui.checkbox(demo, "✨ Demo");
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.checkbox(resize, "↔ Resize examples");
|
ui.checkbox(resize, "↔ Resize examples");
|
||||||
ui.checkbox(color_test, "🎨 Color test")
|
|
||||||
.on_hover_text("For testing the integrations painter");
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.label("Misc:");
|
ui.label("Misc:");
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
mod color_test;
|
|
||||||
mod dancing_strings;
|
mod dancing_strings;
|
||||||
pub mod demo_window;
|
pub mod demo_window;
|
||||||
mod demo_windows;
|
mod demo_windows;
|
||||||
|
@ -21,9 +20,9 @@ pub mod toggle_switch;
|
||||||
mod widgets;
|
mod widgets;
|
||||||
|
|
||||||
pub use {
|
pub use {
|
||||||
app::*, color_test::ColorTest, dancing_strings::DancingStrings, demo_window::DemoWindow,
|
app::*, dancing_strings::DancingStrings, demo_window::DemoWindow, demo_windows::*,
|
||||||
demo_windows::*, drag_and_drop::*, font_book::FontBook, painting::Painting, scrolls::Scrolls,
|
drag_and_drop::*, font_book::FontBook, painting::Painting, scrolls::Scrolls, sliders::Sliders,
|
||||||
sliders::Sliders, tests::Tests, widgets::Widgets,
|
tests::Tests, widgets::Widgets,
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl Default for HttpApp {
|
||||||
|
|
||||||
impl epi::App for HttpApp {
|
impl epi::App for HttpApp {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"HTTP Fetch"
|
"⬇ HTTP"
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called each time the UI needs repainting, which may be many times per second.
|
/// Called each time the UI needs repainting, which may be many times per second.
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
mod color_test;
|
||||||
mod demo;
|
mod demo;
|
||||||
mod fractal_clock;
|
mod fractal_clock;
|
||||||
mod http_app;
|
mod http_app;
|
||||||
|
|
||||||
|
pub use color_test::ColorTest;
|
||||||
pub use demo::DemoApp;
|
pub use demo::DemoApp;
|
||||||
pub use fractal_clock::FractalClock;
|
pub use fractal_clock::FractalClock;
|
||||||
pub use http_app::HttpApp;
|
pub use http_app::HttpApp;
|
||||||
|
|
|
@ -96,7 +96,7 @@ fn test_egui_e2e() {
|
||||||
const NUM_FRAMES: usize = 5;
|
const NUM_FRAMES: usize = 5;
|
||||||
for _ in 0..NUM_FRAMES {
|
for _ in 0..NUM_FRAMES {
|
||||||
ctx.begin_frame(raw_input.clone());
|
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 (_output, paint_commands) = ctx.end_frame();
|
||||||
let paint_jobs = ctx.tessellate(paint_commands);
|
let paint_jobs = ctx.tessellate(paint_commands);
|
||||||
assert!(!paint_jobs.is_empty());
|
assert!(!paint_jobs.is_empty());
|
||||||
|
|
|
@ -12,6 +12,7 @@ pub struct Apps {
|
||||||
demo: crate::apps::DemoApp,
|
demo: crate::apps::DemoApp,
|
||||||
http: crate::apps::HttpApp,
|
http: crate::apps::HttpApp,
|
||||||
clock: crate::apps::FractalClock,
|
clock: crate::apps::FractalClock,
|
||||||
|
color_test: crate::apps::ColorTest,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Apps {
|
impl Apps {
|
||||||
|
@ -20,6 +21,7 @@ impl Apps {
|
||||||
("demo", &mut self.demo as &mut dyn epi::App),
|
("demo", &mut self.demo as &mut dyn epi::App),
|
||||||
("http", &mut self.http as &mut dyn epi::App),
|
("http", &mut self.http as &mut dyn epi::App),
|
||||||
("clock", &mut self.clock 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()
|
.into_iter()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue