aura-gui 0.3.5

UI nativa acelerada por GPU para escritorio, Android e iOS, en un solo crate: estilo tipo Tailwind, componentes, sombras, animaciones y agentes de IA. Reposo a cero. Licencia AGPL-3.0 o comercial.
//! Traducción a Taffy de las propiedades poco frecuentes de [`StyleExtra`]: sentido inverso, alineación del
//! contenido y cuadrícula.

use crate::view::style::Style;
use crate::view::style_extra::{AUTO_BOTTOM, AUTO_LEFT, AUTO_RIGHT, AUTO_TOP, GridStyle};
use taffy::prelude::*;

/// Aplica sobre `out` lo que `style.extra` añade al estilo base ya traducido.
pub(crate) fn apply(style: &Style, out: &mut taffy::Style) {
    let Some(extra) = style.extra.as_deref() else { return };
    if extra.reverse == Some(true) {
        out.flex_direction = match out.flex_direction {
            FlexDirection::Column | FlexDirection::ColumnReverse => FlexDirection::ColumnReverse,
            _ => FlexDirection::RowReverse,
        };
    }
    if let Some(content) = extra.align_content {
        out.align_content = crate::view::layout::justify(content);
    }
    grid(&extra.grid, out);
    let auto = |bit: u8| extra.margin_auto & bit != 0;
    for (bit, side) in [
        (AUTO_TOP, &mut out.margin.top),
        (AUTO_RIGHT, &mut out.margin.right),
        (AUTO_BOTTOM, &mut out.margin.bottom),
        (AUTO_LEFT, &mut out.margin.left),
    ] {
        if auto(bit) {
            *side = LengthPercentageAuto::auto();
        }
    }
}

fn grid(grid: &GridStyle, out: &mut taffy::Style) {
    if grid.is_grid() && out.display != Display::None {
        out.display = Display::Grid;
        if let Some(cols) = grid.cols {
            out.grid_template_columns = vec![repeat(cols, vec![fr(1.0)])];
        }
        if let Some(rows) = grid.rows {
            out.grid_template_rows = vec![repeat(rows, vec![fr(1.0)])];
        }
    }
    if grid.flow_col == Some(true) {
        out.grid_auto_flow = GridAutoFlow::Column;
    }
    out.grid_column = placement(grid.col_start, grid.col_span);
    out.grid_row = placement(grid.row_start, grid.row_span);
}

/// `col-start-2 col-span-3`: línea de inicio opcional y cuántas pistas ocupa.
fn placement(start: Option<i16>, span_by: Option<u16>) -> Line<GridPlacement> {
    Line { start: start.map_or(GridPlacement::Auto, line), end: span_by.map_or(GridPlacement::Auto, span) }
}