From 5fae6e59ffbc5913761df638dc7f0c35b7f43bc9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 20 Sep 2021 14:33:02 +0700 Subject: Introduce and use `CrossAlign` enum for `Column` and `Row` --- native/src/widget/container.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'native/src/widget/container.rs') diff --git a/native/src/widget/container.rs b/native/src/widget/container.rs index 69aee64d..ae18db25 100644 --- a/native/src/widget/container.rs +++ b/native/src/widget/container.rs @@ -5,8 +5,8 @@ use crate::event::{self, Event}; use crate::layout; use crate::overlay; use crate::{ - Align, Clipboard, Element, Hasher, Layout, Length, Padding, Point, - Rectangle, Widget, + Align, Clipboard, CrossAlign, Element, Hasher, Layout, Length, Padding, + Point, Rectangle, Widget, }; use std::u32; @@ -143,7 +143,11 @@ where self.padding.left.into(), self.padding.top.into(), )); - content.align(self.horizontal_alignment, self.vertical_alignment, size); + content.align( + CrossAlign::from(self.horizontal_alignment), + CrossAlign::from(self.vertical_alignment), + size, + ); layout::Node::with_children(size.pad(self.padding), vec![content]) } -- cgit From a0ad3996225601aaa1ebe051cba115374b55c80e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 20 Sep 2021 15:09:55 +0700 Subject: Refactor alignment types into an `alignment` module --- native/src/widget/container.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'native/src/widget/container.rs') diff --git a/native/src/widget/container.rs b/native/src/widget/container.rs index ae18db25..0e86ab62 100644 --- a/native/src/widget/container.rs +++ b/native/src/widget/container.rs @@ -1,12 +1,13 @@ //! Decorate content and apply alignment. use std::hash::Hash; +use crate::alignment::{self, Alignment}; use crate::event::{self, Event}; use crate::layout; use crate::overlay; use crate::{ - Align, Clipboard, CrossAlign, Element, Hasher, Layout, Length, Padding, - Point, Rectangle, Widget, + Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle, + Widget, }; use std::u32; @@ -21,8 +22,8 @@ pub struct Container<'a, Message, Renderer: self::Renderer> { height: Length, max_width: u32, max_height: u32, - horizontal_alignment: Align, - vertical_alignment: Align, + horizontal_alignment: alignment::Horizontal, + vertical_alignment: alignment::Vertical, style: Renderer::Style, content: Element<'a, Message, Renderer>, } @@ -42,8 +43,8 @@ where height: Length::Shrink, max_width: u32::MAX, max_height: u32::MAX, - horizontal_alignment: Align::Start, - vertical_alignment: Align::Start, + horizontal_alignment: alignment::Horizontal::Left, + vertical_alignment: alignment::Vertical::Top, style: Renderer::Style::default(), content: content.into(), } @@ -80,26 +81,26 @@ where } /// Sets the content alignment for the horizontal axis of the [`Container`]. - pub fn align_x(mut self, alignment: Align) -> Self { + pub fn align_x(mut self, alignment: alignment::Horizontal) -> Self { self.horizontal_alignment = alignment; self } /// Sets the content alignment for the vertical axis of the [`Container`]. - pub fn align_y(mut self, alignment: Align) -> Self { + pub fn align_y(mut self, alignment: alignment::Vertical) -> Self { self.vertical_alignment = alignment; self } /// Centers the contents in the horizontal axis of the [`Container`]. pub fn center_x(mut self) -> Self { - self.horizontal_alignment = Align::Center; + self.horizontal_alignment = alignment::Horizontal::Center; self } /// Centers the contents in the vertical axis of the [`Container`]. pub fn center_y(mut self) -> Self { - self.vertical_alignment = Align::Center; + self.vertical_alignment = alignment::Vertical::Center; self } @@ -144,8 +145,8 @@ where self.padding.top.into(), )); content.align( - CrossAlign::from(self.horizontal_alignment), - CrossAlign::from(self.vertical_alignment), + Alignment::from(self.horizontal_alignment), + Alignment::from(self.vertical_alignment), size, ); -- cgit