API ColumnDef

ColumnDef

pub struct ColumnDef {
    pub key: String,
    pub label: String,
    pub width: f64,
    pub format: Option<CellFormat>,
    pub editor: Option<CellEditor>,
    pub validator: Option<CellValidator>,
}
ChampTypeDescription
keyStringIdentifiant unique, utilisé pour rechercher les valeurs de cellules
labelStringTexte affiché dans l'en-tête de colonne
widthf64Largeur en pixels logiques
formatOption<CellFormat>Format d'affichage (None = texte brut)
editorOption<CellEditor>Type d'éditeur (None = champ texte par défaut)
validatorOption<CellValidator>Validateur optionnel appelé avant la validation d'une édition

Constructeur

pub fn new(key: impl Into<String>, label: impl Into<String>, width: f64) -> Self

Crée une colonne sans format et sans surcharge d'éditeur.

CellFormat

#[non_exhaustive]
pub enum CellFormat {
    Number { decimal_places: u8, thousands_sep: Option<char>, decimal_sep: char },
    Percent { decimal_places: u8 },
    Currency { symbol: String, decimal_places: u8, thousands_sep: Option<char>, symbol_after: bool },
    Boolean { true_label: String, false_label: String },
    Custom(Rc<dyn Fn(&str) -> FormattedCell>),
    Image { base_url: Option<String>, border_radius: f64, padding: f64 },
    ImageText { base_url: String, suffix: String, image_size: f64, border_radius: f64, gap: f64 },
}

Méthodes

MéthodeRetourDescription
is_image()boolVrai pour la variante Image
is_image_text()boolVrai pour la variante ImageText

FormattedCell

pub struct FormattedCell {
    pub text: String,
    pub align: Option<CellAlign>,
    pub bold: bool,
    pub color: Option<[u8; 4]>,  // RGBA
}

CellAlign

pub enum CellAlign {
    Left,    // par défaut
    Center,
    Right,
}

CellValidator

pub struct CellValidator(pub Rc<dyn Fn(&str) -> Result<(), String>>);

Callback de validation par colonne. Utilisez CellValidator::new pour en créer un :

CellValidator::new(|v| {
    v.parse::<f64>()
        .map(|_| ())
        .map_err(|_| "pas un nombre".to_string())
})
MéthodeDescription
new(f)Encapsule une closure en validateur
validate(value: &str)Exécute le validateur ; retourne Ok(()) ou Err(message)

Voir Validation pour le guide complet.

CellEditor

#[non_exhaustive]
pub enum CellEditor {
    Text,
    Select { options: Vec<SelectOption> },
}

SelectOption

pub struct SelectOption {
    pub value: String,
    pub label: String,
    pub icon: Option<String>,
}

ColumnOffsets

pub struct ColumnOffsets {
    pub offsets: Vec<f64>,
    pub total_width: f64,
}
MéthodeDescription
compute(columns: &[ColumnDef])Construit les offsets à partir des largeurs de colonnes
hit_column(x: f64, columns: &[ColumnDef])Trouve la colonne à la position x