stocks: fix blank item list after collapsing while scrolled down - #5905
Alistair-Afton wants to merge 4 commits into
Conversation
Collapsing all categories shrinks stocks.i_height but left scroll_position_item untouched, so the view pointed past the end of the list with no way to scroll back. Reset it when collapsing, and clamp scroll_position_type when removing empty categories shrinks the type list. Also fix a missing local on num_items in expand_all, and make the three actions module-level so tests can reach them. fixes DFHack#5772
0265e17 to
99288dd
Compare
SilasD
left a comment
There was a problem hiding this comment.
I am very uncomfortable making collapse_all, expand_all, and remove_empty global.
these functions directly manipulate the UI; the UI is generally fragile and tends to leave dangling pointers when a viewsheet is closed.
making these functions global means that any other script can call them at any time. if the stocks viewsheet is not open, I think there is a significant risk of crashing the game.
to emphasize: these functions should (must) not be called if the stocks interface is not open.
I would either like these changed back to local or have a safety-test added, something like
if stocks.open == false then return; end
at the start of each function.
or both. both would be good.
Other than that issue, the code generally looks fine, though I didn't test it.
|
Done both: the functions are Also added
Verified in-game: 4/4 tests pass, full suite green (271/271). |
Summary
collapse_allshranki_heightbut leftscroll_position_itemstale, so collapsing a list while scrolled down left the viewport past the end of the list and rendered a blank pane (fixes #5772).Applied the same scroll clamp to
remove_empty, which had the identical hazard on the type list, and fixed a leaked global (num_itemsinexpand_allwas missinglocal).Testing
ci/lint.pyclean