Complete API reference for the MiniSheet spreadsheet application. This document describes all public and internal structures, enums, and their methods.
- Core Structures
- Enums
- App Structure
- Sheet Structure
- FormulaParser Structure
- Selection Enum
- Utility Functions
Main application state and UI controller.
Fields:
sheet: Sheet- The spreadsheet dataselection: Selection- Current selection (single cell, range, or multiple)formula_bar: String- Content of the formula barediting_in_cell: bool- True when editing directly inside the selected cellstatus: String- Status message displayed at the bottomstatus_type: StatusType- Status type for color codingtheme: Theme- Color themeundo_stack: Vec<UndoAction>- Undo stackredo_stack: Vec<UndoAction>- Redo stackclipboard: Option<String>- Clipboard content (cell value)current_file: Option<PathBuf>- Current file path (for save)dark_mode: bool- Dark theme enabledcol_widths: Vec<f32>- Column widths (customizable)resizing_col: Option<usize>- Currently resizing column indexshow_formulas: bool- Show formulas instead of valuessearch_dialog_open: bool- Search/Replace dialog statesearch_text: String- Search textreplace_text: String- Replace textsearch_results: Vec<(usize, usize)>- Search results (cell coordinates)current_search_index: usize- Current search result indexfrozen_row: Option<usize>- Frozen row indexfrozen_col: Option<usize>- Frozen column indexcolumn_sorts: HashMap<usize, bool>- Column sort state (column index -> ascending)
Methods:
Selects a single cell at the given coordinates.
Parameters:
r: usize- Row indexc: usize- Column index
Returns the primary cell coordinates from the current selection.
Returns: (usize, usize) - Row and column indices
Handles keyboard input and shortcuts.
Parameters:
ctx: &egui::Context- egui context
Shortcuts handled:
Ctrl+Z- UndoCtrl+Y/Ctrl+Shift+Z- RedoCtrl+C- CopyCtrl+V- PasteCtrl+B- Toggle boldCtrl+I- Toggle italicCtrl+` - Toggle show formulasCtrl+A- Select allCtrl+F- Open search dialogCtrl+S- SaveCtrl+Shift+S- Save AsCtrl+O- OpenCtrl+N- NewF2- Enter edit modeEscape- Cancel editing- Arrow keys - Navigation
Tab/Shift+Tab- Move right/leftEnter/Shift+Enter- Move down/up
Commits the formula bar content to the selected cell.
Undoes the last action.
Redoes the last undone action.
Copies the selected cell(s) to clipboard.
Pastes clipboard content to the selected cell.
Saves the current spreadsheet to the current file path.
Opens a file dialog to save the spreadsheet to a new file.
Saves the spreadsheet to a specific path.
Parameters:
path: &PathBuf- File path to save to
Opens a file dialog to load a spreadsheet from a file.
Gets all cells that the specified cell depends on.
Parameters:
r: usize- Row indexc: usize- Column index
Returns: Vec<(usize, usize)> - List of dependent cell coordinates
Performs a search across all cells and populates search results.
Navigates to the current search result.
Replaces the current search result with the replace text.
Replaces all search results with the replace text.
Sorts all rows based on the values in the specified column.
Parameters:
col: usize- Column index to sort byascending: bool- Sort direction (true = ascending, false = descending)
Renders the main spreadsheet grid.
Parameters:
ui: &mut egui::Ui- egui UI context
render_grid_with_freeze(&mut self, ui: &mut egui::Ui, cols: usize, rows: usize, dependencies: &[(usize, usize)], frozen_row: usize, frozen_col: usize)
Renders the grid with frozen panes.
Parameters:
ui: &mut egui::Ui- egui UI contextcols: usize- Number of columnsrows: usize- Number of rowsdependencies: &[(usize, usize)]- Cells to highlight as dependenciesfrozen_row: usize- Frozen row indexfrozen_col: usize- Frozen column index
Renders column headers with sort buttons.
Parameters:
ui: &mut egui::Ui- egui UI contextcols: usize- Number of columnsskip_cols: usize- Number of columns to skip (for frozen panes)
Renders row numbers.
Parameters:
ui: &mut egui::Ui- egui UI contextrows: usize- Number of rowsskip_rows: usize- Number of rows to skip (for frozen panes)
render_grid_content(&mut self, ui: &mut egui::Ui, cols: usize, rows: usize, dependencies: &[(usize, usize)], skip_rows: usize, skip_cols: usize, show_row_headers: bool, show_col_headers: bool)
Renders the actual cell content in the grid.
Parameters:
ui: &mut egui::Ui- egui UI contextcols: usize- Number of columnsrows: usize- Number of rowsdependencies: &[(usize, usize)]- Cells to highlight as dependenciesskip_rows: usize- Number of rows to skipskip_cols: usize- Number of columns to skipshow_row_headers: bool- Whether to show row headersshow_col_headers: bool- Whether to show column headers
Represents the spreadsheet data model.
Fields:
rows: usize- Number of rows in the sheetcols: usize- Number of columns in the sheetraw: HashMap<(usize, usize), String>- Raw cell content (user input)computed: HashMap<(usize, usize), CellValue>- Computed/evaluated cell values (cache)formats: HashMap<(usize, usize), CellFormat>- Cell formatting
Methods:
Validates cell coordinates.
Parameters:
r: usize- Row indexc: usize- Column index
Returns: bool - True if coordinates are valid
Sets the raw content of a cell.
Parameters:
r: usize- Row indexc: usize- Column indexvalue: String- Cell content
Invalidates a cell and all cells that depend on it (recursive).
Parameters:
r: usize- Row indexc: usize- Column index
Checks if a formula references a specific cell.
Parameters:
formula: &str- Formula stringtarget_r: usize- Target row indextarget_c: usize- Target column index
Returns: bool - True if the formula references the target cell
Gets the raw content of a cell.
Parameters:
r: usize- Row indexc: usize- Column index
Returns: String - Cell content
Gets format for a cell.
Parameters:
r: usize- Row indexc: usize- Column index
Returns: CellFormat - Cell format
Sets format for a cell.
Parameters:
r: usize- Row indexc: usize- Column indexformat: CellFormat- Cell format to apply
Toggles bold formatting for a cell.
Parameters:
r: usize- Row indexc: usize- Column index
Toggles italic formatting for a cell.
Parameters:
r: usize- Row indexc: usize- Column index
Sets cell foreground color.
Parameters:
r: usize- Row indexc: usize- Column indexcolor: Option<[u8; 3]>- RGB color (None to clear)
Sets cell background color.
Parameters:
r: usize- Row indexc: usize- Column indexcolor: Option<[u8; 3]>- RGB color (None to clear)
Sets cell alignment.
Parameters:
r: usize- Row indexc: usize- Column indexalignment: Alignment- Alignment option
Gets the display value (formatted) of a cell.
Parameters:
r: usize- Row indexc: usize- Column index
Returns: String - Formatted display value
Recalculates all cells in the sheet (clears cache for lazy evaluation).
eval_cell(&mut self, r: usize, c: usize, stack: &mut HashSet<(usize, usize)>) -> Result<CellValue, CellValue>
Evaluates a single cell's value.
Parameters:
r: usize- Row indexc: usize- Column indexstack: &mut HashSet<(usize, usize)>- Stack for cycle detection
Returns: Result<CellValue, CellValue> - Evaluated cell value or error
eval_formula(&mut self, formula: &str, stack: &mut HashSet<(usize, usize)>) -> Result<CellValue, CellValue>
Evaluates a formula string.
Parameters:
formula: &str- Formula string (without leading '=')stack: &mut HashSet<(usize, usize)>- Stack for cycle detection
Returns: Result<CellValue, CellValue> - Evaluated result or error
Parses a cell reference string (e.g., "A1") to coordinates.
Parameters:
s: &str- Cell reference string
Returns: Option<(usize, usize)> - Row and column indices, or None if invalid
Converts column letters (e.g., "A", "AB") to column index.
Parameters:
letters: &str- Column letters
Returns: Option<usize> - Column index, or None if invalid
Converts column index to column name (e.g., 0 -> "A", 26 -> "AA").
Parameters:
col: usize- Column index
Returns: String - Column name
Gets the cell address string (e.g., "A1") for given coordinates.
Parameters:
r: usize- Row indexc: usize- Column index
Returns: String - Cell address
Detects if a selection contains a numeric sequence and returns the step.
Parameters:
cells: &[(usize, usize)]- Cell coordinates to analyze
Returns: Option<f64> - Step value if sequence detected, None otherwise
Detects if a selection contains a text sequence (months/days) and returns the sequence type.
Parameters:
cells: &[(usize, usize)]- Cell coordinates to analyze
Returns: Option<usize> - Sequence type identifier, None otherwise
Calculates the next value in a detected sequence.
Parameters:
cells: &[(usize, usize)]- Source cell coordinatesstep: f64- Step value for numeric sequences
Returns: String - Next value in the sequence
fill_range(&mut self, source_cells: &[(usize, usize)], target_start: (usize, usize), target_end: (usize, usize))
Fills a target range with values from a source selection.
Parameters:
source_cells: &[(usize, usize)]- Source cell coordinatestarget_start: (usize, usize)- Target range start (row, col)target_end: (usize, usize)- Target range end (row, col)
adjust_formula_references(&self, formula: &str, src_r: usize, src_c: usize, dst_r: usize, dst_c: usize) -> String
Adjusts relative cell references within formulas during copying.
Parameters:
formula: &str- Original formulasrc_r: usize- Source row indexsrc_c: usize- Source column indexdst_r: usize- Destination row indexdst_c: usize- Destination column index
Returns: String - Adjusted formula
Recursive descent parser for formula evaluation.
Fields:
chars: Vec<char>- Character array of inputpos: usize- Current position in inputinput: &'a str- Original input string
Methods:
Creates a new formula parser.
Parameters:
input: &'a str- Formula string to parse
Returns: Self - New parser instance
Checks if parser has reached end of input.
Returns: bool - True if at end
Peeks at the current character without advancing.
Returns: Option<char> - Current character, or None if at end
Advances and returns the current character.
Returns: Option<char> - Current character, or None if at end
Skips whitespace characters.
Checks if next characters match a string (case insensitive).
Parameters:
s: &str- String to match
Returns: bool - True if matches
Advances the parser position by n characters.
Parameters:
n: usize- Number of characters to advance
parse_expr(&mut self, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Result<f64, CellValue>
Parses and evaluates an expression.
Parameters:
sheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Result<f64, CellValue> - Evaluated numeric value or error
parse_comparison(&mut self, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Result<f64, CellValue>
Parses comparison operators (>, <, >=, <=, =, <>, !=).
Parameters:
sheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Result<f64, CellValue> - 1.0 if true, 0.0 if false, or error
parse_additive(&mut self, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Result<f64, CellValue>
Parses addition and subtraction operations.
Parameters:
sheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Result<f64, CellValue> - Evaluated value or error
parse_term(&mut self, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Result<f64, CellValue>
Parses multiplication and division operations.
Parameters:
sheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Result<f64, CellValue> - Evaluated value or error
parse_power(&mut self, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Result<f64, CellValue>
Parses power operations (^).
Parameters:
sheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Result<f64, CellValue> - Evaluated value or error
parse_factor(&mut self, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Result<f64, CellValue>
Parses atomic factors (numbers, cell references, functions, parentheses).
Parameters:
sheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Result<f64, CellValue> - Evaluated value or error
Parses a numeric literal.
Returns: Result<f64, CellValue> - Parsed number or error
parse_cell_or_function(&mut self, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Result<f64, CellValue>
Parses either a cell reference, a range, or a function call.
Parameters:
sheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Result<f64, CellValue> - Evaluated value or error
parse_function(&mut self, name: &str, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Result<f64, CellValue>
Parses and evaluates a function call.
Parameters:
name: &str- Function namesheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Result<f64, CellValue> - Function result or error
Supported Functions:
SUM,AVG,MIN,MAX,COUNTIF,ABS,SQRT,ROUND,POWERSUMIF,COUNTIF,AVERAGEIFCONCATENATE,CONCAT,LEFT,RIGHT,MIDVLOOKUP,HLOOKUP
Parses function arguments (comma-separated expressions).
Parameters:
sheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Vec<f64> - Vector of argument values
Evaluates a cell range (e.g., A1:B5) and returns all values.
Parameters:
sheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Vec<f64> - Vector of cell values in range
Parses a cell reference for use in ranges.
Returns: Result<(usize, usize), CellValue> - Cell coordinates or error
parse_criteria(&mut self, _sheet: &mut Sheet, _stack: &mut HashSet<(usize, usize)>) -> Result<String, CellValue>
Parses criteria strings for conditional functions (e.g., ">5", "text").
Parameters:
_sheet: &mut Sheet- Spreadsheet reference (unused)_stack: &mut HashSet<(usize, usize)>- Cycle detection stack (unused)
Returns: Result<String, CellValue> - Criteria string or error
parse_text_value(&mut self, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Result<String, CellValue>
Parses cell references or string literals for text functions.
Parameters:
sheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Result<String, CellValue> - Text value or error
eval_sumif(&mut self, range: &[(usize, usize)], criteria: &str, sum_range: Option<&[(usize, usize)]>, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Result<f64, CellValue>
Evaluates SUMIF function.
Parameters:
range: &[(usize, usize)]- Range to evaluate criteria againstcriteria: &str- Criteria stringsum_range: Option<&[(usize, usize)]>- Optional range to sum (if different from criteria range)sheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Result<f64, CellValue> - Sum of matching values or error
eval_countif(&mut self, range: &[(usize, usize)], criteria: &str, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Result<f64, CellValue>
Evaluates COUNTIF function.
Parameters:
range: &[(usize, usize)]- Range to evaluatecriteria: &str- Criteria stringsheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Result<f64, CellValue> - Count of matching values or error
eval_averageif(&mut self, range: &[(usize, usize)], criteria: &str, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Result<f64, CellValue>
Evaluates AVERAGEIF function.
Parameters:
range: &[(usize, usize)]- Range to evaluatecriteria: &str- Criteria stringsheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Result<f64, CellValue> - Average of matching values or error
Matches a value against criteria string.
Parameters:
value: &str- Value to testcriteria: &str- Criteria string (e.g., ">5", "text", "=10")
Returns: bool - True if value matches criteria
eval_vlookup(&mut self, lookup_value: f64, table_array: &[(usize, usize)], col_index: usize, range_lookup: bool, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Result<f64, CellValue>
Evaluates VLOOKUP function.
Parameters:
lookup_value: f64- Value to search fortable_array: &[(usize, usize)]- Table rangecol_index: usize- Column index to return (1-based)range_lookup: bool- True for approximate match, false for exactsheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Result<f64, CellValue> - Lookup result or error
eval_hlookup(&mut self, lookup_value: f64, table_array: &[(usize, usize)], row_index: usize, range_lookup: bool, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Result<f64, CellValue>
Evaluates HLOOKUP function.
Parameters:
lookup_value: f64- Value to search fortable_array: &[(usize, usize)]- Table rangerow_index: usize- Row index to return (1-based)range_lookup: bool- True for approximate match, false for exactsheet: &mut Sheet- Spreadsheet referencestack: &mut HashSet<(usize, usize)>- Cycle detection stack
Returns: Result<f64, CellValue> - Lookup result or error
Expects and consumes a specific character.
Parameters:
c: char- Expected character
Returns: Result<(), CellValue> - Ok if matched, error otherwise
Expects and consumes a separator (comma or semicolon).
Returns: Result<(), CellValue> - Ok if matched, error otherwise
Selection state for cells.
Variants:
Single(usize, usize)- Single active cell (row, col)Range((usize, usize), (usize, usize))- Rectangular range (start, end)Multiple(Vec<(usize, usize)>)- Discontinuous multi-selection
Methods:
Gets all cells in the selection.
Returns: Vec<(usize, usize)> - List of cell coordinates
Gets the primary cell (for formula bar display).
Returns: (usize, usize) - Primary cell coordinates
Checks if a cell is in the selection.
Parameters:
r: usize- Row indexc: usize- Column index
Returns: bool - True if cell is selected
Represents the evaluated value of a cell.
Variants:
Empty- Empty cellNumber(f64)- Numeric valueText(String)- Text valueError(String)- Error message
Status message type for color coding.
Variants:
Ok- Success status (green)Warning- Warning status (orange)Error- Error status (red)Info- Informational status (blue)
Cell text alignment.
Variants:
Left- Left alignmentCenter- Center alignmentRight- Right alignment
Color theme/palette for the application.
Fields:
primary: egui::Color32- Primary colorsecondary: egui::Color32- Secondary colorbackground: egui::Color32- Background coloraccent: egui::Color32- Accent colorheader_bg: egui::Color32- Header backgroundselected_bg: egui::Color32- Selected cell backgroundhover_bg: egui::Color32- Hover backgrounderror_bg: egui::Color32- Error cell backgrounddependency_bg: egui::Color32- Dependency highlight backgroundgrid_line: egui::Color32- Grid line colorrow_stripe: egui::Color32- Row stripe colorstatus_ok: egui::Color32- OK status colorstatus_warning: egui::Color32- Warning status colorstatus_error: egui::Color32- Error status color
Cell formatting options.
Fields:
bold: bool- Bold textitalic: bool- Italic textfg_color: Option<[u8; 3]>- Foreground color (RGB)bg_color: Option<[u8; 3]>- Background color (RGB)alignment: Alignment- Text alignment
Represents an action that can be undone/redone.
Fields:
cell: (usize, usize)- Cell coordinatesold_value: String- Previous valuenew_value: String- New value
Configures custom visual style for the application.
Parameters:
ctx: &egui::Context- egui context
Effects:
- Sets custom font sizes for Body, Button, Heading, and Monospace text styles
The Sheet struct implements Serialize and Deserialize from serde. Custom serialization modules handle HashMap<(usize, usize), T> serialization:
hashmap_string_serde- SerializesHashMap<(usize, usize), String>(raw cell content)hashmap_format_serde- SerializesHashMap<(usize, usize), CellFormat>(cell formats)
The computed field is skipped during serialization as it's recalculated on load.
Most methods return Result<T, CellValue> where errors are represented as CellValue::Error(String). Common error messages include:
"Cell out of bounds"- Invalid cell coordinates"Circular reference"- Circular dependency detected"Division by zero"- Division by zero in formula"Invalid number"- NaN or Infinity detected"Missing closing parenthesis"- Syntax error"Unexpected token"- Parse error"Evaluation failed"- General evaluation error
- All row and column indices are 0-based internally
- Cell references in formulas use 1-based notation (A1, B2, etc.)
- The parser uses recursive descent with operator precedence
- Cycle detection prevents infinite loops in formula evaluation
- Lazy evaluation: cells are only recalculated when accessed
- Incremental recalculation: only affected cells are invalidated
Last Updated: 2026-01-20