Skip to content
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

Horizontal Misalignment of Cells During Vertical Scrolling with Non-Realized First Column #298

Open
00jeser opened this issue Jun 10, 2024 · 10 comments

Comments

@00jeser
Copy link

00jeser commented Jun 10, 2024

Description
When the first column is not realized, an incorrect horizontal position of the cells occurs during vertical scrolling. This issue is demonstrated in the attached video.

Steps to Reproduce

  1. Open the TreeDataGrid.
  2. Ensure that the first column is not realized.
  3. Scroll vertically through the grid.

Expected Behavior
The horizontal position of the cells should remain correct and aligned during vertical scrolling.

Actual Behavior
The horizontal position of the cells is incorrect and misaligned when scrolling vertically.

Environment
TreeDataGrid Version: 11.0.10
Avalonia Version: 11.0.10
Operating System: Windows 11

Additional Information
See the attached videos demonstrating the issue:

2024-06-10.11-41-54.mp4
2024-06-10.11-42-37.mp4

P. S. I'm sorry if I didn't explain it clearly, my English is not perfect

@00jeser
Copy link
Author

00jeser commented Jun 10, 2024

I researched this problem and found that the function GetOrEstimateAnchorElementForViewport() in RealizedStackElements works incorrectly when the 'for' loop inside it does not call return. If you cache the parameters 'u' and 'i', this problem will be fixed, but it is the wrong approach because it breaks the tests.
00jeser@4e2a8c9

@mihnea-radulescu
Copy link

A similar bug (probably having the same root cause) has been raised by a user of my own application ImageFan Reloaded, with a video attached to this comment exposing the issue.

@PaulWillarson-Scalp
Copy link

@00jeser Any update on this? Perhaps there's a workaround without your code change? This issue is a deal breaker for me being able to use this control.

@busitech
Copy link

busitech commented Sep 19, 2024

We have fixed this issue in our own fork, by abandoning the "Or Estimate" side of the GetOrEstimateAnchorElementForViewport routine. Instead, we are simply calculating the actual widths of columns without estimation. We are presently working on fixing the same problem for the height of rows. After that, we will have to see if AUTO sizing needs further work.

I don't think estimates are of any value in achieving correct "smooth scrolling" behavior, because the nature of an estimate is that it is known to be incorrect by an unknown margin. In your recordings, you are seeing the error of the estimated column width being drawn and never fixed, even after the cells have been realized in the wrong place.

@danwalmsley
Copy link
Member

@busitech could you share the fix for GetOrEstimateAnchorElementForViewport ?

@danwalmsley
Copy link
Member

AvaloniaUI/Avalonia#16168

these changes in the main avalonia repo, may well be relevant to this issue.

@busitech
Copy link

@danwalmsley Yes, I will share a patch file with you. The Avalonia project classes are not used that much in the TreeDataGrid project, which has its own implementation of virtualization.

@busitech
Copy link

@danwalmsley Here is the way we fixed the issue in our project, which is suitable for our use cases.

In a nutshell, our changes remove the use of estimates from the scrolling logic in both directions. This avoids the misaligned cells when horizontally scrolling, and allows us to smoothly page in more records when vertically scrolling. Previously, when the user picked up the gripper or thumb and moved it drastically, or used a trackpad to scroll fast, it confused the control.

For horizontal scrolling, we decided to defer to the columns to represent their own width, and assume there won't be millions of columns (this would not perform well otherwise).

For vertical scrolling, we calculate which row should be visible based on the grid scroll position of the thumb. This assumes there could be millions of rows (and will perform well in that case).

If a use case comes up where there are millions of columns, then the approach we took for rows could be used instead.

Also included is a fix so that right justified labels can be used in TDG cells without being too wide or truncated after a previously cached control is reused.

If you decide to use our patch, let us know if you find a use case they do not support well, or witness any strange behavior.

misalignment fix.patch

@busitech
Copy link

busitech commented Oct 19, 2024

@danwalmsley In my earlier message, I thought you were an end user of Avalonia looking for a solution, but I just noticed you are @ Avalonia... 😂

@danwalmsley
Copy link
Member

@busitech thank you :) I had a few minutes to test your patch. It seems to work! I will get more time this week and see if I can test it a bit more. I did manage to trigger an exception (invalid size returned from measure), but haven't looked into it yet.

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

No branches or pull requests

5 participants