Skip to main content

StyleCache

Struct StyleCache 

Source
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

Source

pub fn new() -> Self

Create an empty cache.

Source

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§

Source§

impl Default for StyleCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.