From 16b3fe80164c2f0abc1144f65a31373e4c2960e1 Mon Sep 17 00:00:00 2001 From: MYT Date: Thu, 23 Jan 2025 23:56:48 +0000 Subject: [PATCH 1/2] Add map support to GridRow --- src/widget/grid/types.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/widget/grid/types.rs b/src/widget/grid/types.rs index 7ce99b04..e3e5837d 100644 --- a/src/widget/grid/types.rs +++ b/src/widget/grid/types.rs @@ -245,4 +245,27 @@ where self.elements.push(element.into()); self } + + /// Applies a transformation to the produced message of all the row's [`Element`]. + pub fn map( + self, + f: impl Fn(Message) -> B + 'a + Clone, + ) -> GridRow<'a, B, Theme, Renderer> + where + Message: 'a, + Theme: 'a, + Renderer: renderer::Renderer + 'a, + B: 'a, + { + GridRow { + elements: self + .elements + .into_iter() + .map(|element| { + let f = f.clone(); + element.map(move |message| f(message)) + }) + .collect(), + } + } } From c2beaa0a2edee635882721a38b90223165b5854a Mon Sep 17 00:00:00 2001 From: MYT Date: Fri, 24 Jan 2025 09:28:21 +0000 Subject: [PATCH 2/2] apply fmt suggestion on GridRow map --- src/widget/grid/types.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/widget/grid/types.rs b/src/widget/grid/types.rs index e3e5837d..c2a6d04f 100644 --- a/src/widget/grid/types.rs +++ b/src/widget/grid/types.rs @@ -247,10 +247,7 @@ where } /// Applies a transformation to the produced message of all the row's [`Element`]. - pub fn map( - self, - f: impl Fn(Message) -> B + 'a + Clone, - ) -> GridRow<'a, B, Theme, Renderer> + pub fn map(self, f: impl Fn(Message) -> B + 'a + Clone) -> GridRow<'a, B, Theme, Renderer> where Message: 'a, Theme: 'a,