ColumnDef API

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>,
}
FieldTypeDescription
keyStringUnique identifier, used to look up cell values
labelStringDisplay text in the column header
widthf64Width in logical pixels
formatOption<CellFormat>Display format (None = raw text)
editorOption<CellEditor>Editor type (None = default text input)
validatorOption<CellValidator>Optional validator called before committing an edit

Constructor

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

Creates a column with no format and no editor override.

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 },
}

Methods

MethodReturnsDescription
is_image()boolTrue for Image variant
is_image_text()boolTrue for ImageText variant

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,    // default
    Center,
    Right,
}

CellValidator

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

A per-column validation callback. Call CellValidator::new to construct one:

CellValidator::new(|v| {
    v.parse::<f64>()
        .map(|_| ())
        .map_err(|_| "not a number".to_string())
})
MethodDescription
new(f)Wrap a closure as a validator
validate(value: &str)Run the validator; returns Ok(()) or Err(message)

See Validation for the full feature guide.

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,
}
MethodDescription
compute(columns: &[ColumnDef])Build offsets from column widths
hit_column(x: f64, columns: &[ColumnDef])Find column at x position