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

Remove ThemeCache, since it is buggy

This commit is contained in:
Emil Ernerfeldt
2026-08-04 14:11:56 +02:00
parent 0e552c7844
commit 02389a2578
3 changed files with 1 additions and 44 deletions

View File

@@ -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,

View File

@@ -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<Theme> {
cache: IdTypeMap,
inner: Theme,
}
impl<Theme> ThemeCache<Theme> {
pub fn new(theme: Theme) -> Self {
Self {
cache: IdTypeMap::default(),
inner: theme,
}
}
}
impl<Theme: StyleProvider<S>, S: WidgetStyle> StyleProvider<S> for ThemeCache<Theme> {
/// 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::<S>(style_id) {
style
} else {
let style = self.inner.style(modifiers);
self.cache.insert_temp(style_id, style.clone());
style
}
}
}

View File

@@ -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::<ButtonStyle>(theme);
Panel::left("controls").default_size(260.0).show(ui, |ui| {