On Wed, 5 Jul 2023 19:30:21 GMT, Andy Goryachev <ango...@openjdk.org> wrote:

>> Modified the resize algorithm to work well with fractional scale, thanks for 
>> deeper understanding of the problem thanks to  @hjohn and @mstr2 .
>> 
>> It is important to note that even though the constraints are given by the 
>> user in unsnapped coordinates, they are converted to snapped values, since 
>> the snapped values correspond to the actual pixels on the display.  This 
>> means the tests that validate honoring constraints should, in all the cases 
>> where (scale != 1.0), assume possibly error not exceeding (1.0 / scale) (I 
>> think).
>
> Andy Goryachev has updated the pull request with a new target base due to a 
> merge or a rebase. The incremental webrev excludes the unrelated changes 
> brought in by the merge/rebase. The pull request contains ten additional 
> commits since the last revision:
> 
>  - whitespace
>  - Merge remote-tracking branch 'origin/master' into 8299753.resize
>  - review comments
>  - review comments
>  - whitespace
>  - removed obsolete tester
>  - Merge remote-tracking branch 'origin/master' into 8299753.resize
>  - cleanup
>  - new algorithm

> > My observation is that this algorithm seems unable to provide a proper user 
> > resizing experience as it seems to discard important information it would 
> > need to do so.
> 
> please elaborate, or point to a specific problem. It is entirely possible 
> that a better algorithm might exist, but it might be out of scope _at the 
> moment_, as this is a follow-up for a specific issue.

It's hard to point to a specific problem when most of the algorithm used would 
be unnecessary if it used the initial conditions + current resize position as 
its basis for calculating the column sizes.  My problem with this 
implementation is that it takes what is fundamentally a very simple algorithm 
(columns have sizes X,Y,Z and Y is resized 10 pixels larger, what should the 
layout be?) and turns it into a frame rate dependent, mouse movement dependent 
delta calculation.  The initial conditions are discarded, and so a single drag 
resize of 10 pixels is NOT the same as a drag resize that captured several 
individual steps (1 +  2 +  3  + 4 pixels), while it really should be...

On top of that, if indeed the algorithm is flawed, as I think it is, then there 
is no way to really fix it apart from some cosmetic changes.  This then would 
be a lot of wasted effort.  As I noted, there is no JUnit test for this code as 
of yet, and for such a complicated algorithm to be verified to be correct, I 
think it would need one to pass review.  If we're willing to forego that, then 
I suppose a casual fix is in the cards, but I can't really see whether or not 
it would be correct (within its fundamental limitations) without extensive 
manual testing.

> > The `SMALL_DELTA` constant that changes behavior on how large a "drag" was 
> > registered is a red flag; this shouldn't matter. The sizes should always be 
> > based on what they were initially (at the start of the drag), and where the 
> > cursor is currently, regardless of what path the cursor took to get there 
> > (ie. there should be no memory effects, the algorithm should only need the 
> > initial sizes + current position).
> 
> This is not my experience. Specifically, the difference in behavior between 
> small changes (when the users resizes the columns slowly and we get small 
> deltas of 1 pixel) and large changes (e.g. when initially resizing the table, 
> or the user moves the mouse quickly) are significant.

Yes, it would be needed with this algorithm as it is dependent on mouse cursor 
speed and frame rate as it has no idea of what the initial positions were and 
how it arrived at the current state.

> For example, I tried to use your SpaceDistributor from #1111 and it suffered 
> from the same problem as bypassing the small delta path (by setting 
> SMALL_DELTA=0) - when the user resizes the columns slowly, the same column 
> gets the pixel and grows wider than the rest.

It would not be sufficient to just replace `ResizeHelper` with something that 
uses the space distributor as the information it needs would still be lost. 
When writing algorithms that resize a UI, using the current size of the 
elements in your UI + a resize amount will never result in a consistent looking 
resize.  It always must be based on their size constraints (which can be 
min/pref/max based for controls that can't be individually resized) or the 
actual sizes when the action started (for splitters or columns). Once the 
action is finished, only then do the new sizes become the initial sizes for the 
next action -- not at every mouse event or frame that elapses.

`HBox` for example doesn't use its **current** sizes to calculate its "new" 
size -- it always goes back to the basic min/pref/max sizes, then looks at the 
space available and computes new sizes based on only that information.  If it 
used the current sizes as its base, you would notice that in certain scenario's 
the final sizes (if you slowly vs quickly resized a window) would not 
necessarily always be the same for the same available width -- that's exactly 
what I think is happening with the column sizes; it's not deterministic and 
can't be because it lacks the information to do so and hence has to resort to 
`SMALL_DELTA` tricks to differentiate between "fast" and "slow" resizes.  
Relying on such things (which can vary with mouse hardware, current framerate, 
CPU/GPU load, amount of visible `Node`s) makes for an inconsistent resize 
experience, even when the column was resized by the exact same amount of pixels 
when the resize ends.

This can I think be fixed relatively easily; all it really would take is to 
track when the drag starts, store the sizes, use these sizes to calculate new 
sizes each time, and when the drag ends, discard the stored sizes.  The 
`ResizeHelper` would then only need a single much simpler method that takes an 
array of sizes, the resizing mode, the space available and which column was 
resized and by how much -- or if you want, you can associate the `ResizeHelper` 
with the drag resize start, and use the same helper while the resize is in 
progress.

-------------

PR Comment: https://git.openjdk.org/jfx/pull/1156#issuecomment-1622392841

Reply via email to