From 06c80c5bcedd8dba187af9d187ba1ae40fa4dafa Mon Sep 17 00:00:00 2001 From: Andrew-Schwartz Date: Wed, 12 Jun 2024 10:54:50 -0400 Subject: [PATCH 1/4] Add FromIterator for Row and Column --- widget/src/column.rs | 42 ++++++++++++++++++++++++------------------ widget/src/row.rs | 6 ++++++ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/widget/src/column.rs b/widget/src/column.rs index df7829b3df..708c0806d2 100644 --- a/widget/src/column.rs +++ b/widget/src/column.rs @@ -1,14 +1,14 @@ //! Distribute content vertically. +use crate::core::{ + Alignment, Clipboard, Element, Layout, Length, Padding, Pixels, Rectangle, + Shell, Size, Vector, Widget, +}; use crate::core::event::{self, Event}; use crate::core::layout; use crate::core::mouse; use crate::core::overlay; use crate::core::renderer; use crate::core::widget::{Operation, Tree}; -use crate::core::{ - Alignment, Clipboard, Element, Layout, Length, Padding, Pixels, Rectangle, - Shell, Size, Vector, Widget, -}; /// A container that distributes its contents vertically. #[allow(missing_debug_implementations)] @@ -25,8 +25,8 @@ pub struct Column<'a, Message, Theme = crate::Theme, Renderer = crate::Renderer> } impl<'a, Message, Theme, Renderer> Column<'a, Message, Theme, Renderer> -where - Renderer: crate::core::Renderer, + where + Renderer: crate::core::Renderer, { /// Creates an empty [`Column`]. pub fn new() -> Self { @@ -40,7 +40,7 @@ where /// Creates a [`Column`] with the given elements. pub fn with_children( - children: impl IntoIterator>, + children: impl IntoIterator>, ) -> Self { let iterator = children.into_iter(); @@ -146,25 +146,31 @@ where /// Extends the [`Column`] with the given children. pub fn extend( self, - children: impl IntoIterator>, + children: impl IntoIterator>, ) -> Self { children.into_iter().fold(self, Self::push) } } impl<'a, Message, Renderer> Default for Column<'a, Message, Renderer> -where - Renderer: crate::core::Renderer, + where + Renderer: crate::core::Renderer, { fn default() -> Self { Self::new() } } +impl<'a, Message, Theme, Renderer: crate::core::Renderer> FromIterator> for Column<'a, Message, Theme, Renderer> { + fn from_iter>>(iter: T) -> Self { + Self::with_children(iter) + } +} + impl<'a, Message, Theme, Renderer> Widget - for Column<'a, Message, Theme, Renderer> -where - Renderer: crate::core::Renderer, +for Column<'a, Message, Theme, Renderer> + where + Renderer: crate::core::Renderer, { fn children(&self) -> Vec { self.children.iter().map(Tree::new).collect() @@ -326,11 +332,11 @@ where } impl<'a, Message, Theme, Renderer> From> - for Element<'a, Message, Theme, Renderer> -where - Message: 'a, - Theme: 'a, - Renderer: crate::core::Renderer + 'a, +for Element<'a, Message, Theme, Renderer> + where + Message: 'a, + Theme: 'a, + Renderer: crate::core::Renderer + 'a, { fn from(column: Column<'a, Message, Theme, Renderer>) -> Self { Self::new(column) diff --git a/widget/src/row.rs b/widget/src/row.rs index fa35217163..5a6b368a3f 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -152,6 +152,12 @@ where } } +impl<'a, Message, Theme, Renderer: crate::core::Renderer> FromIterator> for Row<'a, Message, Theme, Renderer> { + fn from_iter>>(iter: T) -> Self { + Self::with_children(iter) + } +} + impl<'a, Message, Theme, Renderer> Widget for Row<'a, Message, Theme, Renderer> where From 1355f8d296fea59bafac600982fafb23d8aac602 Mon Sep 17 00:00:00 2001 From: Andrew-Schwartz Date: Wed, 12 Jun 2024 13:00:02 -0400 Subject: [PATCH 2/4] Revert "Add FromIterator for Row and Column" This reverts commit 06c80c5bcedd8dba187af9d187ba1ae40fa4dafa. --- widget/src/column.rs | 42 ++++++++++++++++++------------------------ widget/src/row.rs | 6 ------ 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/widget/src/column.rs b/widget/src/column.rs index 708c0806d2..df7829b3df 100644 --- a/widget/src/column.rs +++ b/widget/src/column.rs @@ -1,14 +1,14 @@ //! Distribute content vertically. -use crate::core::{ - Alignment, Clipboard, Element, Layout, Length, Padding, Pixels, Rectangle, - Shell, Size, Vector, Widget, -}; use crate::core::event::{self, Event}; use crate::core::layout; use crate::core::mouse; use crate::core::overlay; use crate::core::renderer; use crate::core::widget::{Operation, Tree}; +use crate::core::{ + Alignment, Clipboard, Element, Layout, Length, Padding, Pixels, Rectangle, + Shell, Size, Vector, Widget, +}; /// A container that distributes its contents vertically. #[allow(missing_debug_implementations)] @@ -25,8 +25,8 @@ pub struct Column<'a, Message, Theme = crate::Theme, Renderer = crate::Renderer> } impl<'a, Message, Theme, Renderer> Column<'a, Message, Theme, Renderer> - where - Renderer: crate::core::Renderer, +where + Renderer: crate::core::Renderer, { /// Creates an empty [`Column`]. pub fn new() -> Self { @@ -40,7 +40,7 @@ impl<'a, Message, Theme, Renderer> Column<'a, Message, Theme, Renderer> /// Creates a [`Column`] with the given elements. pub fn with_children( - children: impl IntoIterator>, + children: impl IntoIterator>, ) -> Self { let iterator = children.into_iter(); @@ -146,31 +146,25 @@ impl<'a, Message, Theme, Renderer> Column<'a, Message, Theme, Renderer> /// Extends the [`Column`] with the given children. pub fn extend( self, - children: impl IntoIterator>, + children: impl IntoIterator>, ) -> Self { children.into_iter().fold(self, Self::push) } } impl<'a, Message, Renderer> Default for Column<'a, Message, Renderer> - where - Renderer: crate::core::Renderer, +where + Renderer: crate::core::Renderer, { fn default() -> Self { Self::new() } } -impl<'a, Message, Theme, Renderer: crate::core::Renderer> FromIterator> for Column<'a, Message, Theme, Renderer> { - fn from_iter>>(iter: T) -> Self { - Self::with_children(iter) - } -} - impl<'a, Message, Theme, Renderer> Widget -for Column<'a, Message, Theme, Renderer> - where - Renderer: crate::core::Renderer, + for Column<'a, Message, Theme, Renderer> +where + Renderer: crate::core::Renderer, { fn children(&self) -> Vec { self.children.iter().map(Tree::new).collect() @@ -332,11 +326,11 @@ for Column<'a, Message, Theme, Renderer> } impl<'a, Message, Theme, Renderer> From> -for Element<'a, Message, Theme, Renderer> - where - Message: 'a, - Theme: 'a, - Renderer: crate::core::Renderer + 'a, + for Element<'a, Message, Theme, Renderer> +where + Message: 'a, + Theme: 'a, + Renderer: crate::core::Renderer + 'a, { fn from(column: Column<'a, Message, Theme, Renderer>) -> Self { Self::new(column) diff --git a/widget/src/row.rs b/widget/src/row.rs index 5a6b368a3f..fa35217163 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -152,12 +152,6 @@ where } } -impl<'a, Message, Theme, Renderer: crate::core::Renderer> FromIterator> for Row<'a, Message, Theme, Renderer> { - fn from_iter>>(iter: T) -> Self { - Self::with_children(iter) - } -} - impl<'a, Message, Theme, Renderer> Widget for Row<'a, Message, Theme, Renderer> where From 65eb06c53743c2aa924bd90ee7b7c62c3541fa08 Mon Sep 17 00:00:00 2001 From: Andrew-Schwartz Date: Wed, 12 Jun 2024 13:01:04 -0400 Subject: [PATCH 3/4] Add FromIterator for Row and Column --- widget/src/column.rs | 6 ++++++ widget/src/row.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/widget/src/column.rs b/widget/src/column.rs index df7829b3df..fbdb02d416 100644 --- a/widget/src/column.rs +++ b/widget/src/column.rs @@ -161,6 +161,12 @@ where } } +impl<'a, Message, Theme, Renderer: crate::core::Renderer> FromIterator> for Column<'a, Message, Theme, Renderer> { + fn from_iter>>(iter: T) -> Self { + Self::with_children(iter) + } +} + impl<'a, Message, Theme, Renderer> Widget for Column<'a, Message, Theme, Renderer> where diff --git a/widget/src/row.rs b/widget/src/row.rs index fa35217163..5a6b368a3f 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -152,6 +152,12 @@ where } } +impl<'a, Message, Theme, Renderer: crate::core::Renderer> FromIterator> for Row<'a, Message, Theme, Renderer> { + fn from_iter>>(iter: T) -> Self { + Self::with_children(iter) + } +} + impl<'a, Message, Theme, Renderer> Widget for Row<'a, Message, Theme, Renderer> where From 620c3d3222fa7ea17fd8d48af656f644bf409aa2 Mon Sep 17 00:00:00 2001 From: Andrew-Schwartz Date: Thu, 13 Jun 2024 14:46:56 -0400 Subject: [PATCH 4/4] format --- widget/src/column.rs | 11 +++++++++-- widget/src/row.rs | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/widget/src/column.rs b/widget/src/column.rs index fbdb02d416..8b97e6919f 100644 --- a/widget/src/column.rs +++ b/widget/src/column.rs @@ -161,8 +161,15 @@ where } } -impl<'a, Message, Theme, Renderer: crate::core::Renderer> FromIterator> for Column<'a, Message, Theme, Renderer> { - fn from_iter>>(iter: T) -> Self { +impl<'a, Message, Theme, Renderer: crate::core::Renderer> + FromIterator> + for Column<'a, Message, Theme, Renderer> +{ + fn from_iter< + T: IntoIterator>, + >( + iter: T, + ) -> Self { Self::with_children(iter) } } diff --git a/widget/src/row.rs b/widget/src/row.rs index 5a6b368a3f..271e8a5085 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -152,8 +152,15 @@ where } } -impl<'a, Message, Theme, Renderer: crate::core::Renderer> FromIterator> for Row<'a, Message, Theme, Renderer> { - fn from_iter>>(iter: T) -> Self { +impl<'a, Message, Theme, Renderer: crate::core::Renderer> + FromIterator> + for Row<'a, Message, Theme, Renderer> +{ + fn from_iter< + T: IntoIterator>, + >( + iter: T, + ) -> Self { Self::with_children(iter) } }