diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 32b84a76c1..eb65d70908 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -3204,8 +3204,7 @@ mod tests { Point::new(5, 6)..Point::new(6, 0), ]); }); - let mut notify_views_if_parents_change = Default::default(); - let mut layout_cx = LayoutContext::new(cx, &mut notify_views_if_parents_change, false); + let mut layout_cx = LayoutContext::new(cx, false); element.layout( SizeConstraint::new(vec2f(500., 500.), vec2f(500., 500.)), editor, @@ -3290,8 +3289,7 @@ mod tests { DisplayPoint::new(10, 0)..DisplayPoint::new(13, 0), ]); }); - let mut notify_views_if_parents_change = Default::default(); - let mut layout_cx = LayoutContext::new(cx, &mut notify_views_if_parents_change, false); + let mut layout_cx = LayoutContext::new(cx, false); element.layout( SizeConstraint::new(vec2f(500., 500.), vec2f(500., 500.)), editor, @@ -3351,8 +3349,7 @@ mod tests { let mut element = EditorElement::new(editor.read_with(cx, |editor, cx| editor.style(cx))); let (size, mut state) = editor.update(cx, |editor, cx| { - let mut notify_views_if_parents_change = Default::default(); - let mut layout_cx = LayoutContext::new(cx, &mut notify_views_if_parents_change, false); + let mut layout_cx = LayoutContext::new(cx, false); element.layout( SizeConstraint::new(vec2f(500., 500.), vec2f(500., 500.)), editor, @@ -3549,8 +3546,7 @@ mod tests { editor.set_soft_wrap_mode(language_settings::SoftWrap::EditorWidth, cx); editor.set_wrap_width(Some(editor_width), cx); - let mut notify_views_if_parents_change = Default::default(); - let mut layout_cx = LayoutContext::new(cx, &mut notify_views_if_parents_change, false); + let mut layout_cx = LayoutContext::new(cx, false); element.layout( SizeConstraint::new(vec2f(editor_width, 500.), vec2f(editor_width, 500.)), editor, diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 552f57ba91..cbf2c775c5 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -3461,19 +3461,13 @@ pub trait RenderContext<'a, 'b, V> { pub struct LayoutContext<'a, 'b, 'c, V> { // Nathan: Making this is public while I work on playground. pub view_context: &'c mut ViewContext<'a, 'b, V>, - views_to_notify_if_ancestors_change: &'c mut HashMap>, pub refreshing: bool, } impl<'a, 'b, 'c, V> LayoutContext<'a, 'b, 'c, V> { - pub fn new( - view_context: &'c mut ViewContext<'a, 'b, V>, - views_to_notify_if_ancestors_change: &'c mut HashMap>, - refreshing: bool, - ) -> Self { + pub fn new(view_context: &'c mut ViewContext<'a, 'b, V>, refreshing: bool) -> Self { Self { view_context, - views_to_notify_if_ancestors_change, refreshing, } } @@ -3520,7 +3514,8 @@ impl<'a, 'b, 'c, V> LayoutContext<'a, 'b, 'c, V> { fn notify_if_view_ancestors_change(&mut self, view_id: usize) { let self_view_id = self.view_id; - self.views_to_notify_if_ancestors_change + self.window + .views_to_notify_if_ancestors_change .entry(view_id) .or_default() .push(self_view_id); @@ -6526,9 +6521,7 @@ mod tests { view_1.update(cx, |_, cx| { view_2.update(cx, |_, cx| { // Sanity check - let mut notify_views_if_parents_change = Default::default(); - let mut layout_cx = - LayoutContext::new(cx, &mut notify_views_if_parents_change, false); + let mut layout_cx = LayoutContext::new(cx, false); assert_eq!( layout_cx .keystrokes_for_action(view_1_id, &Action1) diff --git a/crates/gpui/src/app/window.rs b/crates/gpui/src/app/window.rs index c62722ac2d..61a468d11b 100644 --- a/crates/gpui/src/app/window.rs +++ b/crates/gpui/src/app/window.rs @@ -57,6 +57,7 @@ pub struct Window { pub(crate) text_style_stack: Vec, pub(crate) theme_stack: Vec>, pub(crate) new_parents: HashMap, + pub(crate) views_to_notify_if_ancestors_change: HashMap>, titlebar_height: f32, appearance: Appearance, cursor_regions: Vec, @@ -96,6 +97,7 @@ impl Window { text_style_stack: Vec::new(), theme_stack: Vec::new(), new_parents: HashMap::default(), + views_to_notify_if_ancestors_change: HashMap::default(), cursor_regions: Default::default(), mouse_regions: Default::default(), event_handlers: Default::default(), @@ -1000,14 +1002,10 @@ impl<'a> WindowContext<'a> { let mut rendered_root = self.window.rendered_views.remove(&root_view_id).unwrap(); - let mut views_to_notify_if_ancestors_change = HashMap::default(); - rendered_root.layout( - SizeConstraint::new(window_size, window_size), - &mut views_to_notify_if_ancestors_change, - refreshing, - self, - )?; + rendered_root.layout(SizeConstraint::strict(window_size), refreshing, self)?; + let views_to_notify_if_ancestors_change = + mem::take(&mut self.window.views_to_notify_if_ancestors_change); for (view_id, view_ids_to_notify) in views_to_notify_if_ancestors_change { let mut current_view_id = view_id; loop { @@ -1638,12 +1636,7 @@ impl Element for ChildView { let parent_id = cx.view_id(); cx.window.new_parents.insert(self.view_id, parent_id); let size = rendered_view - .layout( - constraint, - cx.views_to_notify_if_ancestors_change, - cx.refreshing, - cx.view_context, - ) + .layout(constraint, cx.refreshing, cx.view_context) .log_err() .unwrap_or(Vector2F::zero()); cx.window.rendered_views.insert(self.view_id, rendered_view); diff --git a/crates/gpui/src/elements.rs b/crates/gpui/src/elements.rs index 9d5adab3ca..da714907c3 100644 --- a/crates/gpui/src/elements.rs +++ b/crates/gpui/src/elements.rs @@ -38,10 +38,8 @@ use crate::{ ViewContext, WeakViewHandle, WindowContext, }; use anyhow::{anyhow, Result}; -use collections::HashMap; use core::panic; use json::ToJson; -use smallvec::SmallVec; use std::{ any::{type_name, Any}, borrow::Cow, @@ -649,7 +647,6 @@ pub trait AnyRootElement { fn layout( &mut self, constraint: SizeConstraint, - views_to_notify_if_ancestors_change: &mut HashMap>, refreshing: bool, cx: &mut WindowContext, ) -> Result; @@ -673,7 +670,6 @@ impl AnyRootElement for RootElement { fn layout( &mut self, constraint: SizeConstraint, - views_to_notify_if_ancestors_change: &mut HashMap>, refreshing: bool, cx: &mut WindowContext, ) -> Result { @@ -682,7 +678,7 @@ impl AnyRootElement for RootElement { .upgrade(cx) .ok_or_else(|| anyhow!("layout called on a root element for a dropped view"))?; view.update(cx, |view, cx| { - let mut cx = LayoutContext::new(cx, views_to_notify_if_ancestors_change, refreshing); + let mut cx = LayoutContext::new(cx, refreshing); Ok(self.element.layout(constraint, view, &mut cx)) }) } diff --git a/crates/gpui/src/elements/list.rs b/crates/gpui/src/elements/list.rs index 34c70eaab7..1f1b2b9fb4 100644 --- a/crates/gpui/src/elements/list.rs +++ b/crates/gpui/src/elements/list.rs @@ -666,8 +666,7 @@ mod tests { }); let mut list = List::new(state.clone()); - let mut notify_views_if_parents_change = Default::default(); - let mut layout_cx = LayoutContext::new(cx, &mut notify_views_if_parents_change, false); + let mut layout_cx = LayoutContext::new(cx, false); let (size, _) = list.layout(constraint, &mut view, &mut layout_cx); assert_eq!(size, vec2f(100., 40.)); assert_eq!( @@ -692,7 +691,7 @@ mod tests { cx, ); - let mut layout_cx = LayoutContext::new(cx, &mut notify_views_if_parents_change, false); + let mut layout_cx = LayoutContext::new(cx, false); let (_, logical_scroll_top) = list.layout(constraint, &mut view, &mut layout_cx); assert_eq!( logical_scroll_top, @@ -717,7 +716,7 @@ mod tests { } ); - let mut layout_cx = LayoutContext::new(cx, &mut notify_views_if_parents_change, false); + let mut layout_cx = LayoutContext::new(cx, false); let (size, logical_scroll_top) = list.layout(constraint, &mut view, &mut layout_cx); assert_eq!(size, vec2f(100., 40.)); assert_eq!( @@ -836,9 +835,7 @@ mod tests { let mut list = List::new(state.clone()); let window_size = vec2f(width, height); - let mut notify_views_if_parents_change = Default::default(); - let mut layout_cx = - LayoutContext::new(cx, &mut notify_views_if_parents_change, false); + let mut layout_cx = LayoutContext::new(cx, false); let (size, logical_scroll_top) = list.layout( SizeConstraint::new(vec2f(0., 0.), window_size), &mut view, diff --git a/crates/gpui/src/elements/text.rs b/crates/gpui/src/elements/text.rs index 2db0888029..3e9214f12c 100644 --- a/crates/gpui/src/elements/text.rs +++ b/crates/gpui/src/elements/text.rs @@ -411,9 +411,7 @@ mod tests { let mut view = TestView; fonts::with_font_cache(cx.font_cache().clone(), || { let mut text = Text::new("Hello\r\n", Default::default()).with_soft_wrap(true); - let mut notify_views_if_parents_change = Default::default(); - let mut layout_cx = - LayoutContext::new(cx, &mut notify_views_if_parents_change, false); + let mut layout_cx = LayoutContext::new(cx, false); let (_, state) = text.layout( SizeConstraint::new(Default::default(), vec2f(f32::INFINITY, f32::INFINITY)), &mut view,