Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Image::uri() #4720

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/egui/src/widgets/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,18 @@ impl<'a> Image<'a> {
}
}

#[inline]
pub fn uri(&self) -> Option<&str> {
let mut uri = self.source.uri();

if is_gif_uri(uri.unwrap_or_default()) {
if let Ok((gif_uri, _index)) = decode_gif_uri(uri.unwrap_or_default()) {
uri = Some(gif_uri);
}
}
uri
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut uri = self.source.uri();
if is_gif_uri(uri.unwrap_or_default()) {
if let Ok((gif_uri, _index)) = decode_gif_uri(uri.unwrap_or_default()) {
uri = Some(gif_uri);
}
}
uri
let uri = self.source.uri()?;
if let Ok((gif_uri, _index)) = decode_gif_uri(uri) {
Some(gif_uri)
} else {
Some(uri)
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And add a docstring for it explaining the gif stuff

}

#[inline]
pub fn image_options(&self) -> &ImageOptions {
&self.image_options
Expand Down
Loading