From b5aedc144d440de745cf94ed305a6cc55133cec8 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 28 Aug 2023 14:23:16 -0600 Subject: [PATCH] Allow layout to be called on element in any phase of its lifecyle. Co-Authored-By: Mikayla Maki --- crates/gpui/playground/src/element.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/crates/gpui/playground/src/element.rs b/crates/gpui/playground/src/element.rs index 6091e17989fe54b7a95a27e1789e9eb3eef2fecd..741ba68317ae40f7c14b3bcbd7812024b0ecd3a0 100644 --- a/crates/gpui/playground/src/element.rs +++ b/crates/gpui/playground/src/element.rs @@ -71,22 +71,19 @@ impl> Default for ElementPhase { impl> AnyStatefulElement for StatefulElement { fn layout(&mut self, view: &mut V, cx: &mut LayoutContext) -> Result { 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