Make the scrolling container reach the last row of a multi-column grid - #236
Open
rubensworks wants to merge 1 commit into
Open
Make the scrolling container reach the last row of a multi-column grid#236rubensworks wants to merge 1 commit into
rubensworks wants to merge 1 commit into
Conversation
ScrollingInventoryContainer supports multiple columns, but two places assume there is only one. ContainerScreenScrolling computes the scrollbar's total rows as `filteredItemCount / getColumns()`, which truncates. With one column that is exact, but with nine columns and 985 elements it gives 109 rows instead of 110, so the four elements of the last row can never be scrolled to. The division is rounded up now, in one place both call sites share. isElementVisible guards against getPageSize(), which is the number of rows, and so returns false for every element past the first row of a grid, even though getVisibleElement returns them and onScroll fills them in. It now guards against the size of the visible elements, which is rows times columns; for a single-column container the two are the same. The constructor also only null-filled the first getPageSize() entries of a list that is rows times columns long. That was harmless, as the array it wraps is already all-null, but it read as if the rest were left uninitialized. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T9xTc8kXNRDppvXktL24aR
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



ScrollingInventoryContainersupports multiple columns —onScrollwalksi * getColumns() + jandgetScrollStepSize()defaults togetColumns()— but two places still assume there is only one.The last row is unreachable
ContainerScreenScrollingcomputes the scrollbar's total rows asfilteredItemCount / getColumns(), in bothinitandupdateSearch. That truncates, soWidgetScrollBar#getScrollStep(totalRows - visibleRows) comes out one short and the last, partially filled row can never be scrolled to.Measured live in a dev client, on a 9-column grid of 985 elements with 6 visible rows, by setting the scrollbar to each value and scrolling fully to the bottom:
totalRows985 / 9= 109 (today)ceil(985 / 9)= 110 (this PR)The final element is index 984, so 981–984 are unreachable: the scrollbar is already at the bottom and they never appear.
Rounded up now, in one
getTotalRows()both call sites share, so a subclass that wants different behaviour has a single place to override.isElementVisiblereturns false past the first rowgetPageSize()is the number of rows, while the parameter indexes into the visible elements, which number rows × columns. So for a grid this returns false for everything after the first row, even thoughgetVisibleElementreturns those elements andonScrollfills them in. It now guards againstgetPageSize() * getColumns(); for a single-column container the two are identical, so nothing changes for existing users.A cosmetic third one
The constructor null-filled only the first
getPageSize()entries of a list that is rows × columns long. Harmless, sinceArrays.asList(new Object[n])is already all-null, but it read as if the rest were left uninitialized.How this came up
Building a 9 × 6 recipe grid on
ScrollingInventoryContainerin IntegratedCrafting (CyclopsMC/IntegratedCrafting#221). Both were worked around locally there; that workaround can go once a release carries this.Testing
./gradlew :loader-neoforge:compileJavapasses. Behaviour verified in a dev client through the IntegratedCrafting grid, as measured above: with the fix, scrolling fully down lands on a last row holding exactly the 4 remaining elements (985 % 9 = 4), and every cell renders across the whole scroll range.🤖 Generated with Claude Code
https://claude.ai/code/session_01T9xTc8kXNRDppvXktL24aR