From 65e8fed37d22824e9c45fff6bf580fe040b2a197 Mon Sep 17 00:00:00 2001 From: mtkennerly Date: Thu, 20 Mar 2025 18:31:24 -0400 Subject: [PATCH] Allow custom vertical spacing for wrapped rows --- widget/src/row.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/widget/src/row.rs b/widget/src/row.rs index 5ffeab49..b9fd2569 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -167,7 +167,10 @@ where /// /// The original alignment of the [`Row`] is preserved per row wrapped. pub fn wrap(self) -> Wrapping<'a, Message, Theme, Renderer> { - Wrapping { row: self } + Wrapping { + row: self, + vertical_spacing: None, + } } } @@ -372,6 +375,15 @@ pub struct Wrapping< Renderer = crate::Renderer, > { row: Row<'a, Message, Theme, Renderer>, + vertical_spacing: Option, +} + +impl Wrapping<'_, Message, Theme, Renderer> { + /// Sets the vertical spacing _between_ lines. + pub fn vertical_spacing(mut self, amount: impl Into) -> Self { + self.vertical_spacing = Some(amount.into().0); + self + } } impl Widget @@ -403,6 +415,7 @@ where .shrink(self.row.padding); let spacing = self.row.spacing; + let vertical_spacing = self.vertical_spacing.unwrap_or(spacing); let max_width = limits.max().width; let mut children: Vec = Vec::new(); @@ -447,7 +460,7 @@ where align(row_start..i, row_height, &mut children); - y += row_height + spacing; + y += row_height + vertical_spacing; x = 0.0; row_start = i; row_height = 0.0;