-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
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: ![image](https://github.com/user-attachments/assets/0a0c5215-9042-4989-9e4a-62f76823588a) -> ![image](https://github.com/user-attachments/assets/ec222323-4692-4fd2-ae7b-2342996829a3) #### 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 <[email protected]>
@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::cache
toegui::cache
(the old path is deprecated, but still works).It also adds the
FramePublisher
helper, which can be used to publish a value which will be retained for this frame and the next: