use std::num::NonZeroUsize;
use super::{
ComputedLengthPercentage, ResolveViewportLengths, RootFontMetricLengthBasis,
ViewportLengthBasis,
};
use crate::units::LayoutLength;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum ColumnCount {
Auto,
Count(NonZeroUsize),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct FlexLineCount(NonZeroUsize);
impl FlexLineCount {
pub(crate) const ONE: Self = Self(NonZeroUsize::MIN);
pub(crate) const fn get(self) -> usize {
self.0.get()
}
pub(crate) const fn new(count: NonZeroUsize) -> Self {
Self(count)
}
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum ComputedColumnWidth {
Auto,
Length(ComputedLengthPercentage),
}
impl ComputedColumnWidth {
pub(crate) const AUTO: Self = Self::Auto;
pub(crate) fn scale_fixed_length_components(&mut self, factor: f32) {
if let Self::Length(length) = self {
length.scale_fixed_length_components(factor);
}
}
pub(crate) fn resolve_font_metric_lengths(&mut self, ch_advance: LayoutLength) {
if let Self::Length(length) = self {
length.resolve_font_metric_lengths(ch_advance);
}
}
pub(crate) fn resolve_root_font_metric_lengths(&mut self, basis: RootFontMetricLengthBasis) {
if let Self::Length(length) = self {
length.resolve_root_font_metric_lengths(basis);
}
}
pub(crate) fn requires_root_font_metrics(&self) -> bool {
matches!(self, Self::Length(length) if length.requires_root_font_metrics())
}
pub(crate) fn requires_ch_advance(&self) -> bool {
matches!(self, Self::Length(length) if length.requires_ch_advance())
}
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum ComputedColumnHeight {
Auto,
Length(ComputedLengthPercentage),
}
impl ComputedColumnHeight {
pub(crate) const AUTO: Self = Self::Auto;
pub(crate) fn scale_fixed_length_components(&mut self, factor: f32) {
if let Self::Length(length) = self {
length.scale_fixed_length_components(factor);
}
}
pub(crate) fn resolve_font_metric_lengths(&mut self, ch_advance: LayoutLength) {
if let Self::Length(length) = self {
length.resolve_font_metric_lengths(ch_advance);
}
}
pub(crate) fn resolve_root_font_metric_lengths(&mut self, basis: RootFontMetricLengthBasis) {
if let Self::Length(length) = self {
length.resolve_root_font_metric_lengths(basis);
}
}
pub(crate) fn requires_root_font_metrics(&self) -> bool {
matches!(self, Self::Length(length) if length.requires_root_font_metrics())
}
pub(crate) fn requires_ch_advance(&self) -> bool {
matches!(self, Self::Length(length) if length.requires_ch_advance())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum ColumnWrap {
Auto,
Nowrap,
Wrap,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum ColumnFill {
Balance,
BalanceAll,
Auto,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum ColumnSpan {
None,
All,
}
impl ResolveViewportLengths for ComputedColumnWidth {
fn resolve_viewport_lengths(&mut self, basis: ViewportLengthBasis) {
if let Self::Length(length) = self {
length.resolve_viewport_lengths(basis);
}
}
}
impl ResolveViewportLengths for ComputedColumnHeight {
fn resolve_viewport_lengths(&mut self, basis: ViewportLengthBasis) {
if let Self::Length(length) = self {
length.resolve_viewport_lengths(basis);
}
}
}