Move refreshing to window
This commit is contained in:
@@ -3204,7 +3204,7 @@ mod tests {
|
||||
Point::new(5, 6)..Point::new(6, 0),
|
||||
]);
|
||||
});
|
||||
let mut layout_cx = LayoutContext::new(cx, false);
|
||||
let mut layout_cx = LayoutContext::new(cx);
|
||||
element.layout(
|
||||
SizeConstraint::new(vec2f(500., 500.), vec2f(500., 500.)),
|
||||
editor,
|
||||
@@ -3289,7 +3289,7 @@ mod tests {
|
||||
DisplayPoint::new(10, 0)..DisplayPoint::new(13, 0),
|
||||
]);
|
||||
});
|
||||
let mut layout_cx = LayoutContext::new(cx, false);
|
||||
let mut layout_cx = LayoutContext::new(cx);
|
||||
element.layout(
|
||||
SizeConstraint::new(vec2f(500., 500.), vec2f(500., 500.)),
|
||||
editor,
|
||||
@@ -3349,7 +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 layout_cx = LayoutContext::new(cx, false);
|
||||
let mut layout_cx = LayoutContext::new(cx);
|
||||
element.layout(
|
||||
SizeConstraint::new(vec2f(500., 500.), vec2f(500., 500.)),
|
||||
editor,
|
||||
@@ -3546,7 +3546,7 @@ mod tests {
|
||||
editor.set_soft_wrap_mode(language_settings::SoftWrap::EditorWidth, cx);
|
||||
editor.set_wrap_width(Some(editor_width), cx);
|
||||
|
||||
let mut layout_cx = LayoutContext::new(cx, false);
|
||||
let mut layout_cx = LayoutContext::new(cx);
|
||||
element.layout(
|
||||
SizeConstraint::new(vec2f(editor_width, 500.), vec2f(editor_width, 500.)),
|
||||
editor,
|
||||
|
||||
@@ -3454,15 +3454,11 @@ impl<V> BorrowWindowContext for ViewContext<'_, '_, V> {
|
||||
pub struct LayoutContext<'a, 'b, 'c, V> {
|
||||
// Nathan: Making this is public while I work on gpui2.
|
||||
pub view_context: &'c mut ViewContext<'a, 'b, V>,
|
||||
pub refreshing: bool,
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'c, V> LayoutContext<'a, 'b, 'c, V> {
|
||||
pub fn new(view_context: &'c mut ViewContext<'a, 'b, V>, refreshing: bool) -> Self {
|
||||
Self {
|
||||
view_context,
|
||||
refreshing,
|
||||
}
|
||||
pub fn new(view_context: &'c mut ViewContext<'a, 'b, V>) -> Self {
|
||||
Self { view_context }
|
||||
}
|
||||
|
||||
pub fn view_context(&mut self) -> &mut ViewContext<'a, 'b, V> {
|
||||
@@ -6482,7 +6478,7 @@ mod tests {
|
||||
view_1.update(cx, |_, cx| {
|
||||
view_2.update(cx, |_, cx| {
|
||||
// Sanity check
|
||||
let mut layout_cx = LayoutContext::new(cx, false);
|
||||
let mut layout_cx = LayoutContext::new(cx);
|
||||
assert_eq!(
|
||||
layout_cx
|
||||
.keystrokes_for_action(view_1_id, &Action1)
|
||||
|
||||
@@ -71,6 +71,7 @@ pub struct Window {
|
||||
pub(crate) clicked_region_ids: Vec<MouseRegionId>,
|
||||
pub(crate) clicked_region: Option<(MouseRegionId, MouseButton)>,
|
||||
text_layout_cache: TextLayoutCache,
|
||||
refreshing: bool,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
@@ -113,6 +114,7 @@ impl Window {
|
||||
clicked_region: None,
|
||||
titlebar_height,
|
||||
appearance,
|
||||
refreshing: false,
|
||||
};
|
||||
|
||||
let mut window_context = WindowContext::mutable(cx, &mut window, handle);
|
||||
@@ -291,6 +293,10 @@ impl<'a> WindowContext<'a> {
|
||||
self.window.platform_window.mouse_position()
|
||||
}
|
||||
|
||||
pub fn refreshing(&self) -> bool {
|
||||
self.window.refreshing
|
||||
}
|
||||
|
||||
pub fn text_layout_cache(&self) -> &TextLayoutCache {
|
||||
&self.window.text_layout_cache
|
||||
}
|
||||
@@ -1034,7 +1040,9 @@ impl<'a> WindowContext<'a> {
|
||||
|
||||
let mut rendered_root = self.window.rendered_views.remove(&root_view_id).unwrap();
|
||||
|
||||
rendered_root.layout(SizeConstraint::strict(window_size), refreshing, self)?;
|
||||
self.window.refreshing = refreshing;
|
||||
rendered_root.layout(SizeConstraint::strict(window_size), self)?;
|
||||
self.window.refreshing = false;
|
||||
|
||||
let views_to_notify_if_ancestors_change =
|
||||
mem::take(&mut self.window.views_to_notify_if_ancestors_change);
|
||||
@@ -1671,7 +1679,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.refreshing, cx.view_context)
|
||||
.layout(constraint, cx.view_context)
|
||||
.log_err()
|
||||
.unwrap_or(Vector2F::zero());
|
||||
cx.window.rendered_views.insert(self.view_id, rendered_view);
|
||||
|
||||
@@ -644,12 +644,7 @@ impl<V> RootElement<V> {
|
||||
}
|
||||
|
||||
pub trait AnyRootElement {
|
||||
fn layout(
|
||||
&mut self,
|
||||
constraint: SizeConstraint,
|
||||
refreshing: bool,
|
||||
cx: &mut WindowContext,
|
||||
) -> Result<Vector2F>;
|
||||
fn layout(&mut self, constraint: SizeConstraint, cx: &mut WindowContext) -> Result<Vector2F>;
|
||||
fn paint(
|
||||
&mut self,
|
||||
scene: &mut SceneBuilder,
|
||||
@@ -667,18 +662,13 @@ pub trait AnyRootElement {
|
||||
}
|
||||
|
||||
impl<V: View> AnyRootElement for RootElement<V> {
|
||||
fn layout(
|
||||
&mut self,
|
||||
constraint: SizeConstraint,
|
||||
refreshing: bool,
|
||||
cx: &mut WindowContext,
|
||||
) -> Result<Vector2F> {
|
||||
fn layout(&mut self, constraint: SizeConstraint, cx: &mut WindowContext) -> Result<Vector2F> {
|
||||
let view = self
|
||||
.view
|
||||
.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, refreshing);
|
||||
let mut cx = LayoutContext::new(cx);
|
||||
Ok(self.element.layout(constraint, view, &mut cx))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ impl<V: 'static> Element<V> for List<V> {
|
||||
item_constraint.min.set_y(0.);
|
||||
item_constraint.max.set_y(f32::INFINITY);
|
||||
|
||||
if cx.refreshing || state.last_layout_width != Some(size.x()) {
|
||||
if cx.refreshing() || state.last_layout_width != Some(size.x()) {
|
||||
state.rendered_range = 0..0;
|
||||
state.items = SumTree::from_iter(
|
||||
(0..state.items.summary().count).map(|_| ListItem::Unrendered),
|
||||
@@ -666,7 +666,7 @@ mod tests {
|
||||
});
|
||||
|
||||
let mut list = List::new(state.clone());
|
||||
let mut layout_cx = LayoutContext::new(cx, false);
|
||||
let mut layout_cx = LayoutContext::new(cx);
|
||||
let (size, _) = list.layout(constraint, &mut view, &mut layout_cx);
|
||||
assert_eq!(size, vec2f(100., 40.));
|
||||
assert_eq!(
|
||||
@@ -691,7 +691,7 @@ mod tests {
|
||||
cx,
|
||||
);
|
||||
|
||||
let mut layout_cx = LayoutContext::new(cx, false);
|
||||
let mut layout_cx = LayoutContext::new(cx);
|
||||
let (_, logical_scroll_top) = list.layout(constraint, &mut view, &mut layout_cx);
|
||||
assert_eq!(
|
||||
logical_scroll_top,
|
||||
@@ -716,7 +716,7 @@ mod tests {
|
||||
}
|
||||
);
|
||||
|
||||
let mut layout_cx = LayoutContext::new(cx, false);
|
||||
let mut layout_cx = LayoutContext::new(cx);
|
||||
let (size, logical_scroll_top) = list.layout(constraint, &mut view, &mut layout_cx);
|
||||
assert_eq!(size, vec2f(100., 40.));
|
||||
assert_eq!(
|
||||
@@ -835,7 +835,7 @@ mod tests {
|
||||
|
||||
let mut list = List::new(state.clone());
|
||||
let window_size = vec2f(width, height);
|
||||
let mut layout_cx = LayoutContext::new(cx, false);
|
||||
let mut layout_cx = LayoutContext::new(cx);
|
||||
let (size, logical_scroll_top) = list.layout(
|
||||
SizeConstraint::new(vec2f(0., 0.), window_size),
|
||||
&mut view,
|
||||
|
||||
@@ -411,7 +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 layout_cx = LayoutContext::new(cx, false);
|
||||
let mut layout_cx = LayoutContext::new(cx);
|
||||
let (_, state) = text.layout(
|
||||
SizeConstraint::new(Default::default(), vec2f(f32::INFINITY, f32::INFINITY)),
|
||||
&mut view,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{element::LayoutId, style::Style};
|
||||
use anyhow::{anyhow, Result};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use gpui::{geometry::Size, taffy::style::Overflow, MeasureParams};
|
||||
use gpui::{geometry::Size, MeasureParams};
|
||||
pub use gpui::{taffy::tree::NodeId, LayoutContext as LegacyLayoutContext};
|
||||
|
||||
#[derive(Deref, DerefMut)]
|
||||
|
||||
Reference in New Issue
Block a user