use core::fmt::Debug;
use crate::{
algo::grid::track_size::TrackSize, DefLength, EdgeOption, LayoutTreeNode, OptionNum, Size,
};
#[derive(Clone, PartialEq)]
pub(crate) struct GridLayoutItem<'a, T: LayoutTreeNode> {
pub(crate) row: usize,
pub(crate) column: usize,
pub(crate) node: &'a T,
pub(crate) margin: EdgeOption<T::Length>,
pub(crate) css_size: Size<OptionNum<T::Length>>,
pub(crate) track_size: Size<OptionNum<T::Length>>,
pub(crate) min_content_size: Option<Size<T::Length>>,
pub(crate) max_content_size: Option<Size<T::Length>>,
pub(crate) computed_size: Size<T::Length>,
}
impl<'a, T: LayoutTreeNode> GridLayoutItem<'a, T> {
pub(crate) fn new(
row: usize,
column: usize,
node: &'a T,
margin: EdgeOption<T::Length>,
css_size: Size<OptionNum<T::Length>>,
track_size: Size<OptionNum<T::Length>>,
) -> Self {
Self {
row,
column,
node,
margin,
css_size,
track_size,
min_content_size: None,
max_content_size: None,
computed_size: Size::zero(),
}
}
#[inline(always)]
pub(crate) fn row(&self) -> usize {
self.row
}
#[inline(always)]
pub(crate) fn column(&self) -> usize {
self.column
}
pub(crate) fn track_inline_size(&self) -> OptionNum<T::Length> {
self.track_size.width.clone()
}
pub(crate) fn track_block_size(&self) -> OptionNum<T::Length> {
self.track_size.height.clone()
}
pub(crate) fn min_content_size(&self) -> Option<&Size<T::Length>> {
self.min_content_size.as_ref()
}
pub(crate) fn set_min_content_size(&mut self, min_content_size: Option<Size<T::Length>>) {
self.min_content_size = min_content_size;
}
pub(crate) fn max_content_size(&self) -> Option<&Size<T::Length>> {
self.max_content_size.as_ref()
}
pub(crate) fn set_max_content_size(&mut self, max_content_size: Option<Size<T::Length>>) {
self.max_content_size = max_content_size;
}
pub(crate) fn computed_size(&self) -> Size<T::Length> {
self.computed_size
}
pub(crate) fn set_computed_size(&mut self, computed_size: Size<T::Length>) {
self.computed_size = computed_size;
}
}
#[derive(Clone, PartialEq)]
pub(crate) struct GridItem<'a, T: LayoutTreeNode> {
row: usize,
column: usize,
pub(crate) node: &'a T,
pub(crate) track_block_size: TrackSize<T>,
pub(crate) track_inline_size: TrackSize<T>,
}
impl<'a, T: LayoutTreeNode> Debug for GridItem<'a, T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
f,
"GridItem {{ row: {}, column: {}, track_block_size: {:?}, track_inline_size: {:?} }}",
self.row, self.column, self.track_block_size, self.track_inline_size
)
}
}
impl<'a, T: LayoutTreeNode> GridItem<'a, T> {
pub fn new(node: &'a T, row: usize, column: usize) -> Self {
Self {
row,
column,
node,
track_block_size: TrackSize::Original(DefLength::Auto),
track_inline_size: TrackSize::Original(DefLength::Auto),
}
}
#[inline(always)]
pub(crate) fn row(&self) -> usize {
self.row
}
#[inline(always)]
pub(crate) fn column(&self) -> usize {
self.column
}
pub(crate) fn update_track_block_size(&mut self, track_block_size: TrackSize<T>) {
self.track_block_size = track_block_size;
}
pub(crate) fn update_track_inline_size(&mut self, track_inline_size: TrackSize<T>) {
self.track_inline_size = track_inline_size;
}
pub(crate) fn fixed_track_block_size(&self) -> Option<&OptionNum<T::Length>> {
match &self.track_block_size {
TrackSize::Fixed(size) => Some(size),
_ => None,
}
}
pub(crate) fn fixed_track_inline_size(&self) -> Option<&OptionNum<T::Length>> {
match &self.track_inline_size {
TrackSize::Fixed(size) => Some(size),
_ => None,
}
}
}