1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 22:00:03 -04:00

Move egui::util::cache to egui::cache; add FramePublisher (#5426)

This moves `egui::util::cache` to `egui::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:

``` rs
pub type MyPublisher = egui::cache::FramePublisher<MyKey, MyValue>;

// Publish:
ctx.memory_mut(|mem| {
    mem.caches.cache::<MyPublisher>().set(key, value);
});

// Retrieve:
let value: Option<MyValue> = ctx.memory_mut(|mem| {
    mem.caches
        .cache::<MyPublisher>()
        .get(key)
        .clone()
})
```
This commit is contained in:
Emil Ernerfeldt
2024-12-03 14:28:12 +01:00
committed by GitHub
parent c7224aab26
commit eac7ba01fa
9 changed files with 172 additions and 86 deletions

View File

@@ -33,9 +33,7 @@ pub fn highlight(
// performing it at a separate thread (ctx, ctx.style()) can be used and when ui is available
// (ui.ctx(), ui.style()) can be used
impl egui::util::cache::ComputerMut<(&egui::FontId, &CodeTheme, &str, &str), LayoutJob>
for Highlighter
{
impl egui::cache::ComputerMut<(&egui::FontId, &CodeTheme, &str, &str), LayoutJob> for Highlighter {
fn compute(
&mut self,
(font_id, theme, code, lang): (&egui::FontId, &CodeTheme, &str, &str),
@@ -44,7 +42,7 @@ pub fn highlight(
}
}
type HighlightCache = egui::util::cache::FrameCache<LayoutJob, Highlighter>;
type HighlightCache = egui::cache::FrameCache<LayoutJob, Highlighter>;
let font_id = style
.override_font_id