oxipdf-ir 0.1.0

Intermediate representation types for the oxipdf PDF engine
Documentation
//! CSS Grid style properties.

use crate::units::{LengthPercentage, Pt};

/// Grid-specific style properties.
///
/// Only meaningful when the parent node has `Display::Grid`.
#[derive(Debug, Clone, PartialEq)]
pub struct GridStyle {
    /// Explicit column track sizing.
    pub template_columns: Vec<TrackSize>,
    /// Explicit row track sizing.
    pub template_rows: Vec<TrackSize>,
    /// Sizing for implicitly created columns.
    pub auto_columns: TrackSize,
    /// Sizing for implicitly created rows.
    pub auto_rows: TrackSize,
    /// Auto-placement algorithm direction.
    pub auto_flow: GridAutoFlow,
    /// Column gap between grid cells.
    pub column_gap: LengthPercentage,
    /// Row gap between grid cells.
    pub row_gap: LengthPercentage,

    // --- Per-item grid placement ---
    /// Column start line.
    pub column_start: GridLine,
    /// Column end line.
    pub column_end: GridLine,
    /// Row start line.
    pub row_start: GridLine,
    /// Row end line.
    pub row_end: GridLine,
}

impl Default for GridStyle {
    fn default() -> Self {
        Self {
            template_columns: Vec::new(),
            template_rows: Vec::new(),
            auto_columns: TrackSize::Auto,
            auto_rows: TrackSize::Auto,
            auto_flow: GridAutoFlow::Row,
            column_gap: LengthPercentage::ZERO,
            row_gap: LengthPercentage::ZERO,
            column_start: GridLine::Auto,
            column_end: GridLine::Auto,
            row_start: GridLine::Auto,
            row_end: GridLine::Auto,
        }
    }
}

/// Size of a grid track (column or row).
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub enum TrackSize {
    /// Fixed length.
    Length(Pt),
    /// Percentage of grid container dimension.
    Percent(f64),
    /// Fractional unit — distributes remaining space proportionally.
    Fr(f64),
    /// Size to fit the largest minimum-size content.
    MinContent,
    /// Size to fit the largest maximum-size content.
    MaxContent,
    /// Automatic sizing.
    #[default]
    Auto,
}

/// Grid auto-placement direction.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum GridAutoFlow {
    #[default]
    Row,
    Column,
    RowDense,
    ColumnDense,
}

/// A grid line specifier for item placement.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum GridLine {
    /// Automatic placement by the grid algorithm.
    #[default]
    Auto,
    /// A specific grid line number (1-indexed, negative counts from end).
    Line(i32),
    /// Span across N tracks from the opposite edge.
    Span(u32),
}