tech-debt: main.rs is 17 300 lines and App has 119 fields #13
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
linux
packaging
performance
question
tech-debt
ui
windows
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
ben/openDither#13
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Version: 0.1.2 (
main@41c7fc5)This is a structural issue, not a defect: nothing behaves wrongly today.
The measurement
app/src/main.rs: 17 304 lines; the next largest file isdata.rswith 5 913.struct App(main.rs:223) has 119 fields and lives in that same file; itsimplblocks span ~13 000 of those lines.AGENTS.mdalready says "main.rs— the whole interface: panels, menus, shortcuts, drag and drop, and the glue between them", so this is known and deliberate. It has reached the size where it costs something.What it costs today
Appis document state, UI state, test hooks, export plumbing and pipeline state in one bag, so a new panel can read and write anything, and nothing says which fields belong to the document (and therefore to a snapshot, a save, or an undo step).uitest.rsdrives real widgets (good) but also setsapp.params.xand readsapp.layer_pixelsdirectly, because there is no document type to talk to.Snapshothas to name every field that is document state by hand (main.rs:3182), solayer_pixelswas simply missed. ADocumenttype with asnapshot()next to its fields makes that omission impossible to forget.Suggested fix, in an order that keeps
main.rsworking throughoutdoc.rs(params,canvas,layer_pixels,shapes,ascii,effects,anim_layers,export_w/h) withimpl Document { fn snapshot(&self) -> Snapshot }. That alone fixes the class of bug thatlayer_pixelsfell into.ui/modules, one per tab (ui/dither.rs,ui/layers.rs, …), each anfn panel(&mut self, ui: &mut Ui) -> Changedstyle signature overDocument+ a smallUiState.main.rswith the frame loop, the menu bar, shortcuts and drag-and-drop — the parts that really are about the window.No behaviour change anywhere; the
--uitestrows keep clicking the same widgets.A check that would catch a regression here
A
cargo testrow that walks theDocumentfields and asserts the snapshot round-trips them (the same trick this repo already uses for project save/load: build a document with everything non-default, snapshot, mutate, restore, compare). That turns "someone added a field and forgot the snapshot" from a data-loss bug into a red test.