Introduce and use CrossAlign enum for Column and Row
This commit is contained in:
parent
95e4791a1e
commit
5fae6e59ff
33 changed files with 166 additions and 115 deletions
|
|
@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue