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

Application of forget to the frame of gif. #4734

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
16 changes: 13 additions & 3 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2969,18 +2969,28 @@ impl Context {
pub fn forget_image(&self, uri: &str) {
use load::BytesLoader as _;

if uri.is_empty() {
return;
}

crate::profile_function!();

let loaders = self.loaders();

loaders.include.forget(uri);
for loader in loaders.bytes.lock().iter() {
for loader in loaders.texture.lock().iter() {
if is_gif_uri(uri) {
for frame_index in 0..128 {
let frame_uri = self::encode_gif_uri(uri, frame_index);
loader.forget(&frame_uri);
}
}
loader.forget(uri);
}
for loader in loaders.image.lock().iter() {
for loader in loaders.bytes.lock().iter() {
loader.forget(uri);
}
for loader in loaders.texture.lock().iter() {
for loader in loaders.image.lock().iter() {
loader.forget(uri);
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/egui/src/widgets/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ pub fn paint_texture_at(
}

/// gif uris contain the uri & the frame that will be displayed
fn encode_gif_uri(uri: &str, frame_index: usize) -> String {
pub fn encode_gif_uri(uri: &str, frame_index: usize) -> String {
format!("{uri}#{frame_index}")
}

Expand All @@ -814,7 +814,7 @@ pub fn decode_gif_uri(uri: &str) -> Result<(&str, usize), String> {
}

/// checks if uri is a gif file
fn is_gif_uri(uri: &str) -> bool {
pub fn is_gif_uri(uri: &str) -> bool {
uri.ends_with(".gif") || uri.contains(".gif#")
}

Expand Down
4 changes: 2 additions & 2 deletions crates/egui/src/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub use self::{
drag_value::DragValue,
hyperlink::{Hyperlink, Link},
image::{
decode_gif_uri, has_gif_magic_header, paint_texture_at, GifFrameDurations, Image, ImageFit,
ImageOptions, ImageSize, ImageSource,
decode_gif_uri, encode_gif_uri, has_gif_magic_header, is_gif_uri, paint_texture_at,
GifFrameDurations, Image, ImageFit, ImageOptions, ImageSize, ImageSource,
},
image_button::ImageButton,
label::Label,
Expand Down
Loading