pub struct StyleCache { /* private fields */ }Expand description
Memoizes ComputedStyle per (widget_type, classes, id, stylesheet_generation).
When CompiledStyleSheet::generation advances, all cached entries from
the previous generation are discarded before the new lookup.
§Example
use oxiui_theme::{StyleCache, stylesheet::StyleSheet};
use oxiui_theme::compile::CompiledStyleSheet;
let sheet = StyleSheet::parse("button { color: #ff0000; }").stylesheet;
let compiled = CompiledStyleSheet::compile(&sheet, 1);
let mut cache = StyleCache::new();
let style = cache.get_or_compute(&compiled, "button", &[], None);
assert!(style.color.is_some());Implementations§
Source§impl StyleCache
impl StyleCache
Sourcepub fn get_or_compute(
&mut self,
compiled: &CompiledStyleSheet,
widget_type: &str,
classes: &[&str],
id: Option<&str>,
) -> &ComputedStyle
pub fn get_or_compute( &mut self, compiled: &CompiledStyleSheet, widget_type: &str, classes: &[&str], id: Option<&str>, ) -> &ComputedStyle
Look up or compute a style.
If compiled.generation differs from the last seen generation, the
entire cache is cleared before the lookup proceeds. On a cache miss the
style is computed via CompiledStyleSheet::compute_style, inserted,
and returned.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StyleCache
impl RefUnwindSafe for StyleCache
impl Send for StyleCache
impl Sync for StyleCache
impl Unpin for StyleCache
impl UnsafeUnpin for StyleCache
impl UnwindSafe for StyleCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more