RFR: 8178297: TableView scrolls slightly when adding new elements [v2]
Kevin Rushforth
kcr at openjdk.java.net
Fri Oct 9 23:52:06 UTC 2020
On Wed, 23 Sep 2020 10:26:12 GMT, Jose Pereda <jpereda at openjdk.org> wrote:
>> This PR fixes an issue that happens when adding new items to a `TableView` or any other control that uses
>> `VirtualFlow`, if the scroll position is not 0: the virtual flow is slightly shifted down.
>> For instance, let's say that a cell has a layoutY of -10.0. After adding a new item to the table, during the layout
>> pass the new value is initially modified to -9.999999999999996 (`VirtualFlow::adjustByPixelAmount`) , and then, after
>> calling `VirtualFlow::positionCell` (that uses `snapSizeY(position)`) the layoutY is modified to -9.5, causing an
>> undesired positive shift of 0.5 pixels. `Region` has different snap methods: `snapSizeX/Y` are used to snap node
>> dimension values, like width or height, by ceiling to the nearest pixel (which explains the -9.5 value), while
>> `snapSpaceX/Y` are used to snap position values like insets, by rounding to the nearest pixel (this will give the
>> expected -10.0). Therefore, this PR modifies `VirtualFlow::positionCell` to use the `snapSpaceX/Y` methods, since
>> these are being used to set the layout of the cell and not its size. Test: A unity test has been included. It
>> simulates the case of adding new items to the virtual flow after an initial scroll. It currently fails after adding a
>> few items, and it passes with the changes of this PR.
>
> Jose Pereda has updated the pull request with a new target base due to a merge or a rebase. The pull request now
> contains three commits:
> - Merge master
> - Add test to verify the cell position remains constant when new cells are added to the virtualFlow.
> - Use correct snap method to set cell layout
Looks good.
-------------
Marked as reviewed by kcr (Lead).
PR: https://git.openjdk.java.net/jfx/pull/297
More information about the openjfx-dev
mailing list