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:
parent
c97c065a57
commit
9150b9342d
|
|
@ -387,7 +387,7 @@ pub type ImageLoadResult = Result<ImagePoll>;
|
||||||
/// An `ImageLoader` decodes raw bytes into a [`ColorImage`].
|
/// An `ImageLoader` decodes raw bytes into a [`ColorImage`].
|
||||||
///
|
///
|
||||||
/// Implementations are expected to cache at least each `URI`.
|
/// Implementations are expected to cache at least each `URI`.
|
||||||
pub trait ImageLoader {
|
pub trait ImageLoader: std::any::Any {
|
||||||
/// Unique ID of this loader.
|
/// Unique ID of this loader.
|
||||||
///
|
///
|
||||||
/// To reduce the chance of collisions, include `module_path!()` as part of this ID.
|
/// 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),
|
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>;
|
pub type TextureLoadResult = Result<TexturePoll>;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ pub mod syntax_highlighting;
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub mod image;
|
pub mod image;
|
||||||
mod layout;
|
mod layout;
|
||||||
mod loaders;
|
pub mod loaders;
|
||||||
mod sizing;
|
mod sizing;
|
||||||
mod strip;
|
mod strip;
|
||||||
mod table;
|
mod table;
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,9 @@ pub fn install_image_loaders(ctx: &egui::Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "http")]
|
#[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(
|
ctx.add_bytes_loader(std::sync::Arc::new(
|
||||||
self::ehttp_loader::EhttpLoader::default(),
|
self::http_loader::EhttpLoader::default(),
|
||||||
));
|
));
|
||||||
log::trace!("installed EhttpLoader");
|
log::trace!("installed EhttpLoader");
|
||||||
}
|
}
|
||||||
|
|
@ -108,16 +108,16 @@ pub fn install_image_loaders(ctx: &egui::Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod file_loader;
|
pub mod file_loader;
|
||||||
|
|
||||||
#[cfg(feature = "http")]
|
#[cfg(feature = "http")]
|
||||||
mod ehttp_loader;
|
pub mod http_loader;
|
||||||
|
|
||||||
#[cfg(feature = "gif")]
|
#[cfg(feature = "gif")]
|
||||||
mod gif_loader;
|
pub mod gif_loader;
|
||||||
#[cfg(feature = "image")]
|
#[cfg(feature = "image")]
|
||||||
mod image_loader;
|
pub mod image_loader;
|
||||||
#[cfg(feature = "svg")]
|
#[cfg(feature = "svg")]
|
||||||
mod svg_loader;
|
pub mod svg_loader;
|
||||||
#[cfg(feature = "webp")]
|
#[cfg(feature = "webp")]
|
||||||
mod webp_loader;
|
pub mod webp_loader;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue