Skip to content

Latest commit

 

History

History
844 lines (588 loc) · 26.3 KB

File metadata and controls

844 lines (588 loc) · 26.3 KB

MiniSheet API Documentation

Complete API reference for the MiniSheet spreadsheet application. This document describes all public and internal structures, enums, and their methods.

Table of Contents

  1. Core Structures
  2. Enums
  3. App Structure
  4. Sheet Structure
  5. FormulaParser Structure
  6. Selection Enum
  7. Utility Functions

Core Structures

App

Main application state and UI controller.

Fields:

  • sheet: Sheet - The spreadsheet data
  • selection: Selection - Current selection (single cell, range, or multiple)
  • formula_bar: String - Content of the formula bar
  • editing_in_cell: bool - True when editing directly inside the selected cell
  • status: String - Status message displayed at the bottom
  • status_type: StatusType - Status type for color coding
  • theme: Theme - Color theme
  • undo_stack: Vec<UndoAction> - Undo stack
  • redo_stack: Vec<UndoAction> - Redo stack
  • clipboard: Option<String> - Clipboard content (cell value)
  • current_file: Option<PathBuf> - Current file path (for save)
  • dark_mode: bool - Dark theme enabled
  • col_widths: Vec<f32> - Column widths (customizable)
  • resizing_col: Option<usize> - Currently resizing column index
  • show_formulas: bool - Show formulas instead of values
  • search_dialog_open: bool - Search/Replace dialog state
  • search_text: String - Search text
  • replace_text: String - Replace text
  • search_results: Vec<(usize, usize)> - Search results (cell coordinates)
  • current_search_index: usize - Current search result index
  • frozen_row: Option<usize> - Frozen row index
  • frozen_col: Option<usize> - Frozen column index
  • column_sorts: HashMap<usize, bool> - Column sort state (column index -> ascending)

Methods:

select_cell(&mut self, r: usize, c: usize)

Selects a single cell at the given coordinates.

Parameters:

  • r: usize - Row index
  • c: usize - Column index

primary_cell(&self) -> (usize, usize)

Returns the primary cell coordinates from the current selection.

Returns: (usize, usize) - Row and column indices

handle_keyboard(&mut self, ctx: &egui::Context)

Handles keyboard input and shortcuts.

Parameters:

  • ctx: &egui::Context - egui context

Shortcuts handled:

  • Ctrl+Z - Undo
  • Ctrl+Y / Ctrl+Shift+Z - Redo
  • Ctrl+C - Copy
  • Ctrl+V - Paste
  • Ctrl+B - Toggle bold
  • Ctrl+I - Toggle italic
  • Ctrl+ ` - Toggle show formulas
  • Ctrl+A - Select all
  • Ctrl+F - Open search dialog
  • Ctrl+S - Save
  • Ctrl+Shift+S - Save As
  • Ctrl+O - Open
  • Ctrl+N - New
  • F2 - Enter edit mode
  • Escape - Cancel editing
  • Arrow keys - Navigation
  • Tab / Shift+Tab - Move right/left
  • Enter / Shift+Enter - Move down/up

commit_formula_bar(&mut self)

Commits the formula bar content to the selected cell.

undo(&mut self)

Undoes the last action.

redo(&mut self)

Redoes the last undone action.

copy(&mut self)

Copies the selected cell(s) to clipboard.

paste(&mut self)

Pastes clipboard content to the selected cell.

save(&mut self)

Saves the current spreadsheet to the current file path.

save_as(&mut self)

Opens a file dialog to save the spreadsheet to a new file.

save_to_path(&mut self, path: &PathBuf)

Saves the spreadsheet to a specific path.

Parameters:

  • path: &PathBuf - File path to save to

open(&mut self)

Opens a file dialog to load a spreadsheet from a file.

get_dependencies(&self, r: usize, c: usize) -> Vec<(usize, usize)>

Gets all cells that the specified cell depends on.

Parameters:

  • r: usize - Row index
  • c: usize - Column index

Returns: Vec<(usize, usize)> - List of dependent cell coordinates

perform_search(&mut self)

Performs a search across all cells and populates search results.

navigate_to_search_result(&mut self)

Navigates to the current search result.

replace_current(&mut self)

Replaces the current search result with the replace text.

replace_all(&mut self)

Replaces all search results with the replace text.

sort_column(&mut self, col: usize, ascending: bool)

Sorts all rows based on the values in the specified column.

Parameters:

  • col: usize - Column index to sort by
  • ascending: bool - Sort direction (true = ascending, false = descending)

render_grid(&mut self, ui: &mut egui::Ui)

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 context
  • cols: usize - Number of columns
  • rows: usize - Number of rows
  • dependencies: &[(usize, usize)] - Cells to highlight as dependencies
  • frozen_row: usize - Frozen row index
  • frozen_col: usize - Frozen column index

render_column_headers(&mut self, ui: &mut egui::Ui, cols: usize, skip_cols: usize)

Renders column headers with sort buttons.

Parameters:

  • ui: &mut egui::Ui - egui UI context
  • cols: usize - Number of columns
  • skip_cols: usize - Number of columns to skip (for frozen panes)

render_row_numbers(&mut self, ui: &mut egui::Ui, rows: usize, skip_rows: usize)

Renders row numbers.

Parameters:

  • ui: &mut egui::Ui - egui UI context
  • rows: usize - Number of rows
  • skip_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 context
  • cols: usize - Number of columns
  • rows: usize - Number of rows
  • dependencies: &[(usize, usize)] - Cells to highlight as dependencies
  • skip_rows: usize - Number of rows to skip
  • skip_cols: usize - Number of columns to skip
  • show_row_headers: bool - Whether to show row headers
  • show_col_headers: bool - Whether to show column headers

Sheet

Represents the spreadsheet data model.

Fields:

  • rows: usize - Number of rows in the sheet
  • cols: usize - Number of columns in the sheet
  • raw: 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:

is_valid_cell(&self, r: usize, c: usize) -> bool

Validates cell coordinates.

Parameters:

  • r: usize - Row index
  • c: usize - Column index

Returns: bool - True if coordinates are valid

set_raw(&mut self, r: usize, c: usize, value: String)

Sets the raw content of a cell.

Parameters:

  • r: usize - Row index
  • c: usize - Column index
  • value: String - Cell content

invalidate_cell(&mut self, r: usize, c: usize)

Invalidates a cell and all cells that depend on it (recursive).

Parameters:

  • r: usize - Row index
  • c: usize - Column index

references_cell(&self, formula: &str, target_r: usize, target_c: usize) -> bool

Checks if a formula references a specific cell.

Parameters:

  • formula: &str - Formula string
  • target_r: usize - Target row index
  • target_c: usize - Target column index

Returns: bool - True if the formula references the target cell

get_raw(&self, r: usize, c: usize) -> String

Gets the raw content of a cell.

Parameters:

  • r: usize - Row index
  • c: usize - Column index

Returns: String - Cell content

get_format(&self, r: usize, c: usize) -> CellFormat

Gets format for a cell.

Parameters:

  • r: usize - Row index
  • c: usize - Column index

Returns: CellFormat - Cell format

set_format(&mut self, r: usize, c: usize, format: CellFormat)

Sets format for a cell.

Parameters:

  • r: usize - Row index
  • c: usize - Column index
  • format: CellFormat - Cell format to apply

toggle_bold(&mut self, r: usize, c: usize)

Toggles bold formatting for a cell.

Parameters:

  • r: usize - Row index
  • c: usize - Column index

toggle_italic(&mut self, r: usize, c: usize)

Toggles italic formatting for a cell.

Parameters:

  • r: usize - Row index
  • c: usize - Column index

set_fg_color(&mut self, r: usize, c: usize, color: Option<[u8; 3]>)

Sets cell foreground color.

Parameters:

  • r: usize - Row index
  • c: usize - Column index
  • color: Option<[u8; 3]> - RGB color (None to clear)

set_bg_color(&mut self, r: usize, c: usize, color: Option<[u8; 3]>)

Sets cell background color.

Parameters:

  • r: usize - Row index
  • c: usize - Column index
  • color: Option<[u8; 3]> - RGB color (None to clear)

set_alignment(&mut self, r: usize, c: usize, alignment: Alignment)

Sets cell alignment.

Parameters:

  • r: usize - Row index
  • c: usize - Column index
  • alignment: Alignment - Alignment option

display_value(&mut self, r: usize, c: usize) -> String

Gets the display value (formatted) of a cell.

Parameters:

  • r: usize - Row index
  • c: usize - Column index

Returns: String - Formatted display value

recalc_all(&mut self)

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 index
  • c: usize - Column index
  • stack: &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

parse_cell_ref(s: &str) -> Option<(usize, usize)>

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

col_index(letters: &str) -> Option<usize>

Converts column letters (e.g., "A", "AB") to column index.

Parameters:

  • letters: &str - Column letters

Returns: Option<usize> - Column index, or None if invalid

col_name(&self, mut col: usize) -> String

Converts column index to column name (e.g., 0 -> "A", 26 -> "AA").

Parameters:

  • col: usize - Column index

Returns: String - Column name

addr(&self, r: usize, c: usize) -> String

Gets the cell address string (e.g., "A1") for given coordinates.

Parameters:

  • r: usize - Row index
  • c: usize - Column index

Returns: String - Cell address

detect_numeric_sequence(&mut self, cells: &[(usize, usize)]) -> Option<f64>

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

detect_text_sequence(&self, cells: &[(usize, usize)]) -> Option<usize>

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

next_sequence_value(&mut self, cells: &[(usize, usize)], step: f64) -> String

Calculates the next value in a detected sequence.

Parameters:

  • cells: &[(usize, usize)] - Source cell coordinates
  • step: 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 coordinates
  • target_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 formula
  • src_r: usize - Source row index
  • src_c: usize - Source column index
  • dst_r: usize - Destination row index
  • dst_c: usize - Destination column index

Returns: String - Adjusted formula


FormulaParser

Recursive descent parser for formula evaluation.

Fields:

  • chars: Vec<char> - Character array of input
  • pos: usize - Current position in input
  • input: &'a str - Original input string

Methods:

new(input: &'a str) -> Self

Creates a new formula parser.

Parameters:

  • input: &'a str - Formula string to parse

Returns: Self - New parser instance

is_end(&self) -> bool

Checks if parser has reached end of input.

Returns: bool - True if at end

peek(&self) -> Option<char>

Peeks at the current character without advancing.

Returns: Option<char> - Current character, or None if at end

next(&mut self) -> Option<char>

Advances and returns the current character.

Returns: Option<char> - Current character, or None if at end

skip_ws(&mut self)

Skips whitespace characters.

matches(&self, s: &str) -> bool

Checks if next characters match a string (case insensitive).

Parameters:

  • s: &str - String to match

Returns: bool - True if matches

advance(&mut self, n: usize)

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 reference
  • stack: &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 reference
  • stack: &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 reference
  • stack: &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 reference
  • stack: &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 reference
  • stack: &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 reference
  • stack: &mut HashSet<(usize, usize)> - Cycle detection stack

Returns: Result<f64, CellValue> - Evaluated value or error

parse_number(&mut self) -> Result<f64, CellValue>

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 reference
  • stack: &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 name
  • sheet: &mut Sheet - Spreadsheet reference
  • stack: &mut HashSet<(usize, usize)> - Cycle detection stack

Returns: Result<f64, CellValue> - Function result or error

Supported Functions:

  • SUM, AVG, MIN, MAX, COUNT
  • IF, ABS, SQRT, ROUND, POWER
  • SUMIF, COUNTIF, AVERAGEIF
  • CONCATENATE, CONCAT, LEFT, RIGHT, MID
  • VLOOKUP, HLOOKUP

parse_function_args(&mut self, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Vec<f64>

Parses function arguments (comma-separated expressions).

Parameters:

  • sheet: &mut Sheet - Spreadsheet reference
  • stack: &mut HashSet<(usize, usize)> - Cycle detection stack

Returns: Vec<f64> - Vector of argument values

eval_range(&mut self, sheet: &mut Sheet, stack: &mut HashSet<(usize, usize)>) -> Vec<f64>

Evaluates a cell range (e.g., A1:B5) and returns all values.

Parameters:

  • sheet: &mut Sheet - Spreadsheet reference
  • stack: &mut HashSet<(usize, usize)> - Cycle detection stack

Returns: Vec<f64> - Vector of cell values in range

parse_cell_ref_for_range(&mut self) -> Result<(usize, usize), CellValue>

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 reference
  • stack: &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 against
  • criteria: &str - Criteria string
  • sum_range: Option<&[(usize, usize)]> - Optional range to sum (if different from criteria range)
  • sheet: &mut Sheet - Spreadsheet reference
  • stack: &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 evaluate
  • criteria: &str - Criteria string
  • sheet: &mut Sheet - Spreadsheet reference
  • stack: &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 evaluate
  • criteria: &str - Criteria string
  • sheet: &mut Sheet - Spreadsheet reference
  • stack: &mut HashSet<(usize, usize)> - Cycle detection stack

Returns: Result<f64, CellValue> - Average of matching values or error

match_criteria(&self, value: &str, criteria: &str) -> bool

Matches a value against criteria string.

Parameters:

  • value: &str - Value to test
  • criteria: &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 for
  • table_array: &[(usize, usize)] - Table range
  • col_index: usize - Column index to return (1-based)
  • range_lookup: bool - True for approximate match, false for exact
  • sheet: &mut Sheet - Spreadsheet reference
  • stack: &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 for
  • table_array: &[(usize, usize)] - Table range
  • row_index: usize - Row index to return (1-based)
  • range_lookup: bool - True for approximate match, false for exact
  • sheet: &mut Sheet - Spreadsheet reference
  • stack: &mut HashSet<(usize, usize)> - Cycle detection stack

Returns: Result<f64, CellValue> - Lookup result or error

expect_char(&mut self, c: char) -> Result<(), CellValue>

Expects and consumes a specific character.

Parameters:

  • c: char - Expected character

Returns: Result<(), CellValue> - Ok if matched, error otherwise

expect_separator(&mut self) -> Result<(), CellValue>

Expects and consumes a separator (comma or semicolon).

Returns: Result<(), CellValue> - Ok if matched, error otherwise


Enums

Selection

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:

cells(&self) -> Vec<(usize, usize)>

Gets all cells in the selection.

Returns: Vec<(usize, usize)> - List of cell coordinates

primary(&self) -> (usize, usize)

Gets the primary cell (for formula bar display).

Returns: (usize, usize) - Primary cell coordinates

contains(&self, r: usize, c: usize) -> bool

Checks if a cell is in the selection.

Parameters:

  • r: usize - Row index
  • c: usize - Column index

Returns: bool - True if cell is selected


CellValue

Represents the evaluated value of a cell.

Variants:

  • Empty - Empty cell
  • Number(f64) - Numeric value
  • Text(String) - Text value
  • Error(String) - Error message

StatusType

Status message type for color coding.

Variants:

  • Ok - Success status (green)
  • Warning - Warning status (orange)
  • Error - Error status (red)
  • Info - Informational status (blue)

Alignment

Cell text alignment.

Variants:

  • Left - Left alignment
  • Center - Center alignment
  • Right - Right alignment

Supporting Structures

Theme

Color theme/palette for the application.

Fields:

  • primary: egui::Color32 - Primary color
  • secondary: egui::Color32 - Secondary color
  • background: egui::Color32 - Background color
  • accent: egui::Color32 - Accent color
  • header_bg: egui::Color32 - Header background
  • selected_bg: egui::Color32 - Selected cell background
  • hover_bg: egui::Color32 - Hover background
  • error_bg: egui::Color32 - Error cell background
  • dependency_bg: egui::Color32 - Dependency highlight background
  • grid_line: egui::Color32 - Grid line color
  • row_stripe: egui::Color32 - Row stripe color
  • status_ok: egui::Color32 - OK status color
  • status_warning: egui::Color32 - Warning status color
  • status_error: egui::Color32 - Error status color

CellFormat

Cell formatting options.

Fields:

  • bold: bool - Bold text
  • italic: bool - Italic text
  • fg_color: Option<[u8; 3]> - Foreground color (RGB)
  • bg_color: Option<[u8; 3]> - Background color (RGB)
  • alignment: Alignment - Text alignment

UndoAction

Represents an action that can be undone/redone.

Fields:

  • cell: (usize, usize) - Cell coordinates
  • old_value: String - Previous value
  • new_value: String - New value

Utility Functions

setup_custom_style(ctx: &egui::Context)

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

Serialization

The Sheet struct implements Serialize and Deserialize from serde. Custom serialization modules handle HashMap<(usize, usize), T> serialization:

  • hashmap_string_serde - Serializes HashMap<(usize, usize), String> (raw cell content)
  • hashmap_format_serde - Serializes HashMap<(usize, usize), CellFormat> (cell formats)

The computed field is skipped during serialization as it's recalculated on load.


Error Handling

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

Notes

  • 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