From ad597a849135571448037811c3a80800b5d3318c Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:20:20 +0900 Subject: [PATCH] Add `Image::uri()` (#4720) `uri()` for image The advantages of this are : 1. No need for `ctx()` and `source()` 2. Displays `name.gif#0` as `name.gif` --- crates/egui/src/widgets/image.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/egui/src/widgets/image.rs b/crates/egui/src/widgets/image.rs index 7783f02fed9..ab2a10bd6ad 100644 --- a/crates/egui/src/widgets/image.rs +++ b/crates/egui/src/widgets/image.rs @@ -283,6 +283,20 @@ impl<'a> Image<'a> { } } + /// Returns the URI of the image. + /// + /// For GIFs, returns the URI without the frame number. + #[inline] + pub fn uri(&self) -> Option<&str> { + let uri = self.source.uri()?; + + if let Ok((gif_uri, _index)) = decode_gif_uri(uri) { + Some(gif_uri) + } else { + Some(uri) + } + } + #[inline] pub fn image_options(&self) -> &ImageOptions { &self.image_options