Move egui::util::cache to egui::cache; add FramePublisher - #5426
Conversation
|
Preview available at https://egui-pr-preview.github.io/pr/5426-emilk/cache-refactor |
9922183 to
1d6153b
Compare
|
If I call Although So would it be better to delete the cache with a cache length of 0 in the |
|
Meta-cache eviction! Yeah, that would make sense, but hopefully there won't be that many cache types… but maybe. |
### Related * Closes #3941 * Uses emilk/egui#5416 * Uses emilk/egui#5426 * Follow-up: #8264 ### What Right-click the name of any space view to get the option to copy its contents as a screenshot, or save it to disk:  ->  #### Details The implementation simply takes a full-screen screenshot and crops the result. The previous attempt (behind a feature-flag) only captured things that were rendered with `re_renderer`, i.e. did not include any egui elements, like labels. So it also only worked on spatial views. This PR work on _all_ space views, and could also be extended to work on containers etc. ### Limitations Not yet implemented on web. See #8264 ### TODO * [x] Point commit hash to egui `master` --------- Co-authored-by: Andreas Reich <andreas@rerun.io>
|
@emilk I tested this new feature and found that it works well in general, but when you have an Here is my test code. type MyPublisher = egui::cache::FramePublisher<String, u32>;
fn main() -> eframe::Result {
eframe::run_simple_native("Example", eframe::NativeOptions::default(), |ctx, _| {
let outer_key = String::from("outer_key");
let value = ctx.memory_mut(|m| m.caches.cache::<MyPublisher>().get(&outer_key).copied());
println!("outer {value:?}"); // None
ctx.memory_mut(|m| m.caches.cache::<MyPublisher>().set(outer_key, 0));
ctx.show_viewport_immediate(
egui::ViewportId::from_hash_of("ExampleViewport"),
Default::default(),
|ctx, _| {
let inner_key = String::from("inner_key");
let value = ctx.memory_mut(|m| m.caches.cache::<MyPublisher>().get(&inner_key).copied());
println!("inner: {value:?}"); // None
ctx.memory_mut(|m| m.caches.cache::<MyPublisher>().set(inner_key, 0));
},
);
})
} |
This moves
egui::util::cachetoegui::cache(the old path is deprecated, but still works).It also adds the
FramePublisherhelper, which can be used to publish a value which will be retained for this frame and the next: