From 7a6421a3e297a3e62ce344cd4e31eca55bf0d3cf Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Wed, 29 May 2024 23:55:50 +0200 Subject: [PATCH] feat(flex-row): add justify_content method --- src/widget/flex_row/layout.rs | 5 ++++- src/widget/flex_row/widget.rs | 5 +++++ src/widget/mod.rs | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/widget/flex_row/layout.rs b/src/widget/flex_row/layout.rs index df1c862f..cf80548e 100644 --- a/src/widget/flex_row/layout.rs +++ b/src/widget/flex_row/layout.rs @@ -8,7 +8,7 @@ use iced_core::{Length, Padding, Point, Size}; use taffy::geometry::Rect; use taffy::style::{AlignItems, Dimension, Display, Style}; use taffy::style_helpers::length; -use taffy::TaffyTree; +use taffy::{AlignContent, TaffyTree}; #[allow(clippy::too_many_lines)] pub fn resolve( @@ -18,6 +18,7 @@ pub fn resolve( padding: Padding, column_spacing: f32, row_spacing: f32, + justify_content: Option, tree: &mut [Tree], ) -> Node { let limits = limits.shrink(padding); @@ -43,6 +44,8 @@ pub fn resolve( height: Dimension::Auto, }, + justify_content, + padding: Rect { left: length(padding.left), right: length(padding.right), diff --git a/src/widget/flex_row/widget.rs b/src/widget/flex_row/widget.rs index 2a445fae..2394d078 100644 --- a/src/widget/flex_row/widget.rs +++ b/src/widget/flex_row/widget.rs @@ -27,6 +27,9 @@ pub struct FlexRow<'a, Message> { width: Length, /// Sets the max width max_width: f32, + /// Defines how the content will be justified. + #[setters(into)] + justify_content: Option, } impl<'a, Message> FlexRow<'a, Message> { @@ -38,6 +41,7 @@ impl<'a, Message> FlexRow<'a, Message> { row_spacing: 4, width: Length::Shrink, max_width: f32::INFINITY, + justify_content: None, } } @@ -83,6 +87,7 @@ impl<'a, Message: 'static + Clone> Widget self.padding, f32::from(self.column_spacing), f32::from(self.row_spacing), + self.justify_content, &mut tree.children, ) } diff --git a/src/widget/mod.rs b/src/widget/mod.rs index 280ef26b..9530d060 100644 --- a/src/widget/mod.rs +++ b/src/widget/mod.rs @@ -231,6 +231,8 @@ pub use icon::{icon, Icon}; #[cfg(feature = "animated-image")] pub mod frames; +pub use taffy::JustifyContent; + pub mod list; #[doc(inline)] pub use list::{list_column, ListColumn};