diff options
author | 2024-02-27 01:21:02 +0100 | |
---|---|---|
committer | 2024-02-27 01:21:02 +0100 | |
commit | 01fbd5049d09b44369b7cd1f283c473afda5d2be (patch) | |
tree | a2aa54b131835f757220efd0f9310349e9330aca | |
parent | 58a7007ac194f66c20a6ec8e9c5ae477ab21b622 (diff) | |
download | iced-01fbd5049d09b44369b7cd1f283c473afda5d2be.tar.gz iced-01fbd5049d09b44369b7cd1f283c473afda5d2be.tar.bz2 iced-01fbd5049d09b44369b7cd1f283c473afda5d2be.zip |
Fix `Column` and `Row` fluidity being overridden by `push`
-rw-r--r-- | core/src/length.rs | 11 | ||||
-rw-r--r-- | widget/src/column.rs | 11 | ||||
-rw-r--r-- | widget/src/keyed/column.rs | 11 | ||||
-rw-r--r-- | widget/src/row.rs | 11 |
4 files changed, 19 insertions, 25 deletions
diff --git a/core/src/length.rs b/core/src/length.rs index 4c139895..5f24169f 100644 --- a/core/src/length.rs +++ b/core/src/length.rs @@ -48,12 +48,21 @@ impl Length { /// Specifically: /// - [`Length::Shrink`] if [`Length::Shrink`] or [`Length::Fixed`]. /// - [`Length::Fill`] otherwise. - pub fn fluid(&self) -> Length { + pub fn fluid(&self) -> Self { match self { Length::Fill | Length::FillPortion(_) => Length::Fill, Length::Shrink | Length::Fixed(_) => Length::Shrink, } } + + /// Adapts the [`Length`] so it can contain the other [`Length`] and + /// match its fluidity. + pub fn enclose(self, other: Length) -> Self { + match (self, other) { + (Length::Shrink, Length::Fill | Length::FillPortion(_)) => other, + _ => self, + } + } } impl From<Pixels> for Length { diff --git a/widget/src/column.rs b/widget/src/column.rs index e59a0809..d37ef695 100644 --- a/widget/src/column.rs +++ b/widget/src/column.rs @@ -115,15 +115,10 @@ where child: impl Into<Element<'a, Message, Theme, Renderer>>, ) -> Self { let child = child.into(); - let size = child.as_widget().size_hint(); + let child_size = child.as_widget().size_hint(); - if size.width.is_fill() { - self.width = Length::Fill; - } - - if size.height.is_fill() { - self.height = Length::Fill; - } + self.width = self.width.enclose(child_size.width); + self.height = self.height.enclose(child_size.height); self.children.push(child); self diff --git a/widget/src/keyed/column.rs b/widget/src/keyed/column.rs index ce74e701..8a8d5fe7 100644 --- a/widget/src/keyed/column.rs +++ b/widget/src/keyed/column.rs @@ -110,15 +110,10 @@ where child: impl Into<Element<'a, Message, Theme, Renderer>>, ) -> Self { let child = child.into(); - let size = child.as_widget().size_hint(); + let child_size = child.as_widget().size_hint(); - if size.width.is_fill() { - self.width = Length::Fill; - } - - if size.height.is_fill() { - self.height = Length::Fill; - } + self.width = self.width.enclose(child_size.width); + self.height = self.height.enclose(child_size.height); self.keys.push(key); self.children.push(child); diff --git a/widget/src/row.rs b/widget/src/row.rs index b41b5380..47feff9c 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -106,15 +106,10 @@ where child: impl Into<Element<'a, Message, Theme, Renderer>>, ) -> Self { let child = child.into(); - let size = child.as_widget().size_hint(); + let child_size = child.as_widget().size_hint(); - if size.width.is_fill() { - self.width = Length::Fill; - } - - if size.height.is_fill() { - self.height = Length::Fill; - } + self.width = self.width.enclose(child_size.width); + self.height = self.height.enclose(child_size.height); self.children.push(child); self |