1
0
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:
Lucas Meurer
2025-05-08 09:27:52 +02:00
committed by GitHub
parent 0fd6a805a4
commit 120d736cfc
10 changed files with 93 additions and 8 deletions

View File

@@ -3546,6 +3546,14 @@ impl Context {
pub fn loaders(&self) -> Arc<Loaders> {
self.read(|this| this.loaders.clone())
}
/// Returns `true` if any image is currently being loaded.
pub fn has_pending_images(&self) -> bool {
self.read(|this| {
this.loaders.image.lock().iter().any(|i| i.has_pending())
|| this.loaders.bytes.lock().iter().any(|i| i.has_pending())
})
}
}
/// ## Viewports

View File

@@ -328,6 +328,11 @@ pub trait BytesLoader {
/// If the loader caches any data, this should return the size of that cache.
fn byte_size(&self) -> usize;
/// Returns `true` if some data is currently being loaded.
fn has_pending(&self) -> bool {
false
}
}
/// Represents an image which is currently being loaded.
@@ -395,6 +400,13 @@ pub trait ImageLoader {
/// If the loader caches any data, this should return the size of that cache.
fn byte_size(&self) -> usize;
/// Returns `true` if some image is currently being loaded.
///
/// NOTE: You probably also want to check [`BytesLoader::has_pending`].
fn has_pending(&self) -> bool {
false
}
}
/// A texture with a known size.