diff options
author | 2024-07-12 15:11:30 +0200 | |
---|---|---|
committer | 2024-07-12 15:14:43 +0200 | |
commit | f9dd5cbb099bbe44a57b6369be54a442363b7a8d (patch) | |
tree | fe16084bc47faadc32d698aa446ea202f7949a4c /widget/src/row.rs | |
parent | be06060117da061ad8cad94ab0830c06def6b147 (diff) | |
download | iced-f9dd5cbb099bbe44a57b6369be54a442363b7a8d.tar.gz iced-f9dd5cbb099bbe44a57b6369be54a442363b7a8d.tar.bz2 iced-f9dd5cbb099bbe44a57b6369be54a442363b7a8d.zip |
Introduce helper methods for alignment for all widgets
Diffstat (limited to '')
-rw-r--r-- | widget/src/row.rs | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/widget/src/row.rs b/widget/src/row.rs index c8fcdb61..129feb7e 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -1,4 +1,5 @@ //! Distribute content horizontally. +use crate::core::alignment::{self, Alignment}; use crate::core::event::{self, Event}; use crate::core::layout::{self, Layout}; use crate::core::mouse; @@ -6,8 +7,8 @@ use crate::core::overlay; use crate::core::renderer; use crate::core::widget::{Operation, Tree}; use crate::core::{ - Alignment, Clipboard, Element, Length, Padding, Pixels, Rectangle, Shell, - Size, Vector, Widget, + Clipboard, Element, Length, Padding, Pixels, Rectangle, Shell, Size, + Vector, Widget, }; /// A container that distributes its contents horizontally. @@ -17,7 +18,7 @@ pub struct Row<'a, Message, Theme = crate::Theme, Renderer = crate::Renderer> { padding: Padding, width: Length, height: Length, - align_items: Alignment, + align: Alignment, clip: bool, children: Vec<Element<'a, Message, Theme, Renderer>>, } @@ -60,7 +61,7 @@ where padding: Padding::ZERO, width: Length::Shrink, height: Length::Shrink, - align_items: Alignment::Start, + align: Alignment::Start, clip: false, children, } @@ -94,9 +95,24 @@ where self } + /// Centers the contents of the [`Row`] vertically. + pub fn center_y(self) -> Self { + self.align_y(Alignment::Center) + } + + /// Aligns the contents of the [`Row`] to the top. + pub fn align_top(self) -> Self { + self.align_y(alignment::top()) + } + + /// Aligns the contents of the [`Row`] to the bottom. + pub fn align_bottom(self) -> Self { + self.align_y(alignment::bottom()) + } + /// Sets the vertical alignment of the contents of the [`Row`] . - pub fn align_items(mut self, align: Alignment) -> Self { - self.align_items = align; + pub fn align_y(mut self, align: impl Into<alignment::Vertical>) -> Self { + self.align = Alignment::from(align.into()); self } @@ -199,7 +215,7 @@ where self.height, self.padding, self.spacing, - self.align_items, + self.align, &self.children, &mut tree.children, ) |