Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add map support to GridRow #317

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/widget/grid/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
pub(super) row_heights: Vec<Length>,
}

impl<'a, Message, Theme, Renderer> Default for Grid<'a, Message, Theme, Renderer>

Check warning on line 24 in src/widget/grid/types.rs

View workflow job for this annotation

GitHub Actions / all

the following explicit lifetimes could be elided: 'a
where
Renderer: renderer::Renderer,
{
Expand Down Expand Up @@ -207,7 +207,7 @@
pub(crate) elements: Vec<Element<'a, Message, Theme, Renderer>>,
}

impl<'a, Message, Theme, Renderer> Default for GridRow<'a, Message, Theme, Renderer>

Check warning on line 210 in src/widget/grid/types.rs

View workflow job for this annotation

GitHub Actions / all

the following explicit lifetimes could be elided: 'a
where
Renderer: renderer::Renderer,
{
Expand Down Expand Up @@ -245,4 +245,24 @@
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(),
}
}
}
Loading