Remove after_layout from Element trait

Now that layout takes a MutableAppContext we don't need an after_layout phase.
This commit is contained in:
Nathan Sobo 2021-08-20 16:40:45 -06:00
parent d0a5bc694c
commit d68e0b0b97
18 changed files with 22 additions and 191 deletions

View File

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

View File

@ -59,13 +59,6 @@ pub trait Element {
cx: &mut LayoutContext, cx: &mut LayoutContext,
) -> (Vector2F, Self::LayoutState); ) -> (Vector2F, Self::LayoutState);
fn after_layout(
&mut self,
size: Vector2F,
layout: &mut Self::LayoutState,
cx: &mut AfterLayoutContext,
);
fn paint( fn paint(
&mut self, &mut self,
bounds: RectF, bounds: RectF,
@ -163,20 +156,6 @@ impl<T: Element> AnyElement for Lifecycle<T> {
result 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) { fn paint(&mut self, origin: Vector2F, cx: &mut PaintContext) {
*self = if let Lifecycle::PostLayout { *self = if let Lifecycle::PostLayout {
mut element, mut element,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,8 +6,8 @@ use crate::{
vector::{vec2f, Vector2F}, vector::{vec2f, Vector2F},
}, },
json::{json, ToJson}, json::{json, ToJson},
AfterLayoutContext, DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
PaintContext, SizeConstraint, SizeConstraint,
}; };
pub struct LineBox { 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( fn paint(
&mut self, &mut self,
bounds: pathfinder_geometry::rect::RectF, bounds: pathfinder_geometry::rect::RectF,

View File

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

View File

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

View File

@ -1,8 +1,8 @@
use crate::{ use crate::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
json::{self, json, ToJson}, json::{self, json, ToJson},
AfterLayoutContext, DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
PaintContext, SizeConstraint, SizeConstraint,
}; };
pub struct Stack { pub struct Stack {
@ -33,17 +33,6 @@ impl Element for Stack {
(size, ()) (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( fn paint(
&mut self, &mut self,
bounds: RectF, bounds: RectF,

View File

@ -8,8 +8,7 @@ use crate::{
rect::RectF, rect::RectF,
vector::{vec2f, Vector2F}, vector::{vec2f, Vector2F},
}, },
scene, AfterLayoutContext, DebugContext, Element, Event, EventContext, LayoutContext, scene, DebugContext, Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint,
PaintContext, SizeConstraint,
}; };
pub struct Svg { 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) { fn paint(&mut self, bounds: RectF, svg: &mut Self::LayoutState, cx: &mut PaintContext) {
if let Some(svg) = svg.clone() { if let Some(svg) = svg.clone() {
cx.scene.push_icon(scene::Icon { cx.scene.push_icon(scene::Icon {

View File

@ -1,6 +1,4 @@
use super::{ use super::{Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint};
AfterLayoutContext, Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint,
};
use crate::{ use crate::{
geometry::{ geometry::{
rect::RectF, 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( fn paint(
&mut self, &mut self,
bounds: RectF, bounds: RectF,

View File

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

View File

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