Remove after_layout from Element trait

Nathan Sobo created

Now that layout takes a MutableAppContext we don't need an after_layout phase.

Change summary

gpui/examples/text.rs                    |  8 --------
gpui/src/elements.rs                     | 21 ---------------------
gpui/src/elements/align.rs               | 13 ++-----------
gpui/src/elements/canvas.rs              |  8 --------
gpui/src/elements/constrained_box.rs     | 13 ++-----------
gpui/src/elements/container.rs           | 12 +-----------
gpui/src/elements/empty.rs               |  7 +------
gpui/src/elements/event_handler.rs       | 13 ++-----------
gpui/src/elements/flex.rs                | 24 ++----------------------
gpui/src/elements/label.rs               |  7 ++-----
gpui/src/elements/line_box.rs            | 13 ++-----------
gpui/src/elements/list.rs                |  9 ---------
gpui/src/elements/mouse_event_handler.rs | 13 ++-----------
gpui/src/elements/stack.rs               | 15 ++-------------
gpui/src/elements/svg.rs                 |  6 +-----
gpui/src/elements/uniform_list.rs        | 15 +--------------
gpui/src/presenter.rs                    |  9 ---------
zed/src/editor/element.rs                |  7 ++-----
18 files changed, 22 insertions(+), 191 deletions(-)

Detailed changes

gpui/examples/text.rs 🔗

@@ -46,14 +46,6 @@ impl gpui::Element for TextElement {
         (constraint.max, ())
     }
 
