mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 13:50:04 -04:00
Add ImageLoader::has_pending and wait_for_pending_images (#7030)
With kittest it was difficult to wait for images to be loaded before taking a snapshot test. This PR adds `Harness::with_wait_for_pending_images` (true by default) which will cause `Harness::run` to sleep until all images are loaded (or `HarnessBuilder::with_max_steps` is exceeded). It also adds a new ImageLoader::has_pending and BytesLoader::has_pending, which should be implemented if things are loaded / decoded asynchronously. It reverts https://github.com/emilk/egui/pull/6901 which was my previous attempt to fix this (but this didn't work since only the tested crate is compiled with cfg(test) and not it's dependencies)
This commit is contained in:
@@ -11,6 +11,7 @@ pub struct HarnessBuilder<State = ()> {
|
||||
pub(crate) step_dt: f32,
|
||||
pub(crate) state: PhantomData<State>,
|
||||
pub(crate) renderer: Box<dyn TestRenderer>,
|
||||
pub(crate) wait_for_pending_images: bool,
|
||||
}
|
||||
|
||||
impl<State> Default for HarnessBuilder<State> {
|
||||
@@ -22,6 +23,7 @@ impl<State> Default for HarnessBuilder<State> {
|
||||
renderer: Box::new(LazyRenderer::default()),
|
||||
max_steps: 4,
|
||||
step_dt: 1.0 / 4.0,
|
||||
wait_for_pending_images: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,6 +65,19 @@ impl<State> HarnessBuilder<State> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Should we wait for pending images?
|
||||
///
|
||||
/// If `true`, [`Harness::run`] and related methods will check if there are pending images
|
||||
/// (via [`egui::Context::has_pending_images`]) and sleep for [`Self::with_step_dt`] up to
|
||||
/// [`Self::with_max_steps`] times.
|
||||
///
|
||||
/// Default: `true`
|
||||
#[inline]
|
||||
pub fn with_wait_for_pending_images(mut self, wait_for_pending_images: bool) -> Self {
|
||||
self.wait_for_pending_images = wait_for_pending_images;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the [`TestRenderer`] to use for rendering.
|
||||
///
|
||||
/// By default, a [`LazyRenderer`] is used.
|
||||
|
||||
Reference in New Issue
Block a user