Skip to content

Checkboxes: ribbon button, Excel's value and Delete rules, XLSX cell controls (#196) - #305

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
vangel76:feat/cell-checkbox
Oct 11, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
vangel76:feat/cell-checkbox

Conversation

@vangel76

Copy link
Copy Markdown
Contributor

Fixes #196

Root cause

GridCraft already had cell checkboxes (insert.checkbox, drawn in the grid, toggled by click or Space), but:

  • Hard to find: the egui ribbon had no button for it. Only the macOS native menu and the command palette offered it.
  • Data loss: inserting a checkbox replaced every value in the range with FALSE.
  • Wrong display: text or numbers in a checkbox cell were hidden behind an unchecked box.
  • Bad XLSX output: the checkbox was written to XLSX as a custom number format checkbox. That is not a valid Excel format code, and Excel doesn't read it as a checkbox.

What changed

  • Ribbon: Insert › Checkbox (Cell Controls group, after Sparklines) with a code-drawn icon. The label and tooltip are in all catalogs.
  • Values (from Microsoft's "Using checkboxes in Excel" support article):
    • TRUE/FALSE draw as a box. An empty cell starts as FALSE.
    • Other values and formulas stay in the cell and display as General (the checkbox marker format now renders as General in numfmt).
    • Clicking or pressing Space toggles; an emptied checkbox counts as FALSE, so toggling checks it. Space over a selection toggles only checkbox cells, not plain TRUE/FALSE cells.
    • Delete works in two passes: if any box in the selection is checked, all boxes are unchecked; when all are unchecked, the boxes are removed (value cleared, checkbox format dropped).
    • Clear Formats removes the boxes and keeps the TRUE/FALSE values.
  • XLSX (new crates/xlsx/src/feature_bags.rs), from the public [MS-XLSX] spec sections 2.1.22, 2.3.9.1–2.3.9.4, 2.4.99, 2.6.229–2.6.239 and the Styles extension table 2.2.4.9:
    • Write:
      • Checkbox styles are written as General plus an xf extLst ({C7286773-470A-42A8-94C5-96B5CB345126}) holding xfpb:xfComplement i="0".
      • One xl/featurePropertyBag/featurePropertyBag.xml part holds the chain Checkbox ← XFControls (CellControl) ← XFComplement (XFControls) ← XFComplements (MappedFeaturePropertyBags).
      • The part is related from the workbook with type …/2022/11/relationships/FeaturePropertyBag.
    • Read: an xf whose complement resolves through that chain to a Checkbox bag becomes a checkbox. Bad indexes, wrong bag types or a missing part just mean "not a checkbox"; nothing panics.

Tests

  • Engine:
    • checkboxes_keep_values_toggle_and_delete_in_two_passes
    • checkboxes_survive_xlsx_as_cell_controls (write → read round trip; a plain cell next to it stays General)
  • XLSX: feature_bags::tests::written_chain_resolves_and_hostile_chains_do_not
  • The existing UI test interaction::space_toggles_the_active_checkbox_without_clicking_the_hovered_cell still passes.
  • Commands run:
    • cargo test -p gridcraft-engine
    • cargo test -p gridcraft-xlsx
    • cargo test -p gridcraft-numfmt
    • cargo test -p gridcraft-ui-egui --lib --test interaction
    • cargo fmt and cargo clippy --all-targets -D warnings on numfmt, engine, xlsx and ui-egui

Not done

  • I haven't opened our XLSX output in Excel, and no Excel-authored checkbox file was read. See the assumptions below.
  • The Checkbox bag's default key (2.3.9.4) is not read or written; absent means FALSE.
  • A checkbox's original number format is not kept underneath it, because the model stores the checkbox as the number format.
  • The checkbox format for differential formats (DXFComplements, 2.3.9.5) is not handled.

Unverified assumptions (needs confirmation in Excel)

  • The spec doesn't say which part the FeaturePropertyBag relationship comes from. I relate it from the workbook part, like the other workbook-level parts.
  • Inserting a checkbox keeps values that are already in the cells. The support article doesn't say; the spec's default key suggests Excel may write FALSE on insert.
  • Clicking anywhere in a checkbox cell toggles it (existing behaviour). Excel may toggle only when the box itself is clicked.

🤖 Generated with Claude Code

…controls (storytold#196)

insert.checkbox existed but had no ribbon button, replaced existing values
with FALSE and was written to XLSX as an invalid number format. Now:
Insert > Checkbox (Cell Controls); empty cells start FALSE, other values
stay and display as General; toggling an emptied box checks it and only
checkbox cells toggle; Delete unchecks first, then removes the boxes; XLSX
reads and writes the checkbox as Excel's feature-property-bag cell control
([MS-XLSX] 2.1.22, 2.3.9, 2.4.99).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 4dce118 into storytold:main Oct 11, 2026
@echelon

echelon commented Oct 11, 2026

Copy link
Copy Markdown
Member

Merged — thank you for the contribution!

If you haven't already, come join us on the ArtCraft Discord: https://discord.gg/artcraft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Allow user to style a check box in a Cell (Like Google Sheets)

3 participants