-    fn after_layout(
-        &mut self,
-        _: pathfinder_geometry::vector::Vector2F,
-        _: &mut Self::LayoutState,
-        _: &mut gpui::AfterLayoutContext,
-    ) {
-    }
-
     fn paint(
         &mut self,
         bounds: RectF,

gpui/src/elements.rs 🔗

@@ -59,13 +59,6 @@ pub trait Element {
         cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState);
 
-    fn after_layout(
-        &mut self,
-        size: Vector2F,
-        layout: &mut Self::LayoutState,
-        cx: &mut AfterLayoutContext,
-    );
-
     fn paint(
         &mut self,
         bounds: RectF,
@@ -163,20 +156,6 @@ impl<T: Element> AnyElement for Lifecycle<T> {
         result
     }
 
-    fn after_layout(&mut self, cx: &mut AfterLayoutContext) {
-        if let Lifecycle::PostLayout {
-            element,
-            size,
-            layout,
-            ..
-        } = self
-        {
-            element.after_layout(*size, layout, cx);
-        } else {
-            panic!("invalid element lifecycle state");
-        }
-    }
-
     fn paint(&mut self, origin: Vector2F, cx: &mut PaintContext) {
         *self = if let Lifecycle::PostLayout {
             mut element,

gpui/src/elements/align.rs 🔗

@@ -1,6 +1,6 @@
 use crate::{
-    json, AfterLayoutContext, DebugContext, Element, ElementBox, Event, EventContext,
-    LayoutContext, PaintContext, SizeConstraint,
+    json, DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
+    SizeConstraint,
 };
 use json::ToJson;
 use pathfinder_geometry::vector::Vector2F;
@@ -51,15 +51,6 @@ impl Element for Align {
         (size, ())
     }
 
-    fn after_layout(
-        &mut self,
-        _: Vector2F,
-        _: &mut Self::LayoutState,
-        cx: &mut AfterLayoutContext,
-    ) {
-        self.child.after_layout(cx);
-    }
-
     fn paint(
         &mut self,
         bounds: pathfinder_geometry::rect::RectF,

gpui/src/elements/canvas.rs 🔗

@@ -56,14 +56,6 @@ where
         self.0(bounds, cx)
     }
 
-    fn after_layout(
-        &mut self,
-        _: Vector2F,
-        _: &mut Self::LayoutState,
-        _: &mut crate::AfterLayoutContext,
-    ) {
-    }
-
     fn dispatch_event(
         &mut self,
         _: &crate::Event,

gpui/src/elements/constrained_box.rs 🔗

@@ -3,8 +3,8 @@ use serde_json::json;
 
 use crate::{
     geometry::{rect::RectF, vector::Vector2F},
-    json, AfterLayoutContext, DebugContext, Element, ElementBox, Event, EventContext,
-    LayoutContext, PaintContext, SizeConstraint,
+    json, DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
+    SizeConstraint,
 };
 
 pub struct ConstrainedBox {
@@ -67,15 +67,6 @@ impl Element for ConstrainedBox {
         (size, ())
     }
 
-    fn after_layout(
-        &mut self,
-        _: Vector2F,
-        _: &mut Self::LayoutState,
-        cx: &mut AfterLayoutContext,
-    ) {
-        self.child.after_layout(cx);
-    }
-
     fn paint(
         &mut self,
         bounds: RectF,

gpui/src/elements/container.rs 🔗

@@ -10,8 +10,7 @@ use crate::{
     },
     json::ToJson,
     scene::{self, Border, Quad},
-    AfterLayoutContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
-    SizeConstraint,
+    Element, ElementBox, Event, EventContext, LayoutContext, PaintContext, SizeConstraint,
 };
 
 #[derive(Clone, Debug, Default, Deserialize)]
@@ -167,15 +166,6 @@ impl Element for Container {
         (child_size + size_buffer, ())
     }
 
-    fn after_layout(
-        &mut self,
-        _: Vector2F,
-        _: &mut Self::LayoutState,
-        cx: &mut AfterLayoutContext,
-    ) {
-        self.child.after_layout(cx);
-    }
-
     fn paint(
         &mut self,
         bounds: RectF,

gpui/src/elements/empty.rs 🔗

@@ -6,9 +6,7 @@ use crate::{
     json::{json, ToJson},
     DebugContext,
 };
-use crate::{
-    AfterLayoutContext, Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint,
-};
+use crate::{Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint};
 
 pub struct Empty;
 
@@ -41,9 +39,6 @@ impl Element for Empty {
         (vec2f(x, y), ())
     }
 
-    fn after_layout(&mut self, _: Vector2F, _: &mut Self::LayoutState, _: &mut AfterLayoutContext) {
-    }
-
     fn paint(
         &mut self,
         _: RectF,

gpui/src/elements/event_handler.rs 🔗

@@ -2,8 +2,8 @@ use pathfinder_geometry::rect::RectF;
 use serde_json::json;
 
 use crate::{
-    geometry::vector::Vector2F, AfterLayoutContext, DebugContext, Element, ElementBox, Event,
-    EventContext, LayoutContext, PaintContext, SizeConstraint,
+    geometry::vector::Vector2F, DebugContext, Element, ElementBox, Event, EventContext,
+    LayoutContext, PaintContext, SizeConstraint,
 };
 
 pub struct EventHandler {
@@ -41,15 +41,6 @@ impl Element for EventHandler {
         (size, ())
     }
 
-    fn after_layout(
-        &mut self,
-        _: Vector2F,
-        _: &mut Self::LayoutState,
-        cx: &mut AfterLayoutContext,
-    ) {
-        self.child.after_layout(cx);
-    }
-
     fn paint(
         &mut self,
         bounds: RectF,

gpui/src/elements/flex.rs 🔗

@@ -2,8 +2,8 @@ use std::{any::Any, f32::INFINITY};
 
 use crate::{
     json::{self, ToJson, Value},
-    AfterLayoutContext, Axis, DebugContext, Element, ElementBox, Event, EventContext,
-    LayoutContext, PaintContext, SizeConstraint, Vector2FExt,
+    Axis, DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
+    SizeConstraint, Vector2FExt,
 };
 use pathfinder_geometry::{
     rect::RectF,
@@ -134,17 +134,6 @@ impl Element for Flex {
         (size, ())
     }
 
-    fn after_layout(
-        &mut self,
-        _: Vector2F,
-        _: &mut Self::LayoutState,
-        cx: &mut AfterLayoutContext,
-    ) {
-        for child in &mut self.children {
-            child.after_layout(cx);
-        }
-    }
-
     fn paint(
         &mut self,
         bounds: RectF,
@@ -223,15 +212,6 @@ impl Element for Expanded {
         (size, ())
     }
 
-    fn after_layout(
-        &mut self,
-        _: Vector2F,
-        _: &mut Self::LayoutState,
-        cx: &mut AfterLayoutContext,
-    ) {
-        self.child.after_layout(cx);
-    }
-
     fn paint(
         &mut self,
         bounds: RectF,

gpui/src/elements/label.rs 🔗

@@ -8,8 +8,8 @@ use crate::{
     },
     json::{ToJson, Value},
     text_layout::Line,
-    AfterLayoutContext, DebugContext, Element, Event, EventContext, FontCache, LayoutContext,
-    PaintContext, SizeConstraint,
+    DebugContext, Element, Event, EventContext, FontCache, LayoutContext, PaintContext,
+    SizeConstraint,
 };
 use serde::Deserialize;
 use serde_json::json;
@@ -140,9 +140,6 @@ impl Element for Label {
         (size, line)
     }
 
-    fn after_layout(&mut self, _: Vector2F, _: &mut Self::LayoutState, _: &mut AfterLayoutContext) {
-    }
-
     fn paint(
         &mut self,
         bounds: RectF,

gpui/src/elements/line_box.rs 🔗

@@ -6,8 +6,8 @@ use crate::{
         vector::{vec2f, Vector2F},
     },
     json::{json, ToJson},
-    AfterLayoutContext, DebugContext, Element, ElementBox, Event, EventContext, LayoutContext,
-    PaintContext, SizeConstraint,
+    DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
+    SizeConstraint,
 };
 
 pub struct LineBox {
@@ -60,15 +60,6 @@ impl Element for LineBox {
         }
     }
 
-    fn after_layout(
-        &mut self,
-        _: Vector2F,
-        _: &mut Self::LayoutState,
-        cx: &mut AfterLayoutContext,
-    ) {
-        self.child.after_layout(cx);
-    }
-
     fn paint(
         &mut self,
         bounds: pathfinder_geometry::rect::RectF,

gpui/src/elements/list.rs 🔗

@@ -44,15 +44,6 @@ impl Element for List {
         todo!()
     }
 
-    fn after_layout(
-        &mut self,
-        size: Vector2F,
-        layout: &mut Self::LayoutState,
-        cx: &mut crate::AfterLayoutContext,
-    ) {
-        todo!()
-    }
-
     fn paint(
         &mut self,
         bounds: RectF,

gpui/src/elements/mouse_event_handler.rs 🔗

@@ -1,7 +1,7 @@
 use crate::{
     geometry::{rect::RectF, vector::Vector2F},
-    AfterLayoutContext, AppContext, DebugContext, Element, ElementBox, Event, EventContext,
-    LayoutContext, PaintContext, SizeConstraint, ValueHandle,
+    AppContext, DebugContext, Element, ElementBox, Event, EventContext, LayoutContext,
+    PaintContext, SizeConstraint, ValueHandle,
 };
 use serde_json::json;
 
@@ -51,15 +51,6 @@ impl Element for MouseEventHandler {
         (self.child.layout(constraint, cx), ())
     }
 
-    fn after_layout(
-        &mut self,
-        _: Vector2F,
-        _: &mut Self::LayoutState,
-        cx: &mut AfterLayoutContext,
-    ) {
-        self.child.after_layout(cx);
-    }
-
     fn paint(
         &mut self,
         bounds: RectF,

gpui/src/elements/stack.rs 🔗

@@ -1,8 +1,8 @@
 use crate::{
     geometry::{rect::RectF, vector::Vector2F},
     json::{self, json, ToJson},
-    AfterLayoutContext, DebugContext, Element, ElementBox, Event, EventContext, LayoutContext,
-    PaintContext, SizeConstraint,
+    DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
+    SizeConstraint,
 };
 
 pub struct Stack {
@@ -33,17 +33,6 @@ impl Element for Stack {
         (size, ())
     }
 
-    fn after_layout(
-        &mut self,
-        _: Vector2F,
-        _: &mut Self::LayoutState,
-        cx: &mut AfterLayoutContext,
-    ) {
-        for child in &mut self.children {
-            child.after_layout(cx);
-        }
-    }
-
     fn paint(
         &mut self,
         bounds: RectF,

gpui/src/elements/svg.rs 🔗

@@ -8,8 +8,7 @@ use crate::{
         rect::RectF,
         vector::{vec2f, Vector2F},
     },
-    scene, AfterLayoutContext, DebugContext, Element, Event, EventContext, LayoutContext,
-    PaintContext, SizeConstraint,
+    scene, DebugContext, Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint,
 };
 
 pub struct Svg {
@@ -66,9 +65,6 @@ impl Element for Svg {
         }
     }
 
-    fn after_layout(&mut self, _: Vector2F, _: &mut Self::LayoutState, _: &mut AfterLayoutContext) {
-    }
-
     fn paint(&mut self, bounds: RectF, svg: &mut Self::LayoutState, cx: &mut PaintContext) {
         if let Some(svg) = svg.clone() {
             cx.scene.push_icon(scene::Icon {

gpui/src/elements/uniform_list.rs 🔗

@@ -1,6 +1,4 @@
-use super::{
-    AfterLayoutContext, Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint,
-};
+use super::{Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint};
 use crate::{
     geometry::{
         rect::RectF,
@@ -164,17 +162,6 @@ where
         )
     }
 
-    fn after_layout(
-        &mut self,
-        _: Vector2F,
-        layout: &mut Self::LayoutState,
-        cx: &mut AfterLayoutContext,
-    ) {
-        for item in &mut layout.items {
-            item.after_layout(cx);
-        }
-    }
-
     fn paint(
         &mut self,
         bounds: RectF,

gpui/src/presenter.rs 🔗

@@ -398,15 +398,6 @@ impl Element for ChildView {
         (size, ())
     }
 
-    fn after_layout(
-        &mut self,
-        _: Vector2F,
-        _: &mut Self::LayoutState,
-        cx: &mut AfterLayoutContext,
-    ) {
-        cx.after_layout(self.view_id);
-    }
-
     fn paint(
         &mut self,
         bounds: pathfinder_geometry::rect::RectF,

zed/src/editor/element.rs 🔗

@@ -9,8 +9,8 @@ use gpui::{
     },
     json::{self, ToJson},
     text_layout::{self, TextLayoutCache},
-    AfterLayoutContext, AppContext, Border, Element, Event, EventContext, FontCache, LayoutContext,
-    MutableAppContext, PaintContext, Quad, Scene, SizeConstraint, ViewContext, WeakViewHandle,
+    AppContext, Border, Element, Event, EventContext, FontCache, LayoutContext, MutableAppContext,
+    PaintContext, Quad, Scene, SizeConstraint, ViewContext, WeakViewHandle,
 };
 use json::json;
 use smallvec::SmallVec;
@@ -552,9 +552,6 @@ impl Element for EditorElement {
         (size, Some(layout))
     }
 
-    fn after_layout(&mut self, _: Vector2F, _: &mut Self::LayoutState, _: &mut AfterLayoutContext) {
-    }
-
     fn paint(
         &mut self,
         bounds: RectF,