From 02389a257897dd18998cb17065f41b26391df398 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 4 Aug 2026 14:11:56 +0200 Subject: [PATCH] Remove ThemeCache, since it is buggy --- crates/egui/src/theme/mod.rs | 3 +- crates/egui/src/theme/theme_cache.rs | 41 ---------------------------- examples/styling_engine/src/main.rs | 1 - 3 files changed, 1 insertion(+), 44 deletions(-) delete mode 100644 crates/egui/src/theme/theme_cache.rs diff --git a/crates/egui/src/theme/mod.rs b/crates/egui/src/theme/mod.rs index 9aa880831..bd7bc484d 100644 --- a/crates/egui/src/theme/mod.rs +++ b/crates/egui/src/theme/mod.rs @@ -2,10 +2,9 @@ mod default_style; mod style_provider; -mod theme_cache; mod themes; -pub use self::{style_provider::StyleProvider, theme_cache::ThemeCache, themes::Themes}; +pub use self::{style_provider::StyleProvider, themes::Themes}; use crate::{ Ui, diff --git a/crates/egui/src/theme/theme_cache.rs b/crates/egui/src/theme/theme_cache.rs deleted file mode 100644 index f9b2cdcaa..000000000 --- a/crates/egui/src/theme/theme_cache.rs +++ /dev/null @@ -1,41 +0,0 @@ -use crate::{ - Id, - theme::StyleProvider, - util::IdTypeMap, - widget_style::{StyleArgs, WidgetStyle}, -}; - -/// A cache that can be implemented to reduce computation time of a `StyleProvider` -#[derive(Debug, Default, Clone)] -pub struct ThemeCache { - cache: IdTypeMap, - inner: Theme, -} - -impl ThemeCache { - pub fn new(theme: Theme) -> Self { - Self { - cache: IdTypeMap::default(), - inner: theme, - } - } -} - -impl, S: WidgetStyle> StyleProvider for ThemeCache { - /// Access the cache for the requested [`WidgetStyle`] based on the [`Classes`](crate::widget_style::Classes) and - /// the [`WidgetState`](crate::widget_style::WidgetState) - /// - /// If no entry match the parameter then compute the fallback style and - /// save the output for later. - fn style(&mut self, modifiers: &StyleArgs<'_>) -> S { - let StyleArgs { classes, state, .. } = modifiers; - let style_id = Id::new((classes, state)); - if let Some(style) = self.cache.get_temp::(style_id) { - style - } else { - let style = self.inner.style(modifiers); - self.cache.insert_temp(style_id, style.clone()); - style - } - } -} diff --git a/examples/styling_engine/src/main.rs b/examples/styling_engine/src/main.rs index d9503a3e6..80b27795d 100644 --- a/examples/styling_engine/src/main.rs +++ b/examples/styling_engine/src/main.rs @@ -93,7 +93,6 @@ fn main() -> eframe::Result { eframe::run_ui_native("Styling engine", options, move |ui, _frame| { // Register our theme for all buttons. This is a no-op after the first frame. - // Wrap it in a `ThemeCache` if computing the style is expensive. ui.add_widget_theme::(theme); Panel::left("controls").default_size(260.0).show(ui, |ui| {