mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 12:50:04 -04:00
WIP: Debug tests with eframe
This commit is contained in:
@@ -1363,6 +1363,7 @@ version = "0.29.1"
|
||||
dependencies = [
|
||||
"dify",
|
||||
"document-features",
|
||||
"eframe",
|
||||
"egui",
|
||||
"egui-wgpu",
|
||||
"egui_kittest",
|
||||
|
||||
@@ -22,10 +22,15 @@ wgpu = ["dep:egui-wgpu", "dep:pollster", "dep:image"]
|
||||
# Adds a dify-based image snapshot utility.
|
||||
snapshot = ["dep:dify", "dep:image", "image/png"]
|
||||
|
||||
# Allows debugging tests via eframe.
|
||||
run_with_eframe = ["dep:eframe"]
|
||||
|
||||
default = ["eframe?/wgpu"]
|
||||
|
||||
[dependencies]
|
||||
kittest.workspace = true
|
||||
egui = { workspace = true, features = ["accesskit"] }
|
||||
eframe = { workspace = true, features = ["accesskit"], optional = true }
|
||||
|
||||
# wgpu dependencies
|
||||
egui-wgpu = { workspace = true, optional = true }
|
||||
|
||||
@@ -12,6 +12,8 @@ mod snapshot;
|
||||
pub use snapshot::*;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
mod app_kind;
|
||||
#[cfg(feature = "run_with_eframe")]
|
||||
mod run_with_eframe;
|
||||
#[cfg(feature = "wgpu")]
|
||||
mod texture_to_image;
|
||||
#[cfg(feature = "wgpu")]
|
||||
@@ -23,7 +25,7 @@ use std::mem;
|
||||
use crate::app_kind::AppKind;
|
||||
use crate::event::EventState;
|
||||
pub use builder::*;
|
||||
use egui::{Pos2, Rect, TexturesDelta, Vec2, ViewportId};
|
||||
use egui::{Pos2, Rect, TexturesDelta, Vec2, ViewportBuilder, ViewportId};
|
||||
use kittest::{Node, Queryable};
|
||||
|
||||
/// The test Harness. This contains everything needed to run the test.
|
||||
@@ -268,6 +270,19 @@ impl<'a, State> Harness<'a, State> {
|
||||
physical_key: None,
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(feature = "run_with_eframe")]
|
||||
pub fn run_with_eframe(&mut self) {
|
||||
let native_options = eframe::NativeOptions {
|
||||
viewport: ViewportBuilder::default().with_inner_size(self.ctx.screen_rect().size()),
|
||||
..Default::default()
|
||||
};
|
||||
eframe::run_native(
|
||||
"egui_debug",
|
||||
native_options,
|
||||
Box::new(|cc| Ok(Box::new(self))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Utilities for stateless harnesses.
|
||||
|
||||
13
crates/egui_kittest/src/run_with_eframe.rs
Normal file
13
crates/egui_kittest/src/run_with_eframe.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use crate::Harness;
|
||||
use eframe::Frame;
|
||||
use egui::Context;
|
||||
|
||||
impl<'a, State> eframe::App for &mut Harness<'a, State> {
|
||||
fn update(&mut self, ctx: &Context, frame: &mut Frame) {
|
||||
self.app.run(ctx, &mut self.state, false);
|
||||
}
|
||||
|
||||
fn persist_egui_memory(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
@@ -10,5 +10,7 @@ fn test_shrink() {
|
||||
|
||||
harness.fit_contents();
|
||||
|
||||
harness.run_with_eframe();
|
||||
|
||||
harness.wgpu_snapshot("test_shrink");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user