mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
Add tests for layout and visuals of most egui widgets (#6752)
This is mostly in preparation for #5830 where I want to ensure that I don't introduce any regressions
This commit is contained in:
@@ -274,6 +274,7 @@ impl<'a, State> Harness<'a, State> {
|
||||
///
|
||||
/// See also:
|
||||
/// - [`Harness::try_run`].
|
||||
/// - [`Harness::try_run_realtime`].
|
||||
/// - [`Harness::run_ok`].
|
||||
/// - [`Harness::step`].
|
||||
/// - [`Harness::run_steps`].
|
||||
@@ -287,6 +288,27 @@ impl<'a, State> Harness<'a, State> {
|
||||
}
|
||||
}
|
||||
|
||||
fn _try_run(&mut self, sleep: bool) -> Result<u64, ExceededMaxStepsError> {
|
||||
let mut steps = 0;
|
||||
loop {
|
||||
steps += 1;
|
||||
self.step();
|
||||
// We only care about immediate repaints
|
||||
if self.root_viewport_output().repaint_delay != Duration::ZERO {
|
||||
break;
|
||||
} else if sleep {
|
||||
std::thread::sleep(Duration::from_secs_f32(self.step_dt));
|
||||
}
|
||||
if steps > self.max_steps {
|
||||
return Err(ExceededMaxStepsError {
|
||||
max_steps: self.max_steps,
|
||||
repaint_causes: self.ctx.repaint_causes(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(steps)
|
||||
}
|
||||
|
||||
/// Run until
|
||||
/// - all animations are done
|
||||
/// - no more repaints are requested
|
||||
@@ -302,23 +324,9 @@ impl<'a, State> Harness<'a, State> {
|
||||
/// - [`Harness::run_ok`].
|
||||
/// - [`Harness::step`].
|
||||
/// - [`Harness::run_steps`].
|
||||
/// - [`Harness::try_run_realtime`].
|
||||
pub fn try_run(&mut self) -> Result<u64, ExceededMaxStepsError> {
|
||||
let mut steps = 0;
|
||||
loop {
|
||||
steps += 1;
|
||||
self.step();
|
||||
// We only care about immediate repaints
|
||||
if self.root_viewport_output().repaint_delay != Duration::ZERO {
|
||||
break;
|
||||
}
|
||||
if steps > self.max_steps {
|
||||
return Err(ExceededMaxStepsError {
|
||||
max_steps: self.max_steps,
|
||||
repaint_causes: self.ctx.repaint_causes(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(steps)
|
||||
self._try_run(false)
|
||||
}
|
||||
|
||||
/// Run until
|
||||
@@ -333,10 +341,34 @@ impl<'a, State> Harness<'a, State> {
|
||||
/// - [`Harness::try_run`].
|
||||
/// - [`Harness::step`].
|
||||
/// - [`Harness::run_steps`].
|
||||
/// - [`Harness::try_run_realtime`].
|
||||
pub fn run_ok(&mut self) -> Option<u64> {
|
||||
self.try_run().ok()
|
||||
}
|
||||
|
||||
/// Run multiple frames, sleeping for [`HarnessBuilder::with_step_dt`] between frames.
|
||||
///
|
||||
/// This is useful to e.g. wait for an async operation to complete (e.g. loading of images).
|
||||
/// Runs until
|
||||
/// - all animations are done
|
||||
/// - no more repaints are requested
|
||||
/// - the maximum number of steps is reached (See [`HarnessBuilder::with_max_steps`])
|
||||
///
|
||||
/// Returns the number of steps that were run.
|
||||
///
|
||||
/// # Errors
|
||||
/// Returns an error if the maximum number of steps is exceeded.
|
||||
///
|
||||
/// See also:
|
||||
/// - [`Harness::run`].
|
||||
/// - [`Harness::run_ok`].
|
||||
/// - [`Harness::step`].
|
||||
/// - [`Harness::run_steps`].
|
||||
/// - [`Harness::try_run`].
|
||||
pub fn try_run_realtime(&mut self) -> Result<u64, ExceededMaxStepsError> {
|
||||
self._try_run(true)
|
||||
}
|
||||
|
||||
/// Run a number of steps.
|
||||
/// Equivalent to calling [`Harness::step`] x times.
|
||||
pub fn run_steps(&mut self, steps: usize) {
|
||||
|
||||
Reference in New Issue
Block a user