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
+1 -1
View File
@@ -4,7 +4,7 @@ mod components;
mod element_ext;
mod elements;
pub mod prelude;
mod settings;
pub mod settings;
mod static_data;
mod theme;
+5 -1
View File
@@ -1,9 +1,13 @@
use std::ops::Deref;
use gpui2::{rems, AbsoluteLength, WindowContext};
use gpui2::{rems, AbsoluteLength, AppContext, WindowContext};
use crate::prelude::*;
pub fn init(cx: &mut AppContext) {
cx.set_global(FakeSettings::default());
}
/// Returns the user settings.
pub fn user_settings(cx: &WindowContext) -> FakeSettings {
cx.global::<FakeSettings>().clone()
+14 -8
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();
}
}