diff --git a/crates/egui_kittest/src/builder.rs b/crates/egui_kittest/src/builder.rs index 021019a8..75ebd54b 100644 --- a/crates/egui_kittest/src/builder.rs +++ b/crates/egui_kittest/src/builder.rs @@ -8,6 +8,7 @@ pub struct HarnessBuilder { pub(crate) screen_rect: Rect, pub(crate) pixels_per_point: f32, pub(crate) theme: egui::Theme, + pub(crate) os: egui::os::OperatingSystem, pub(crate) max_steps: u64, pub(crate) step_dt: f32, pub(crate) state: PhantomData, @@ -26,6 +27,7 @@ impl Default for HarnessBuilder { max_steps: 4, step_dt: 1.0 / 4.0, wait_for_pending_images: true, + os: egui::os::OperatingSystem::Nix, } } } @@ -54,6 +56,21 @@ impl HarnessBuilder { self } + /// Override the [`egui::os::OperatingSystem`] reported to egui. + /// + /// This affects e.g. the way shortcuts are displayed. So for snapshot tests, + /// it makes sense to set this to a specific OS, so snapshots don't change when running + /// the same tests on different OSes. + /// + /// Default is [`egui::os::OperatingSystem::Nix`]. + /// Use [`egui::os::OperatingSystem::from_target_os()`] to use the current OS (this restores + /// eguis default behavior). + #[inline] + pub fn with_os(mut self, os: egui::os::OperatingSystem) -> Self { + self.os = os; + self + } + /// Set the maximum number of steps to run when calling [`Harness::run`]. /// /// Default is 4. diff --git a/crates/egui_kittest/src/lib.rs b/crates/egui_kittest/src/lib.rs index ae4d42f4..0f99da17 100644 --- a/crates/egui_kittest/src/lib.rs +++ b/crates/egui_kittest/src/lib.rs @@ -93,6 +93,7 @@ impl<'a, State> Harness<'a, State> { screen_rect, pixels_per_point, theme, + os, max_steps, step_dt, state: _, @@ -101,6 +102,7 @@ impl<'a, State> Harness<'a, State> { } = builder; let ctx = ctx.unwrap_or_default(); ctx.set_theme(theme); + ctx.set_os(os); ctx.enable_accesskit(); ctx.all_styles_mut(|style| { // Disable cursor blinking so it doesn't interfere with snapshots