mirror of
https://github.com/emilk/egui.git
synced 2026-09-03 23:30:04 -04:00
Change Harness::run to run until no more repaints are requested (#5580)
Previously, `Harness::run` just called `Harness::step` 3 times. If that wasn't enough, tests would often call run multiple times so all animations would finish properly. Also, I introduced `HarnessBuilder::with_step_dt` to customize with how big of a dt each frame is called. I set the default to 1.0 / 6.0 (~6fps) so we don't waste cpu in tests waiting on animations. `HarnessBuilder::max_steps` allows us to control how many steps `Harness::run` should run before panicing. The default is 6, so we run for up to 1.0 logical seconds (six frames at 6 fps), which should be enough to finish most animations. Turns out a lot of snapshots where rendered before fully shown and had a light opacity, those are now fixed. * [x] I have followed the instructions in the PR template
This commit is contained in:
@@ -8,6 +8,8 @@ use std::marker::PhantomData;
|
||||
pub struct HarnessBuilder<State = ()> {
|
||||
pub(crate) screen_rect: Rect,
|
||||
pub(crate) pixels_per_point: f32,
|
||||
pub(crate) max_steps: u64,
|
||||
pub(crate) step_dt: f32,
|
||||
pub(crate) state: PhantomData<State>,
|
||||
pub(crate) renderer: Box<dyn TestRenderer>,
|
||||
}
|
||||
@@ -19,6 +21,8 @@ impl<State> Default for HarnessBuilder<State> {
|
||||
pixels_per_point: 1.0,
|
||||
state: PhantomData,
|
||||
renderer: Box::new(LazyRenderer::default()),
|
||||
max_steps: 4,
|
||||
step_dt: 1.0 / 4.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +44,26 @@ impl<State> HarnessBuilder<State> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the maximum number of steps to run when calling [`Harness::run`].
|
||||
///
|
||||
/// Default is 4.
|
||||
/// With the default `step_dt`, this means 1 second of simulation.
|
||||
#[inline]
|
||||
pub fn with_max_steps(mut self, max_steps: u64) -> Self {
|
||||
self.max_steps = max_steps;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the time delta for a single [`Harness::step`].
|
||||
///
|
||||
/// Default is 1.0 / 4.0 (4fps).
|
||||
/// The default is low so we don't waste cpu waiting for animations.
|
||||
#[inline]
|
||||
pub fn with_step_dt(mut self, step_dt: f32) -> Self {
|
||||
self.step_dt = step_dt;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the [`TestRenderer`] to use for rendering.
|
||||
///
|
||||
/// By default, a [`LazyRenderer`] is used.
|
||||
|
||||
Reference in New Issue
Block a user