Adjust mouse scroll speed to height of the scrollpane content

This commit is contained in:
0xb00bface 2020-11-14 19:25:51 +01:00
parent 13eef32ffb
commit e96bdc1c7e
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,31 @@
package ctbrec.ui.controls;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.skin.ScrollPaneSkin;
import javafx.scene.input.ScrollEvent;
public class FasterVerticalScrollPaneSkin extends ScrollPaneSkin {
public FasterVerticalScrollPaneSkin(final ScrollPane scrollPane) {
super(scrollPane);
getSkinnable().addEventFilter(ScrollEvent.SCROLL, event -> {
double ratio = scrollPane.getViewportBounds().getHeight() / scrollPane.getContent().getBoundsInLocal().getHeight();
double baseUnitIncrement = 0.15;
double unitIncrement = baseUnitIncrement * ratio * 1.25;
getVerticalScrollBar().setUnitIncrement(unitIncrement);
if (event.getDeltaX() < 0) {
getHorizontalScrollBar().increment();
} else if (event.getDeltaX() > 0) {
getHorizontalScrollBar().decrement();
}
if (event.getDeltaY() < 0) {
getVerticalScrollBar().increment();
} else if (event.getDeltaY() > 0) {
getVerticalScrollBar().decrement();
}
event.consume();
});
}
}

View File

@ -42,6 +42,7 @@ import ctbrec.ui.action.OpenRecordingsDir;
import ctbrec.ui.controls.SearchBox;
import ctbrec.ui.controls.SearchPopover;
import ctbrec.ui.controls.SearchPopoverTreeList;
import ctbrec.ui.controls.FasterVerticalScrollPaneSkin;
import javafx.animation.FadeTransition;
import javafx.animation.Interpolator;
import javafx.animation.ParallelTransition;
@ -196,6 +197,8 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
scrollPane.setContent(grid);
scrollPane.setFitToHeight(true);
scrollPane.setFitToWidth(true);
FasterVerticalScrollPaneSkin scrollPaneSkin = new FasterVerticalScrollPaneSkin(scrollPane);
scrollPane.setSkin(scrollPaneSkin);
BorderPane.setMargin(scrollPane, new Insets(5));
pagination = new HBox(5);