优化 JFXListView 的平滑滚动效果 (#5052)
This commit is contained in:
@@ -25,7 +25,6 @@ import javafx.animation.Animation.Status;
|
|||||||
import javafx.animation.KeyFrame;
|
import javafx.animation.KeyFrame;
|
||||||
import javafx.animation.Timeline;
|
import javafx.animation.Timeline;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.scene.control.IndexedCell;
|
|
||||||
import javafx.scene.control.ScrollPane;
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.control.skin.VirtualFlow;
|
import javafx.scene.control.skin.VirtualFlow;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
@@ -226,7 +225,6 @@ final class ScrollUtils {
|
|||||||
final double[] derivatives = new double[FRICTIONS.length];
|
final double[] derivatives = new double[FRICTIONS.length];
|
||||||
|
|
||||||
Timeline timeline = new Timeline();
|
Timeline timeline = new Timeline();
|
||||||
Holder<ScrollDirection> scrollDirectionHolder = new Holder<>();
|
|
||||||
final EventHandler<MouseEvent> mouseHandler = event -> timeline.stop();
|
final EventHandler<MouseEvent> mouseHandler = event -> timeline.stop();
|
||||||
final EventHandler<ScrollEvent> scrollHandler = event -> {
|
final EventHandler<ScrollEvent> scrollHandler = event -> {
|
||||||
if (event.getEventType() == ScrollEvent.SCROLL) {
|
if (event.getEventType() == ScrollEvent.SCROLL) {
|
||||||
@@ -234,7 +232,6 @@ final class ScrollUtils {
|
|||||||
if (scrollDirection == ScrollDirection.LEFT || scrollDirection == ScrollDirection.RIGHT) {
|
if (scrollDirection == ScrollDirection.LEFT || scrollDirection == ScrollDirection.RIGHT) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
scrollDirectionHolder.value = scrollDirection;
|
|
||||||
double currentSpeed = isTrackPad(event, scrollDirection) ? speed / trackPadAdjustment : speed;
|
double currentSpeed = isTrackPad(event, scrollDirection) ? speed / trackPadAdjustment : speed;
|
||||||
|
|
||||||
derivatives[0] += scrollDirection.intDirection * currentSpeed;
|
derivatives[0] += scrollDirection.intDirection * currentSpeed;
|
||||||
@@ -256,15 +253,7 @@ final class ScrollUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double dy = derivatives[derivatives.length - 1];
|
double dy = derivatives[derivatives.length - 1];
|
||||||
|
virtualFlow.scrollPixels(dy);
|
||||||
int cellCount = virtualFlow.getCellCount();
|
|
||||||
IndexedCell<?> firstVisibleCell = virtualFlow.getFirstVisibleCell();
|
|
||||||
double height = firstVisibleCell != null ? firstVisibleCell.getHeight() * cellCount : 0.0;
|
|
||||||
|
|
||||||
double delta = height > 0.0
|
|
||||||
? dy / height
|
|
||||||
: (scrollDirectionHolder.value == ScrollDirection.DOWN ? 0.001 : -0.001);
|
|
||||||
virtualFlow.setPosition(Math.min(Math.max(virtualFlow.getPosition() + delta, 0), 1));
|
|
||||||
|
|
||||||
if (Math.abs(dy) < 0.001) {
|
if (Math.abs(dy) < 0.001) {
|
||||||
timeline.stop();
|
timeline.stop();
|
||||||
|
|||||||
Reference in New Issue
Block a user