`egui_kittest`: Add `HarnessBuilder::theme` (#7289)
Makes it ergonomic to snapshot test light vs dark mode
This commit is contained in:
parent
0857527f1d
commit
22c6a9ae69
|
|
@ -7,6 +7,7 @@ use std::marker::PhantomData;
|
||||||
pub struct HarnessBuilder<State = ()> {
|
pub struct HarnessBuilder<State = ()> {
|
||||||
pub(crate) screen_rect: Rect,
|
pub(crate) screen_rect: Rect,
|
||||||
pub(crate) pixels_per_point: f32,
|
pub(crate) pixels_per_point: f32,
|
||||||
|
pub(crate) theme: egui::Theme,
|
||||||
pub(crate) max_steps: u64,
|
pub(crate) max_steps: u64,
|
||||||
pub(crate) step_dt: f32,
|
pub(crate) step_dt: f32,
|
||||||
pub(crate) state: PhantomData<State>,
|
pub(crate) state: PhantomData<State>,
|
||||||
|
|
@ -19,6 +20,7 @@ impl<State> Default for HarnessBuilder<State> {
|
||||||
Self {
|
Self {
|
||||||
screen_rect: Rect::from_min_size(Pos2::ZERO, Vec2::new(800.0, 600.0)),
|
screen_rect: Rect::from_min_size(Pos2::ZERO, Vec2::new(800.0, 600.0)),
|
||||||
pixels_per_point: 1.0,
|
pixels_per_point: 1.0,
|
||||||
|
theme: egui::Theme::Dark,
|
||||||
state: PhantomData,
|
state: PhantomData,
|
||||||
renderer: Box::new(LazyRenderer::default()),
|
renderer: Box::new(LazyRenderer::default()),
|
||||||
max_steps: 4,
|
max_steps: 4,
|
||||||
|
|
@ -45,6 +47,13 @@ impl<State> HarnessBuilder<State> {
|
||||||
self
|
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`].
|
/// Set the maximum number of steps to run when calling [`Harness::run`].
|
||||||
///
|
///
|
||||||
/// Default is 4.
|
/// Default is 4.
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ impl<'a, State> Harness<'a, State> {
|
||||||
let HarnessBuilder {
|
let HarnessBuilder {
|
||||||
screen_rect,
|
screen_rect,
|
||||||
pixels_per_point,
|
pixels_per_point,
|
||||||
|
theme,
|
||||||
max_steps,
|
max_steps,
|
||||||
step_dt,
|
step_dt,
|
||||||
state: _,
|
state: _,
|
||||||
|
|
@ -93,6 +94,7 @@ impl<'a, State> Harness<'a, State> {
|
||||||
wait_for_pending_images,
|
wait_for_pending_images,
|
||||||
} = builder;
|
} = builder;
|
||||||
let ctx = ctx.unwrap_or_default();
|
let ctx = ctx.unwrap_or_default();
|
||||||
|
ctx.set_theme(theme);
|
||||||
ctx.enable_accesskit();
|
ctx.enable_accesskit();
|
||||||
// Disable cursor blinking so it doesn't interfere with snapshots
|
// Disable cursor blinking so it doesn't interfere with snapshots
|
||||||
ctx.all_styles_mut(|style| style.visuals.text_cursor.blink = false);
|
ctx.all_styles_mut(|style| style.visuals.text_cursor.blink = false);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue