diff options
| author | pml68 <contact@pml68.dev> | 2025-06-09 13:00:56 +0200 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2025-06-09 13:00:56 +0200 |
| commit | c54196d95373d37a64be57b180c08ddfdc2cbadd (patch) | |
| tree | 5b8c26b1883f9e5d63767533c3388c6ce6248a94 | |
| parent | ci: fix workflow (diff) | |
| download | iced_dialog-c54196d95373d37a64be57b180c08ddfdc2cbadd.tar.gz | |
feat: simplify the internal `view` method
| -rw-r--r-- | src/dialog.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/dialog.rs b/src/dialog.rs index 74dea5a..8c93c17 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -238,7 +238,7 @@ where <Theme as container::Catalog>::Class<'a>: From<container::StyleFn<'a, Theme>>, { - 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<Element<'a, Message, Theme, Renderer>>, - content: impl Into<Element<'a, Message, Theme, Renderer>>, + content: Option<impl Into<Element<'a, Message, Theme, Renderer>>>, class: <Theme as Catalog>::Class<'a>, ) -> Element<'a, Message, Theme, Renderer> where @@ -311,16 +309,18 @@ where <Theme as container::Catalog>::Class<'a>: From<container::StyleFn<'a, Theme>>, { - 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`]. |
