GridState API

Definition

pub struct GridState {
    pub model: GridModel,
    pub viewport: ViewportState,
    pub selection: SelectionState,
    pub hovered_row: Option<u64>,
    pub sort: Option<SortState>,
    pub edit: Option<EditCell>,
    pub search: SearchState,
    history: UndoHistory,  // private
}

Fields

FieldTypeDescription
modelGridModelColumns, data source, sizing, sort/filter state
viewportViewportStateScroll position (scroll_x, scroll_y), canvas dimensions
selectionSelectionStateAnchor/focus selection, clipboard buffer
hovered_rowOption<u64>Row under the mouse cursor
sortOption<SortState>Active sort column and direction
editOption<EditCell>Cell currently being edited
searchSearchStateActive search query, matches, current index

Constructor

pub fn new(
    model: GridModel,
    viewport_width: f64,
    viewport_height: f64,
) -> Self

Creates a GridState with the given model and initial viewport dimensions. All other fields start at their defaults (no selection, no sort, no edit, etc.).

Methods

apply

pub fn apply(&mut self, cmd: GridCommand) -> CommandOutput

The only way to mutate GridState. Applies a command and returns output.

See GridCommand API for all available commands.

SortState

pub struct SortState {
    pub col_key: String,
    pub dir: SortDir,
}

pub enum SortDir { Asc, Desc }

EditCell

pub struct EditCell {
    pub row: u64,
    pub col_key: String,
    pub original_value: Option<String>,
}

SearchState

pub struct SearchState {
    pub query: String,
    pub matches: Vec<CellCoord>,
    pub current: usize,
}