Refactor alignment types into an alignment module

This commit is contained in:
Héctor Ramón Jiménez 2021-09-20 15:09:55 +07:00
parent 5fae6e59ff
commit a0ad399622
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
54 changed files with 402 additions and 377 deletions

View file

@ -1,4 +1,4 @@
use crate::{CrossAlign, Point, Rectangle, Size};
use crate::{Alignment, 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: CrossAlign,
vertical_alignment: CrossAlign,
horizontal_alignment: Alignment,
vertical_alignment: Alignment,
space: Size,
) {
match horizontal_alignment {
CrossAlign::Start => {}
CrossAlign::Center => {
Alignment::Start => {}
Alignment::Center => {
self.bounds.x += (space.width - self.bounds.width) / 2.0;
}
CrossAlign::End => {
Alignment::End => {
self.bounds.x += space.width - self.bounds.width;
}
CrossAlign::Fill => {
Alignment::Fill => {
self.bounds.width = space.width;
}
}
match vertical_alignment {
CrossAlign::Start => {}
CrossAlign::Center => {
Alignment::Start => {}
Alignment::Center => {
self.bounds.y += (space.height - self.bounds.height) / 2.0;
}
CrossAlign::End => {
Alignment::End => {
self.bounds.y += space.height - self.bounds.height;
}
CrossAlign::Fill => {
Alignment::Fill => {
self.bounds.height = space.height;
}
}