diff options
author | 2021-09-20 14:33:02 +0700 | |
---|---|---|
committer | 2021-09-20 15:12:43 +0700 | |
commit | 5fae6e59ffbc5913761df638dc7f0c35b7f43bc9 (patch) | |
tree | 02cbacf17780d1df9e37b38a33c0f882ab9312d7 /native/src | |
parent | 95e4791a1e4611f0db703ac2911f56b391469b5f (diff) | |
download | iced-5fae6e59ffbc5913761df638dc7f0c35b7f43bc9.tar.gz iced-5fae6e59ffbc5913761df638dc7f0c35b7f43bc9.tar.bz2 iced-5fae6e59ffbc5913761df638dc7f0c35b7f43bc9.zip |
Introduce and use `CrossAlign` enum for `Column` and `Row`
Diffstat (limited to 'native/src')
-rw-r--r-- | native/src/layout/flex.rs | 30 | ||||
-rw-r--r-- | native/src/layout/node.rs | 22 | ||||
-rw-r--r-- | native/src/lib.rs | 4 | ||||
-rw-r--r-- | native/src/widget/checkbox.rs | 4 | ||||
-rw-r--r-- | native/src/widget/column.rs | 8 | ||||
-rw-r--r-- | native/src/widget/container.rs | 10 | ||||
-rw-r--r-- | native/src/widget/radio.rs | 6 | ||||
-rw-r--r-- | native/src/widget/row.rs | 8 | ||||
-rw-r--r-- | native/src/widget/scrollable.rs | 6 | ||||
-rw-r--r-- | native/src/widget/toggler.rs | 6 |
10 files changed, 58 insertions, 46 deletions
diff --git a/native/src/layout/flex.rs b/native/src/layout/flex.rs index 52b48fec..dfb5288b 100644 --- a/native/src/layout/flex.rs +++ b/native/src/layout/flex.rs @@ -19,7 +19,7 @@ use crate::{ layout::{Limits, Node}, - Align, Element, Padding, Point, Size, + CrossAlign, Element, Padding, Point, Size, }; /// The main axis of a flex layout. @@ -65,7 +65,7 @@ pub fn resolve<Message, Renderer>( limits: &Limits, padding: Padding, spacing: f32, - align_items: Align, + align_items: CrossAlign, items: &[Element<'_, Message, Renderer>], ) -> Node where @@ -82,7 +82,7 @@ where let mut nodes: Vec<Node> = Vec::with_capacity(items.len()); nodes.resize(items.len(), Node::default()); - if align_items == Align::Fill { + if align_items == CrossAlign::Fill { let mut fill_cross = axis.cross(limits.min()); items.iter().for_each(|child| { @@ -116,13 +116,13 @@ where .fill_factor(); if fill_factor == 0 { - let (min_width, min_height) = if align_items == Align::Fill { + let (min_width, min_height) = if align_items == CrossAlign::Fill { axis.pack(0.0, cross) } else { axis.pack(0.0, 0.0) }; - let (max_width, max_height) = if align_items == Align::Fill { + let (max_width, max_height) = if align_items == CrossAlign::Fill { axis.pack(available, cross) } else { axis.pack(available, max_cross) @@ -138,7 +138,7 @@ where available -= axis.main(size); - if align_items != Align::Fill { + if align_items != CrossAlign::Fill { cross = cross.max(axis.cross(size)); } @@ -165,13 +165,13 @@ where max_main }; - let (min_width, min_height) = if align_items == Align::Fill { + let (min_width, min_height) = if align_items == CrossAlign::Fill { axis.pack(min_main, cross) } else { axis.pack(min_main, axis.cross(limits.min())) }; - let (max_width, max_height) = if align_items == Align::Fill { + let (max_width, max_height) = if align_items == CrossAlign::Fill { axis.pack(max_main, cross) } else { axis.pack(max_main, max_cross) @@ -184,7 +184,7 @@ where let layout = child.layout(renderer, &child_limits); - if align_items != Align::Fill { + if align_items != CrossAlign::Fill { cross = cross.max(axis.cross(layout.size())); } @@ -206,10 +206,18 @@ where match axis { Axis::Horizontal => { - node.align(Align::Start, align_items, Size::new(0.0, cross)); + node.align( + CrossAlign::Start, + align_items, + Size::new(0.0, cross), + ); } Axis::Vertical => { - node.align(align_items, Align::Start, Size::new(cross, 0.0)); + node.align( + align_items, + CrossAlign::Start, + Size::new(cross, 0.0), + ); } } diff --git a/native/src/layout/node.rs b/native/src/layout/node.rs index bee5e64e..2239a654 100644 --- a/native/src/layout/node.rs +++ b/native/src/layout/node.rs @@ -1,4 +1,4 @@ -use crate::{Align, Point, Rectangle, Size}; +use crate::{CrossAlign, Point, Rectangle, Size}; /// The bounds of an element and its children. #[derive(Debug, Clone, Default)] @@ -44,32 +44,32 @@ impl Node { /// Aligns the [`Node`] in the given space. pub fn align( &mut self, - horizontal_alignment: Align, - vertical_alignment: Align, + horizontal_alignment: CrossAlign, + vertical_alignment: CrossAlign, space: Size, ) { match horizontal_alignment { - Align::Start => {} - Align::Center => { + CrossAlign::Start => {} + CrossAlign::Center => { self.bounds.x += (space.width - self.bounds.width) / 2.0; } - Align::End => { + CrossAlign::End => { self.bounds.x += space.width - self.bounds.width; } - Align::Fill => { + CrossAlign::Fill => { self.bounds.width = space.width; } } match vertical_alignment { - Align::Start => {} - Align::Center => { + CrossAlign::Start => {} + CrossAlign::Center => { self.bounds.y += (space.height - self.bounds.height) / 2.0; } - Align::End => { + CrossAlign::End => { self.bounds.y += space.height - self.bounds.height; } - Align::Fill => { + CrossAlign::Fill => { self.bounds.height = space.height; } } diff --git a/native/src/lib.rs b/native/src/lib.rs index cb0600e2..cf8b0da5 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -62,8 +62,8 @@ mod debug; mod debug; pub use iced_core::{ - Align, Background, Color, Font, HorizontalAlignment, Length, Padding, - Point, Rectangle, Size, Vector, VerticalAlignment, + Align, Background, Color, CrossAlign, Font, HorizontalAlignment, Length, + Padding, Point, Rectangle, Size, Vector, VerticalAlignment, }; pub use iced_futures::{executor, futures}; diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index 0f21c873..e74515c6 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -8,7 +8,7 @@ use crate::row; use crate::text; use crate::touch; use crate::{ - Align, Clipboard, Color, Element, Hasher, HorizontalAlignment, Layout, + Clipboard, Color, CrossAlign, Element, Hasher, HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text, VerticalAlignment, Widget, }; @@ -138,7 +138,7 @@ where Row::<(), Renderer>::new() .width(self.width) .spacing(self.spacing) - .align_items(Align::Center) + .align_items(CrossAlign::Center) .push( Row::new() .width(Length::Units(self.size)) diff --git a/native/src/widget/column.rs b/native/src/widget/column.rs index 52a2e80c..83e5760a 100644 --- a/native/src/widget/column.rs +++ b/native/src/widget/column.rs @@ -5,7 +5,7 @@ use crate::event::{self, Event}; use crate::layout; use crate::overlay; use crate::{ - Align, Clipboard, Element, Hasher, Layout, Length, Padding, Point, + Clipboard, CrossAlign, Element, Hasher, Layout, Length, Padding, Point, Rectangle, Widget, }; @@ -20,7 +20,7 @@ pub struct Column<'a, Message, Renderer> { height: Length, max_width: u32, max_height: u32, - align_items: Align, + align_items: CrossAlign, children: Vec<Element<'a, Message, Renderer>>, } @@ -41,7 +41,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> { height: Length::Shrink, max_width: u32::MAX, max_height: u32::MAX, - align_items: Align::Start, + align_items: CrossAlign::Start, children, } } @@ -87,7 +87,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> { } /// Sets the horizontal alignment of the contents of the [`Column`] . - pub fn align_items(mut self, align: Align) -> Self { + pub fn align_items(mut self, align: CrossAlign) -> Self { self.align_items = align; self } 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]) } diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs index dee82d1f..1ab51051 100644 --- a/native/src/widget/radio.rs +++ b/native/src/widget/radio.rs @@ -8,8 +8,8 @@ use crate::text; use crate::touch; use crate::{layout, Color}; use crate::{ - Align, Clipboard, Element, Hasher, HorizontalAlignment, Layout, Length, - Point, Rectangle, Row, Text, VerticalAlignment, Widget, + Clipboard, CrossAlign, Element, Hasher, HorizontalAlignment, Layout, + Length, Point, Rectangle, Row, Text, VerticalAlignment, Widget, }; /// A circular button representing a choice. @@ -153,7 +153,7 @@ where Row::<(), Renderer>::new() .width(self.width) .spacing(self.spacing) - .align_items(Align::Center) + .align_items(CrossAlign::Center) .push( Row::new() .width(Length::Units(self.size)) diff --git a/native/src/widget/row.rs b/native/src/widget/row.rs index 9ebc9145..e200e697 100644 --- a/native/src/widget/row.rs +++ b/native/src/widget/row.rs @@ -3,7 +3,7 @@ use crate::event::{self, Event}; use crate::layout; use crate::overlay; use crate::{ - Align, Clipboard, Element, Hasher, Layout, Length, Padding, Point, + Clipboard, CrossAlign, Element, Hasher, Layout, Length, Padding, Point, Rectangle, Widget, }; @@ -19,7 +19,7 @@ pub struct Row<'a, Message, Renderer> { height: Length, max_width: u32, max_height: u32, - align_items: Align, + align_items: CrossAlign, children: Vec<Element<'a, Message, Renderer>>, } @@ -40,7 +40,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { height: Length::Shrink, max_width: u32::MAX, max_height: u32::MAX, - align_items: Align::Start, + align_items: CrossAlign::Start, children, } } @@ -86,7 +86,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { } /// Sets the vertical alignment of the contents of the [`Row`] . - pub fn align_items(mut self, align: Align) -> Self { + pub fn align_items(mut self, align: CrossAlign) -> Self { self.align_items = align; self } diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 68da2e67..0a2155cc 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -6,8 +6,8 @@ use crate::mouse; use crate::overlay; use crate::touch; use crate::{ - Align, Clipboard, Column, Element, Hasher, Layout, Length, Padding, Point, - Rectangle, Size, Vector, Widget, + Clipboard, Column, CrossAlign, Element, Hasher, Layout, Length, Padding, + Point, Rectangle, Size, Vector, Widget, }; use std::{f32, hash::Hash, u32}; @@ -84,7 +84,7 @@ impl<'a, Message, Renderer: self::Renderer> Scrollable<'a, Message, Renderer> { } /// Sets the horizontal alignment of the contents of the [`Scrollable`] . - pub fn align_items(mut self, align_items: Align) -> Self { + pub fn align_items(mut self, align_items: CrossAlign) -> Self { self.content = self.content.align_items(align_items); self } diff --git a/native/src/widget/toggler.rs b/native/src/widget/toggler.rs index 4035276c..34dc52a0 100644 --- a/native/src/widget/toggler.rs +++ b/native/src/widget/toggler.rs @@ -2,8 +2,8 @@ use std::hash::Hash; use crate::{ - event, layout, mouse, row, text, Align, Clipboard, Element, Event, Hasher, - HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text, + event, layout, mouse, row, text, Clipboard, CrossAlign, Element, Event, + Hasher, HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text, VerticalAlignment, Widget, }; @@ -132,7 +132,7 @@ where let mut row = Row::<(), Renderer>::new() .width(self.width) .spacing(self.spacing) - .align_items(Align::Center); + .align_items(CrossAlign::Center); if let Some(label) = &self.label { row = row.push( |