summaryrefslogtreecommitdiffstats
path: root/native/src/layout
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-09-20 14:33:02 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-09-20 15:12:43 +0700
commit5fae6e59ffbc5913761df638dc7f0c35b7f43bc9 (patch)
tree02cbacf17780d1df9e37b38a33c0f882ab9312d7 /native/src/layout
parent95e4791a1e4611f0db703ac2911f56b391469b5f (diff)
downloadiced-5fae6e59ffbc5913761df638dc7f0c35b7f43bc9.tar.gz
iced-5fae6e59ffbc5913761df638dc7f0c35b7f43bc9.tar.bz2
iced-5fae6e59ffbc5913761df638dc7f0c35b7f43bc9.zip
Introduce and use `CrossAlign` enum for `Column` and `Row`
Diffstat (limited to 'native/src/layout')
-rw-r--r--native/src/layout/flex.rs30
-rw-r--r--native/src/layout/node.rs22
2 files changed, 30 insertions, 22 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;
}
}