From 2700486b207443027231c3ed3b49953f2369c998 Mon Sep 17 00:00:00 2001 From: pml68 Date: Mon, 9 Jun 2025 13:00:56 +0200 Subject: feat: simplify the internal `view` method --- src/dialog.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/dialog.rs b/src/dialog.rs index 73994aa..881aed5 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -238,7 +238,7 @@ where ::Class<'a>: From>, { - if self.is_open { + let dialog = self.is_open.then(|| { let contents = Container::new( Column::new() .push_maybe(self.title.map(|title| { @@ -267,7 +267,7 @@ where .height(80) .padding(self.padding); - let dialog = Container::new( + Container::new( Column::new() .push(contents) .push(vertical_space()) @@ -276,12 +276,10 @@ where .width(self.width) .height(self.height) .class(self.container_class) - .clip(true); + .clip(true) + }); - modal(self.base, dialog, self.class) - } else { - self.base - } + modal(self.base, dialog, self.class) } } @@ -301,7 +299,7 @@ where fn modal<'a, Message, Theme, Renderer>( base: impl Into>, - content: impl Into>, + content: Option>>, class: ::Class<'a>, ) -> Element<'a, Message, Theme, Renderer> where @@ -311,16 +309,18 @@ where ::Class<'a>: From>, { - let area = mouse_area(center(opaque(content)).style(move |theme| { - container::Style { - background: Some( - Catalog::style(theme, &class).backdrop_color.into(), - ), - ..Default::default() - } - })); - - stack![base.into(), opaque(area)].into() + let area = content.map(|content| { + opaque(mouse_area(center(opaque(content)).style(move |theme| { + container::Style { + background: Some( + Catalog::style(theme, &class).backdrop_color.into(), + ), + ..Default::default() + } + }))) + }); + + stack![base.into()].push_maybe(area).into() } /// The style of a [`Dialog`]. -- cgit v1.2.3