From 9f0bbf6020146d16521dd301b925f710d85dc92d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 19 Feb 2024 08:42:58 +0100 Subject: Add `extend` method to `Column` and `Row` --- widget/src/column.rs | 10 +++++++++- widget/src/row.rs | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/widget/src/column.rs b/widget/src/column.rs index b9eb5d93..0c5ea75e 100644 --- a/widget/src/column.rs +++ b/widget/src/column.rs @@ -46,7 +46,7 @@ where pub fn with_children( children: impl IntoIterator>, ) -> Self { - children.into_iter().fold(Self::new(), Self::push) + Self::new().extend(children) } /// Sets the vertical spacing _between_ elements. @@ -127,6 +127,14 @@ where self } } + + /// Extends the [`Column`] with the given children. + pub fn extend( + self, + children: impl IntoIterator>, + ) -> 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..4ad806ed 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -43,7 +43,7 @@ where pub fn with_children( children: impl IntoIterator>, ) -> Self { - children.into_iter().fold(Self::new(), Self::push) + Self::new().extend(children) } /// Sets the horizontal spacing _between_ elements. @@ -118,6 +118,14 @@ where self } } + + /// Extends the [`Row`] with the given children. + pub fn extend( + self, + children: impl IntoIterator>, + ) -> Self { + children.into_iter().fold(self, Self::push) + } } impl<'a, Message, Renderer> Default for Row<'a, Message, Renderer> -- cgit From e60dabddefd6608a34ecb3f21a0fd53fef6d1f07 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 19 Feb 2024 08:49:28 +0100 Subject: Add `from_vec` method to `Column` and `Row` --- widget/src/column.rs | 31 ++++++++++++++++++++++--------- widget/src/row.rs | 31 ++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/widget/src/column.rs b/widget/src/column.rs index 0c5ea75e..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>, + ) -> 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>, + ) -> 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>, - ) -> Self { - Self::new().extend(children) - } - /// Sets the vertical spacing _between_ elements. /// /// Custom margins per element do not exist in iced. You should use this diff --git a/widget/src/row.rs b/widget/src/row.rs index 4ad806ed..b41b5380 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -28,15 +28,7 @@ where { /// Creates an empty [`Row`]. pub fn new() -> Self { - Row { - spacing: 0.0, - padding: Padding::ZERO, - width: Length::Shrink, - height: Length::Shrink, - align_items: Alignment::Start, - clip: false, - children: Vec::new(), - } + Self::from_vec(Vec::new()) } /// Creates a [`Row`] with the given elements. @@ -46,6 +38,27 @@ where 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>, + ) -> Self { + Self { + spacing: 0.0, + padding: Padding::ZERO, + width: Length::Shrink, + height: Length::Shrink, + align_items: Alignment::Start, + clip: false, + children, + } + } + /// Sets the horizontal spacing _between_ elements. /// /// Custom margins per element do not exist in iced. You should use this -- cgit From 74f764f57157b956ba4a3671b310697b58697cc9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 19 Feb 2024 08:52:34 +0100 Subject: Update `CHANGELOG` --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb488f8f..654402e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -118,6 +118,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Patched - Black images when using OpenGL backend in `iced_wgpu`. [#2259](https://github.com/iced-rs/iced/pull/2259) +- `extend` and `from_vec` methods for `Column` and `Row`. [#2264](https://github.com/iced-rs/iced/pull/2264) Many thanks to... -- cgit From 626604b8afcd649b408d64cd9e767b822bb32b8f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 19 Feb 2024 08:57:39 +0100 Subject: Fix `CHANGELOG` --- CHANGELOG.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 654402e2..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,9 +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) -- `extend` and `from_vec` methods for `Column` and `Row`. [#2264](https://github.com/iced-rs/iced/pull/2264) Many thanks to... @@ -160,7 +166,6 @@ Many thanks to... - @nicksenger - @Nisatru - @nyurik -- @PolyMeilex - @Remmirad - @ripytide - @snaggen -- cgit