textiler_core/context/
theme_context.rs1use crate::theme::Theme;
2use std::ops::Deref;
3use yew::UseStateHandle;
4
5#[derive(Debug, Clone)]
7pub struct ThemeContext {
8 inner: UseStateHandle<Theme>,
9}
10
11impl ThemeContext {
12 pub(crate) fn new(inner: UseStateHandle<Theme>) -> Self {
13 Self { inner }
14 }
15
16 pub fn modify<F: FnOnce(&mut Theme)>(&self, cb: F) {
18 let mut theme: Theme = (*self.inner).clone();
19 cb(&mut theme);
20 self.inner.set(theme);
21 }
22}
23
24impl Deref for ThemeContext {
25 type Target = Theme;
26
27 fn deref(&self) -> &Self::Target {
28 &*self.inner
29 }
30}
31
32impl PartialEq for ThemeContext {
33 fn eq(&self, other: &Self) -> bool {
34 *self.inner == *other.inner
35 }
36}