`egui_kittest`: Add `HarnessBuilder::theme` (#7289)

Makes it ergonomic to snapshot test light vs dark mode
This commit is contained in:
Emil Ernerfeldt 2025-07-02 12:00:22 +02:00 committed by GitHub
parent 0857527f1d
commit 22c6a9ae69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View File

@ -7,6 +7,7 @@ use std::marker::PhantomData;
pub struct HarnessBuilder<State = ()> {
pub(crate) screen_rect: Rect,
pub(crate) pixels_per_point: f32,
pub(crate) theme: egui::Theme,
pub(crate) max_steps: u64,
pub(crate) step_dt: f32,
pub(crate) state: PhantomData<State>,
@ -19,6 +20,7 @@ impl<State> Default for HarnessBuilder<State> {
Self {
screen_rect: Rect::from_min_size(Pos2::ZERO, Vec2::new(800.0, 600.0)),
pixels_per_point: 1.0,
theme: egui::Theme::Dark,
state: PhantomData,
renderer: Box::new(LazyRenderer::default()),
max_steps: 4,
@ -45,6 +47,13 @@ impl<State> HarnessBuilder<State> {
self
}
/// Set the desired theme (dark or light).
#[inline]
pub fn with_theme(mut self, theme: egui::Theme) -> Self {
self.theme = theme;
self
}
/// Set the maximum number of steps to run when calling [`Harness::run`].
///
/// Default is 4.

View File

@ -86,6 +86,7 @@ impl<'a, State> Harness<'a, State> {
let HarnessBuilder {
screen_rect,
pixels_per_point,
theme,
max_steps,
step_dt,
state: _,
@ -93,6 +94,7 @@ impl<'a, State> Harness<'a, State> {
wait_for_pending_images,
} = builder;
let ctx = ctx.unwrap_or_default();
ctx.set_theme(theme);
ctx.enable_accesskit();
// Disable cursor blinking so it doesn't interfere with snapshots
ctx.all_styles_mut(|style| style.visuals.text_cursor.blink = false);