Allow layout to be called on element in any phase of its lifecyle.

Nathan Sobo and Mikayla Maki created

Co-Authored-By: Mikayla Maki <mikayla@zed.dev>

Change summary

crates/gpui/playground/src/element.rs | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)

Detailed changes

crates/gpui/playground/src/element.rs 🔗

@@ -71,22 +71,19 @@ impl<V: 'static, E: Element<V>> Default for ElementPhase<V, E> {
 impl<V, E: Element<V>> AnyStatefulElement<V> for StatefulElement<V, E> {
     fn layout(&mut self, view: &mut V, cx: &mut LayoutContext<V>) -> Result<LayoutId> {
         let result;
-        self.phase = match std::mem::take(&mut self.phase) {
-            ElementPhase::Init => match self.element.layout(view, cx) {
-                Ok((layout_id, paint_state)) => {
-                    result = Ok(layout_id);
-                    ElementPhase::PostLayout {
-                        layout_id,
-                        paint_state,
-                    }
+        self.phase = match self.element.layout(view, cx) {
+            Ok((layout_id, paint_state)) => {
+                result = Ok(layout_id);
+                ElementPhase::PostLayout {
+                    layout_id,
+                    paint_state,
                 }
-                Err(error) => {
-                    let message = error.to_string();
-                    result = Err(error);
-                    ElementPhase::Error(message)
-                }
-            },
-            _ => panic!("invalid element phase to call layout"),
+            }
+            Err(error) => {
+                let message = error.to_string();
+                result = Err(error);
+                ElementPhase::Error(message)
+            }
         };
 
         result