Fix runtime errors

This commit is contained in:
Nathan Sobo 2023-10-23 11:34:35 +02:00
parent 5247f217fd
commit da8919002f
7 changed files with 31 additions and 20 deletions

View file

@ -137,9 +137,9 @@ where
E: Element,
F: FnOnce(&mut ViewContext<E::ViewState>) -> E,
{
cx.default_global::<ThemeStack>().0.push(theme.clone());
cx.default_global_mut::<ThemeStack>().0.push(theme.clone());
let child = build_child(cx);
cx.default_global::<ThemeStack>().0.pop();
cx.default_global_mut::<ThemeStack>().0.pop();
Themed { theme, child }
}
@ -174,9 +174,11 @@ impl<E: Element> Element for Themed<E> {
element_state: Option<Self::ElementState>,
cx: &mut ViewContext<Self::ViewState>,
) -> Self::ElementState {
cx.default_global::<ThemeStack>().0.push(self.theme.clone());
cx.default_global_mut::<ThemeStack>()
.0
.push(self.theme.clone());
let element_state = self.child.initialize(view_state, element_state, cx);
cx.default_global::<ThemeStack>().0.pop();
cx.default_global_mut::<ThemeStack>().0.pop();
element_state
}
@ -189,9 +191,11 @@ impl<E: Element> Element for Themed<E> {
where
Self: Sized,
{
cx.default_global::<ThemeStack>().0.push(self.theme.clone());
cx.default_global_mut::<ThemeStack>()
.0
.push(self.theme.clone());
let layout_id = self.child.layout(view_state, element_state, cx);
cx.default_global::<ThemeStack>().0.pop();
cx.default_global_mut::<ThemeStack>().0.pop();
layout_id
}
@ -204,9 +208,11 @@ impl<E: Element> Element for Themed<E> {
) where
Self: Sized,
{
cx.default_global::<ThemeStack>().0.push(self.theme.clone());
cx.default_global_mut::<ThemeStack>()
.0
.push(self.theme.clone());
self.child.paint(bounds, view_state, frame_state, cx);
cx.default_global::<ThemeStack>().0.pop();
cx.default_global_mut::<ThemeStack>().0.pop();
}
}