Adjust image cache APIs to enable ElementState based APIs (#29243)

cc: @sunli829 @huacnlee @probably-neb 

I really liked the earlier PR, but had an idea for how to utilize the
element state so that you don't need to construct the cache externally.
I've updated the APIs to introduce an `ImageCacheProvider` trait, and
added an example implementation of it to the image gallery :)

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2025-04-22 15:08:28 -07:00 committed by GitHub
parent aefb3aa2fa
commit 3705986fac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 272 additions and 69 deletions

View file

@ -1467,6 +1467,20 @@ impl Window {
self.rem_size = rem_size.into();
}
/// Acquire a globally unique identifier for the given ElementId.
/// Only valid for the duration of the provided closure.
pub fn with_global_id<R>(
&mut self,
element_id: ElementId,
f: impl FnOnce(&GlobalElementId, &mut Self) -> R,
) -> R {
self.element_id_stack.push(element_id);
let global_id = GlobalElementId(self.element_id_stack.clone());
let result = f(&global_id, self);
self.element_id_stack.pop();
result
}
/// Executes the provided function with the specified rem size.
///
/// This method must only be called as part of element drawing.