diff options
-rw-r--r-- | CHANGELOG.md | 12 | ||||
-rw-r--r-- | widget/src/column.rs | 39 | ||||
-rw-r--r-- | widget/src/row.rs | 39 |
3 files changed, 69 insertions, 21 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index bb488f8f..348d0201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- `extend` and `from_vec` methods for `Column` and `Row`. [#2264](https://github.com/iced-rs/iced/pull/2264) + +### Fixed +- Black images when using OpenGL backend in `iced_wgpu`. [#2259](https://github.com/iced-rs/iced/pull/2259) + +Many thanks to... + +- @PolyMeilex ## [0.12.0] - 2024-02-15 ### Added @@ -116,8 +125,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Alpha mode misconfiguration in `iced_wgpu`. [#2231](https://github.com/iced-rs/iced/pull/2231) - Outdated documentation leading to a dead link. [#2232](https://github.com/iced-rs/iced/pull/2232) -## Patched -- Black images when using OpenGL backend in `iced_wgpu`. [#2259](https://github.com/iced-rs/iced/pull/2259) Many thanks to... @@ -159,7 +166,6 @@ Many thanks to... - @nicksenger - @Nisatru - @nyurik -- @PolyMeilex - @Remmirad - @ripytide - @snaggen diff --git a/widget/src/column.rs b/widget/src/column.rs index b9eb5d93..e59a0809 100644 --- a/widget/src/column.rs +++ b/widget/src/column.rs @@ -30,7 +30,27 @@ where { /// Creates an empty [`Column`]. pub fn new() -> Self { - Column { + Self::from_vec(Vec::new()) + } + + /// Creates a [`Column`] with the given elements. + pub fn with_children( + children: impl IntoIterator<Item = Element<'a, Message, Theme, Renderer>>, + ) -> Self { + Self::new().extend(children) + } + + /// Creates a [`Column`] from an already allocated [`Vec`]. + /// + /// Keep in mind that the [`Column`] will not inspect the [`Vec`], which means + /// it won't automatically adapt to the sizing strategy of its contents. + /// + /// If any of the children have a [`Length::Fill`] strategy, you will need to + /// call [`Column::width`] or [`Column::height`] accordingly. + pub fn from_vec( + children: Vec<Element<'a, Message, Theme, Renderer>>, + ) -> Self { + Self { spacing: 0.0, padding: Padding::ZERO, width: Length::Shrink, @@ -38,17 +58,10 @@ where max_width: f32::INFINITY, align_items: Alignment::Start, clip: false, - children: Vec::new(), + children, } } - /// Creates a [`Column`] with the given elements. - pub fn with_children( - children: impl IntoIterator<Item = Element<'a, Message, Theme, Renderer>>, - ) -> Self { - children.into_iter().fold(Self::new(), Self::push) - } - /// Sets the vertical spacing _between_ elements. /// /// Custom margins per element do not exist in iced. You should use this @@ -127,6 +140,14 @@ where self } } + + /// Extends the [`Column`] with the given children. + pub fn extend( + self, + children: impl IntoIterator<Item = Element<'a, Message, Theme, Renderer>>, + ) -> Self { + children.into_iter().fold(self, Self::push) + } } impl<'a, Message, Renderer> Default for Column<'a, Message, Renderer> diff --git a/widget/src/row.rs b/widget/src/row.rs index 20b47a41..b41b5380 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -28,24 +28,37 @@ where { /// Creates an empty [`Row`]. pub fn new() -> Self { - Row { + Self::from_vec(Vec::new()) + } + + /// Creates a [`Row`] with the given elements. + pub fn with_children( + children: impl IntoIterator<Item = Element<'a, Message, Theme, Renderer>>, + ) -> Self { + Self::new().extend(children) + } + + /// Creates a [`Row`] from an already allocated [`Vec`]. + /// + /// Keep in mind that the [`Row`] will not inspect the [`Vec`], which means + /// it won't automatically adapt to the sizing strategy of its contents. + /// + /// If any of the children have a [`Length::Fill`] strategy, you will need to + /// call [`Row::width`] or [`Row::height`] accordingly. + pub fn from_vec( + children: Vec<Element<'a, Message, Theme, Renderer>>, + ) -> Self { + Self { spacing: 0.0, padding: Padding::ZERO, width: Length::Shrink, height: Length::Shrink, align_items: Alignment::Start, clip: false, - children: Vec::new(), + children, } } - /// Creates a [`Row`] with the given elements. - pub fn with_children( - children: impl IntoIterator<Item = Element<'a, Message, Theme, Renderer>>, - ) -> Self { - children.into_iter().fold(Self::new(), Self::push) - } - /// Sets the horizontal spacing _between_ elements. /// /// Custom margins per element do not exist in iced. You should use this @@ -118,6 +131,14 @@ where self } } + + /// Extends the [`Row`] with the given children. + pub fn extend( + self, + children: impl IntoIterator<Item = Element<'a, Message, Theme, Renderer>>, + ) -> Self { + children.into_iter().fold(self, Self::push) + } } impl<'a, Message, Renderer> Default for Row<'a, Message, Renderer> |