From 145534c92e3ea493a065abf47ef5b09b747b01ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 23 Sep 2025 02:23:12 +0200 Subject: [PATCH] Remove `push_maybe` from `stack` widget --- devtools/src/lib.rs | 19 +++++++++---------- widget/src/stack.rs | 24 +++++++----------------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/devtools/src/lib.rs b/devtools/src/lib.rs index c806912d..6ad7ae9a 100644 --- a/devtools/src/lib.rs +++ b/devtools/src/lib.rs @@ -344,11 +344,10 @@ where .background(Color::BLACK.scale_alpha(0.8)) }); - Some(setup) + Some(themer(theme(), Element::from(setup).map(Event::Message))) } else { None - } - .map(|setup| themer(theme(), Element::from(setup).map(Event::Message))); + }; let notification = self .show_notification @@ -359,12 +358,8 @@ where "Types have changed. Restart to re-enable hotpatching.", ) }) - }); - - stack![view] - .height(Fill) - .push_maybe(setup.map(opaque)) - .push_maybe(notification.map(|notification| { + }) + .map(|notification| { themer( theme(), bottom_right(opaque( @@ -373,7 +368,11 @@ where .style(container::dark), )), ) - })) + }); + + stack![view, setup, notification] + .width(Fill) + .height(Fill) .into() } diff --git a/widget/src/stack.rs b/widget/src/stack.rs index 6cfe0311..65c5aeb0 100644 --- a/widget/src/stack.rs +++ b/widget/src/stack.rs @@ -84,30 +84,20 @@ where child: impl Into>, ) -> Self { let child = child.into(); + let child_size = child.as_widget().size_hint(); - if self.children.is_empty() { - let child_size = child.as_widget().size_hint(); + if !child_size.is_void() { + if self.children.is_empty() { + self.width = self.width.enclose(child_size.width); + self.height = self.height.enclose(child_size.height); + } - self.width = self.width.enclose(child_size.width); - self.height = self.height.enclose(child_size.height); + self.children.push(child); } - self.children.push(child); self } - /// Adds an element to the [`Stack`], if `Some`. - pub fn push_maybe( - self, - child: Option>>, - ) -> Self { - if let Some(child) = child { - self.push(child) - } else { - self - } - } - /// Extends the [`Stack`] with the given children. pub fn extend( self,