Skip to content

Commit

Permalink
Add Image::uri() (#4720)
Browse files Browse the repository at this point in the history
`uri()` for image

The advantages of this are :

1. No need for `ctx()` and `source()`
2. Displays `name.gif#0` as `name.gif`
  • Loading branch information
rustbasic authored Jul 5, 2024
1 parent 9a4c462 commit ad597a8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/egui/src/widgets/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ad597a8

Please sign in to comment.