mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-26 10:40:54 +00:00
Move views_to_notify_if_ancestors_change to Window
This commit is contained in:
parent
2e7356a53e
commit
48d3e2d9b9
6 changed files with 20 additions and 47 deletions
|
@ -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,
|
||||
|
|
|
@ -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<usize, SmallVec<[usize; 2]>>,
|
||||
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<usize, SmallVec<[usize; 2]>>,
|
||||
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)
|
||||
|
|
|
@ -57,6 +57,7 @@ pub struct Window {
|
|||
pub(crate) text_style_stack: Vec<TextStyle>,
|
||||
pub(crate) theme_stack: Vec<Box<dyn Any>>,
|
||||
pub(crate) new_parents: HashMap<usize, usize>,
|
||||
pub(crate) views_to_notify_if_ancestors_change: HashMap<usize, SmallVec<[usize; 2]>>,
|
||||
titlebar_height: f32,
|
||||
appearance: Appearance,
|
||||
cursor_regions: Vec<CursorRegion>,
|
||||
|
@ -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<V: 'static> Element<V> 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);
|
||||
|
|
|
@ -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<usize, SmallVec<[usize; 2]>>,
|
||||
refreshing: bool,
|
||||
cx: &mut WindowContext,
|
||||
) -> Result<Vector2F>;
|
||||
|
@ -673,7 +670,6 @@ impl<V: View> AnyRootElement for RootElement<V> {
|
|||
fn layout(
|
||||
&mut self,
|
||||
constraint: SizeConstraint,
|
||||
views_to_notify_if_ancestors_change: &mut HashMap<usize, SmallVec<[usize; 2]>>,
|
||||
refreshing: bool,
|
||||
cx: &mut WindowContext,
|
||||
) -> Result<Vector2F> {
|
||||
|
@ -682,7 +678,7 @@ impl<V: View> AnyRootElement for RootElement<V> {
|
|||
.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))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue