Fix runtime errors
This commit is contained in:
@@ -510,14 +510,12 @@ impl AppContext {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn default_global<G: 'static + Default + Sync + Send>(&mut self) -> &mut G {
|
||||
pub fn default_global_mut<G: 'static + Default + Sync + Send>(&mut self) -> &mut G {
|
||||
let global_type = TypeId::of::<G>();
|
||||
self.push_effect(Effect::NotifyGlobalObservers { global_type });
|
||||
self.globals_by_type
|
||||
.insert(global_type, Box::new(G::default()));
|
||||
self.globals_by_type
|
||||
.get_mut(&global_type)
|
||||
.unwrap()
|
||||
.entry(global_type)
|
||||
.or_insert_with(|| Box::new(G::default()))
|
||||
.downcast_mut::<G>()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
@@ -603,7 +603,7 @@ pub struct GroupBounds(HashMap<SharedString, SmallVec<[Bounds<Pixels>; 1]>>);
|
||||
|
||||
impl GroupBounds {
|
||||
pub fn get(name: &SharedString, cx: &mut AppContext) -> Option<Bounds<Pixels>> {
|
||||
cx.default_global::<Self>()
|
||||
cx.default_global_mut::<Self>()
|
||||
.0
|
||||
.get(name)
|
||||
.and_then(|bounds_stack| bounds_stack.last())
|
||||
@@ -611,7 +611,7 @@ impl GroupBounds {
|
||||
}
|
||||
|
||||
pub fn push(name: SharedString, bounds: Bounds<Pixels>, cx: &mut AppContext) {
|
||||
cx.default_global::<Self>()
|
||||
cx.default_global_mut::<Self>()
|
||||
.0
|
||||
.entry(name)
|
||||
.or_default()
|
||||
@@ -619,7 +619,7 @@ impl GroupBounds {
|
||||
}
|
||||
|
||||
pub fn pop(name: &SharedString, cx: &mut AppContext) {
|
||||
cx.default_global::<GroupBounds>()
|
||||
cx.default_global_mut::<Self>()
|
||||
.0
|
||||
.get_mut(name)
|
||||
.unwrap()
|
||||
|
||||
Reference in New Issue
Block a user