use crate::{
components::{Column, Row},
layout::Alignment,
node::{Element, dimension::Dimension},
};
pub(super) const FILL_WIDTH: Dimension = Dimension::Pct(100.0);
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum BlockWidth {
Fill,
Fit,
}
impl BlockWidth {
pub(super) fn new(fit_content: bool) -> Self {
if fit_content { Self::Fit } else { Self::Fill }
}
pub(super) fn blocks(self, column: Column) -> Column {
match self {
Self::Fill => column.width(FILL_WIDTH),
Self::Fit => column.max_width(FILL_WIDTH).align_items(Alignment::Stretch),
}
}
pub(super) fn row(self, row: Row) -> Row {
match self {
Self::Fill => row.width(FILL_WIDTH),
Self::Fit => row,
}
}
pub(super) fn row_body(self, column: Column) -> Column {
match self {
Self::Fill => column.flex(1.0),
Self::Fit => column
.flex_shrink(1.0)
.max_width(FILL_WIDTH)
.align_items(Alignment::Stretch),
}
}
pub(super) fn leaf(self, element: impl Into<Element>) -> Element {
let element = element.into();
match self {
Self::Fill => element.map_node(|node| node.width(FILL_WIDTH)),
Self::Fit => element,
}
}
}