use kurbo::{Axis, Size};
use crate::layout::Length;
#[derive(Copy, Clone, Debug, Default, PartialEq)]
pub struct LayoutSize {
width: Option<Length>,
height: Option<Length>,
}
impl From<Size> for LayoutSize {
#[track_caller]
fn from(size: Size) -> Self {
Self {
width: Some(Length::px(size.width)),
height: Some(Length::px(size.height)),
}
}
}
impl LayoutSize {
pub const NONE: Self = Self {
width: None,
height: None,
};
pub fn new(width: Length, height: Length) -> Self {
Self {
width: Some(width),
height: Some(height),
}
}
pub fn one(axis: Axis, length: Length) -> Self {
match axis {
Axis::Horizontal => Self {
width: Some(length),
height: None,
},
Axis::Vertical => Self {
width: None,
height: Some(length),
},
}
}
pub fn maybe(axis: Axis, length: Option<Length>) -> Self {
let Some(length) = length else {
return Self {
width: None,
height: None,
};
};
Self::one(axis, length)
}
pub const fn length(&self, axis: Axis) -> Option<Length> {
match axis {
Axis::Horizontal => self.width,
Axis::Vertical => self.height,
}
}
}