Skip to content

Commit

Permalink
Add map support to GridRow
Browse files Browse the repository at this point in the history
  • Loading branch information
mytdragon committed Jan 23, 2025
1 parent 0d85cfb commit 16b3fe8
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/widget/grid/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B>(
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(),
}
}
}

0 comments on commit 16b3fe8

Please sign in to comment.