Bug 565883

Summary: [GTK] Scrolling in Canvas is different than in Table
Product: [Eclipse Project] Platform Reporter: Thomas Singer <ts-swt>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: alexandr.miloslavskiy, sdamrong, ts-swt
Version: 4.15   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=565426
Whiteboard:
Attachments:
Description Flags
Snippet to reproduce
none
After scrolling 2 steps
none
Snippet with large scroll steps in Canvas none

Description Thomas Singer CLA 2020-08-07 05:44:31 EDT
Please launch the attached snippet on Linux and use the mouse wheel to scroll. In the left Canvas scrolling appears to be much slower (sometimes one mouse wheel step does not result in any scrolling at all) then in the right Table (often one mouse wheel step results in 2 scrolled rows).
Comment 1 Thomas Singer CLA 2020-08-07 05:45:15 EDT
Created attachment 283811 [details]
Snippet to reproduce
Comment 2 Thomas Singer CLA 2020-08-07 05:46:50 EDT
Created attachment 283812 [details]
After scrolling 2 steps
Comment 3 Thomas Singer CLA 2020-08-07 06:17:37 EDT
Created attachment 283813 [details]
Snippet with large scroll steps in Canvas
Comment 4 Thomas Singer CLA 2020-08-07 06:18:50 EDT
In the "Snippet with large scroll steps in Canvas" it scrolls 9 rows (Canvas) vs. 2 (Table) per mouse wheel step.
Comment 5 Soraphol (Paul) Damrongpiriyapong CLA 2020-08-21 14:33:53 EDT
Hello, I have tested the snippets and reproduce the same results. However, I'm not sure what the problem is here. Since the canvas scrollbar is having custom values set, it will be different than the Table scroll speed.
Comment 6 Thomas Singer CLA 2020-08-24 03:43:10 EDT
(In reply to Soraphol (Paul) Damrongpiriyapong from comment #5)
> Since the canvas scrollbar is having
> custom values set, it will be different than the Table scroll speed.

Try to implement a table-like control (which we did because Table was too slow on some platforms to handle large amounts of data). The user will expect to see the same scroll effect on a Table or custom control. On Windows it works as expected, but not on Linux.
Comment 7 Alexandr Miloslavskiy CLA 2020-09-21 11:18:46 EDT
I found that GTK table behaves the following way (in GTK terms):
1) Scrolling speed is calculated from verticalBar.setThumb()
2) GTK's Table passes Table height to verticalBar.setThumb()
3) The final formula is for pixels scrolled per wheel step:
   min(tableHeight/2, pow(tableHeight, 2/3))

Note that on Windows, scrolling speed does not depend on tableHeight.

So in order to mimic the behavior of GTK, one should do the following:
1) Set max of verticalBar to total pixel height of contents
2) verticalBar.setThumb(canvas.getSize().y)
3) Consider 'verticalBar.getSelection()' to be measured in pixels.

Note that measuring in anything but pixels is hard because GTK uses pow(,2/3) and SWT discards fractional part of 'verticalBar.getSelection()'.

References in GTK code:
* get_scroll_unit() in gtkscrolledwindow.c
* gtk_adjustment_configure() in gtk_tree_view_size_allocate()