ZIm/crates/gpui/examples
Sunli abf2b9d7d3
gpui: Add ImageCache (#27774)
Closes #27414

`ImageCache` is independent of the original image loader and can
actively release its cached images to solve the problem of images loaded
from the network or files not being released.

It has two constructors:

- `ImageCache::new`: Manually manage the cache.
- `ImageCache::max_items`: Remove the least recently used items when the
cache reaches the specified number.

When creating an `img` element, you can specify the cache object with
`Img::cache`, and the image cache will be managed by `ImageCache`.

In the example `crates\gpui\examples\image-gallery.rs`, the
`ImageCache::clear` method is actively called when switching a set of
images, and the memory will no longer continuously increase.


Release Notes:

- N/A

---------

Co-authored-by: Ben Kunkle <ben@zed.dev>
2025-04-22 13:30:21 -07:00
..
image chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
svg chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
animation.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
data_table.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
drag_drop.rs gpui: Keep drag cursor style when dragging (#24797) 2025-04-10 23:54:12 +00:00
gif_viewer.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
gradient.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
hello_world.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
image_gallery.rs gpui: Add ImageCache (#27774) 2025-04-22 13:30:21 -07:00
image_loading.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
input.rs gpui: Introduce PlatformKeyboardLayout trait for human-friendly keyboard layout names (#29049) 2025-04-19 22:23:03 +08:00
on_window_close_quit.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
opacity.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
ownership_post.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
painting.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
pattern.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
set_menus.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
shadow.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
text_layout.rs Revert buggy pr (#28554) 2025-04-10 18:58:36 -06:00
text_wrapper.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
uniform_list.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
window.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
window_positioning.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
window_shadow.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00