mirror of
https://github.com/emilk/egui.git
synced 2026-09-03 07:10:04 -04:00
Remove ThemeCache, since it is buggy
This commit is contained in:
@@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
mod default_style;
|
mod default_style;
|
||||||
mod style_provider;
|
mod style_provider;
|
||||||
mod theme_cache;
|
|
||||||
mod themes;
|
mod themes;
|
||||||
|
|
||||||
pub use self::{style_provider::StyleProvider, theme_cache::ThemeCache, themes::Themes};
|
pub use self::{style_provider::StyleProvider, themes::Themes};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Ui,
|
Ui,
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -93,7 +93,6 @@ fn main() -> eframe::Result {
|
|||||||
|
|
||||||
eframe::run_ui_native("Styling engine", options, move |ui, _frame| {
|
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.
|
// 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);
|
ui.add_widget_theme::<ButtonStyle>(theme);
|
||||||
|
|
||||||
Panel::left("controls").default_size(260.0).show(ui, |ui| {
|
Panel::left("controls").default_size(260.0).show(ui, |ui| {
|
||||||
|
|||||||
Reference in New Issue
Block a user