Make individual egui_extras image loaders public (#7551)

This was initially a PR to add kitdiff, but this now lives in it's own
crate: https://github.com/rerun-io/kitdiff

I needed to make the image loaders public, this way it's possible to
compose image loaders together (which allowed me to create a image diff
loader that uses two other image loaders). But you can't use the
`ctx.try_load_image` since that would deadlock, so you have to store a
reference to the other loader in the wrapping loader.
This commit is contained in:
Lucas Meurer 2025-09-23 10:07:18 +02:00 committed by GitHub
parent c97c065a57
commit 9150b9342d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 10 deletions

View File

@ -387,7 +387,7 @@ pub type ImageLoadResult = Result<ImagePoll>;
/// An `ImageLoader` decodes raw bytes into a [`ColorImage`].
///
/// Implementations are expected to cache at least each `URI`.
pub trait ImageLoader {
pub trait ImageLoader: std::any::Any {
/// Unique ID of this loader.
///
/// To reduce the chance of collisions, include `module_path!()` as part of this ID.
@ -517,6 +517,16 @@ impl TexturePoll {
Self::Ready { texture } => Some(texture.id),
}
}
#[inline]
pub fn is_pending(&self) -> bool {
matches!(self, Self::Pending { .. })
}
#[inline]
pub fn is_ready(&self) -> bool {
matches!(self, Self::Ready { .. })
}
}
pub type TextureLoadResult = Result<TexturePoll>;

View File

@ -17,7 +17,7 @@ pub mod syntax_highlighting;
#[doc(hidden)]
pub mod image;
mod layout;
mod loaders;
pub mod loaders;
mod sizing;
mod strip;
mod table;

View File

@ -63,9 +63,9 @@ pub fn install_image_loaders(ctx: &egui::Context) {
}
#[cfg(feature = "http")]
if !ctx.is_loader_installed(self::ehttp_loader::EhttpLoader::ID) {
if !ctx.is_loader_installed(self::http_loader::EhttpLoader::ID) {
ctx.add_bytes_loader(std::sync::Arc::new(
self::ehttp_loader::EhttpLoader::default(),
self::http_loader::EhttpLoader::default(),
));
log::trace!("installed EhttpLoader");
}
@ -108,16 +108,16 @@ pub fn install_image_loaders(ctx: &egui::Context) {
}
#[cfg(not(target_arch = "wasm32"))]
mod file_loader;
pub mod file_loader;
#[cfg(feature = "http")]
mod ehttp_loader;
pub mod http_loader;
#[cfg(feature = "gif")]
mod gif_loader;
pub mod gif_loader;
#[cfg(feature = "image")]
mod image_loader;
pub mod image_loader;
#[cfg(feature = "svg")]
mod svg_loader;
pub mod svg_loader;
#[cfg(feature = "webp")]
mod webp_loader;
pub mod webp_loader;