use crate::Size;
#[derive(Debug, Clone, Copy, Default, PartialEq, PartialOrd)]
pub enum BoxSizing {
Fixed(f32),
#[default]
Shrink,
Flex(u32),
}
#[derive(Debug, Clone, Copy, Default, PartialEq, PartialOrd)]
pub struct BoxConstraints {
pub max_width: Option<f32>,
pub max_height: Option<f32>,
pub min_height: Option<f32>,
pub min_width: Option<f32>,
}
impl BoxConstraints {
pub const fn new() -> Self {
Self {
max_height: None,
max_width: None,
min_height: None,
min_width: None,
}
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, PartialOrd)]
pub struct IntrinsicSize {
pub width: BoxSizing,
pub height: BoxSizing,
}
impl IntrinsicSize {
pub const fn fill() -> Self {
Self {
width: BoxSizing::Flex(1),
height: BoxSizing::Flex(1),
}
}
pub const fn flex(factor: u32) -> Self {
Self {
width: BoxSizing::Flex(factor),
height: BoxSizing::Flex(factor),
}
}
pub const fn shrink() -> Self {
Self {
width: BoxSizing::Shrink,
height: BoxSizing::Shrink,
}
}
pub const fn fixed(width: f32, height: f32) -> Self {
Self {
width: BoxSizing::Fixed(width),
height: BoxSizing::Fixed(height),
}
}
}
impl From<Size> for IntrinsicSize {
fn from(size: Size) -> Self {
IntrinsicSize {
width: BoxSizing::Fixed(size.width),
height: BoxSizing::Fixed(size.height),
}
}
}
macro_rules! impl_constraints {
() => {
pub fn max_width(mut self, width: f32) -> Self {
self.constraints.max_width = Some(width);
self
}
pub fn maximum_height(mut self, height: f32) -> Self {
self.constraints.max_height = Some(height);
self
}
pub fn min_width(mut self, width: f32) -> Self {
self.constraints.min_width = Some(width);
self
}
pub fn min_height(mut self, height: f32) -> Self {
self.constraints.min_height = Some(height);
self
}
pub fn intrinsic_size(mut self, intrinsic_size: $crate::IntrinsicSize) -> Self {
self.intrinsic_size = intrinsic_size;
self
}
};
}
pub(crate) use impl_constraints;