-
Notifications
You must be signed in to change notification settings - Fork 79
Ensure all Rows layout its cells consistently with the Column headers #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Ensure all Rows layout its cells consistently with the Column headers #358
Conversation
…and maintain the measure information if the datasource appears to show the same data. This prevents horizontal scrolling becoming disjointed... if the data is different we scroll to the top left again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a horizontal scroll issue by preserving column measure information when the underlying source changes.
- Introduces a new method, TryToMaintainColumnLayouts, to restore column measurements if the columns match.
- Posts a scroll-to-home action on the Dispatcher if the columns are different, ensuring the scroll offsets reset.
- Adds new scroll utility methods (ScrollToHome and ScrollToEnd) in the presenter base class.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridRowsPresenter.cs | Introduces logic to maintain column layouts and conditionally reset the scroll position. |
src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridPresenterBase.cs | Adds helper methods for scrolling operations. |
{ | ||
for (int i = 0; i < oldValue.Count; i++) | ||
{ | ||
if (newValue[i].Header == oldValue[i].Header) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Comparing columns solely by 'Header' could lead to issues if headers are not unique. Consider using a unique identifier or additional column properties to more reliably verify column equivalence.
if (newValue[i].Header == oldValue[i].Header) | |
if (newValue[i].Id == oldValue[i].Id) // Use a unique identifier for comparison |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ok since the user sets this to either a viewmodel or a string, and we are essentially checking if all the columns are the same.
…e column positions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses inconsistent cell layout during horizontal scrolling by deferring column estimation and calculation to the IColumns interface to ensure uniform presenter behavior.
- TreeDataGridPresenterBase now exposes StartU and FirstIndex properties and changes the accessibility of EstimateElementSizeU.
- TreeDataGridColumnarPresenterBase uses a new pattern-matched call to IColumns.GetOrEstimateColumnAt and overrides EstimateElementSizeU to update the cached estimate.
- IColumns and ColumnList are extended with GetOrEstimateColumnAt and EstimateElementSizeU methods, and ColumnList now uses MathUtilities.AreClose for viewport width comparisons.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridPresenterBase.cs | Added properties and updated element size estimation accessibility. |
src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridColumnarPresenterBase.cs | Updated anchor element and size estimation logic using new IColumns methods. |
src/Avalonia.Controls.TreeDataGrid/Models/TreeDataGrid/IColumns.cs | Extended interface with column estimation methods. |
src/Avalonia.Controls.TreeDataGrid/Models/TreeDataGrid/ColumnList.cs | Implemented estimation logic and adjusted viewport comparison methodology. |
I attempted to unit test this: the problem is that when this happens:
during runjobs, cells presenters seem to start appearing with invalid viewports, causing it to just realize all the columns / cells. This doesnt match the issue that this PR fixes.
|
If they user changes the source… when horizontally scrolled to the right, we dont have realized elements before the viewport.
This means we have to fallback to estimating the anchor element position and index. however because the CellsPresenters in each row, make this calculation independently of each other and of the column header… we get different results (due to recycled presenters not resetting its
_lastEstimatedElementSizeU
field)This PR fixes it by deferring the columnar presenters estimations and calculation to IColumns, ensuring consistent results.