Skip to content

Commit 9f682e0

Browse files
authored
[release/3.9] 优化 JFXListView 的平滑滚动效果 (#5228)
#5052
1 parent eac12ef commit 9f682e0

1 file changed

Lines changed: 1 addition & 12 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/ui/ScrollUtils.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import javafx.animation.KeyFrame;
2626
import javafx.animation.Timeline;
2727
import javafx.event.EventHandler;
28-
import javafx.scene.control.IndexedCell;
2928
import javafx.scene.control.ScrollPane;
3029
import javafx.scene.control.skin.VirtualFlow;
3130
import javafx.scene.input.MouseEvent;
@@ -226,15 +225,13 @@ private static void smoothScroll(VirtualFlow<?> virtualFlow, double speed, doubl
226225
final double[] derivatives = new double[FRICTIONS.length];
227226

228227
Timeline timeline = new Timeline();
229-
Holder<ScrollDirection> scrollDirectionHolder = new Holder<>();
230228
final EventHandler<MouseEvent> mouseHandler = event -> timeline.stop();
231229
final EventHandler<ScrollEvent> scrollHandler = event -> {
232230
if (event.getEventType() == ScrollEvent.SCROLL) {
233231
ScrollDirection scrollDirection = determineScrollDirection(event);
234232
if (scrollDirection == ScrollDirection.LEFT || scrollDirection == ScrollDirection.RIGHT) {
235233
return;
236234
}
237-
scrollDirectionHolder.value = scrollDirection;
238235
double currentSpeed = isTrackPad(event, scrollDirection) ? speed / trackPadAdjustment : speed;
239236

240237
derivatives[0] += scrollDirection.intDirection * currentSpeed;
@@ -256,15 +253,7 @@ private static void smoothScroll(VirtualFlow<?> virtualFlow, double speed, doubl
256253
}
257254

258255
double dy = derivatives[derivatives.length - 1];
259-
260-
int cellCount = virtualFlow.getCellCount();
261-
IndexedCell<?> firstVisibleCell = virtualFlow.getFirstVisibleCell();
262-
double height = firstVisibleCell != null ? firstVisibleCell.getHeight() * cellCount : 0.0;
263-
264-
double delta = height > 0.0
265-
? dy / height
266-
: (scrollDirectionHolder.value == ScrollDirection.DOWN ? 0.001 : -0.001);
267-
virtualFlow.setPosition(Math.min(Math.max(virtualFlow.getPosition() + delta, 0), 1));
256+
virtualFlow.scrollPixels(dy);
268257

269258
if (Math.abs(dy) < 0.001) {
270259
timeline.stop();

0 commit comments

Comments
 (0)