chore: Smooth scroller (kinda)
This commit is contained in:
@@ -62,6 +62,7 @@ public class AbsencesController extends DashboardBaseController {
|
|||||||
loadingIndicator.setVisible(false);
|
loadingIndicator.setVisible(false);
|
||||||
|
|
||||||
if (result.isSuccess() && result.getData().isPresent()) {
|
if (result.isSuccess() && result.getData().isPresent()) {
|
||||||
|
cz.jzitnik.util.ScrollUtils.enableSmoothScrolling(scrollPane);
|
||||||
currentPage = result.getData().get();
|
currentPage = result.getData().get();
|
||||||
renderAbsences();
|
renderAbsences();
|
||||||
scrollPane.setVisible(true);
|
scrollPane.setVisible(true);
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ public class ClassroomDetailController extends DashboardBaseController {
|
|||||||
loadingIndicator.setVisible(false);
|
loadingIndicator.setVisible(false);
|
||||||
|
|
||||||
if (result.isSuccess() && result.getData().isPresent()) {
|
if (result.isSuccess() && result.getData().isPresent()) {
|
||||||
|
cz.jzitnik.util.ScrollUtils.enableSmoothScrolling(scrollPane);
|
||||||
renderRoom(result.getData().get());
|
renderRoom(result.getData().get());
|
||||||
scrollPane.setVisible(true);
|
scrollPane.setVisible(true);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public class ClassroomsController extends DashboardBaseController {
|
|||||||
loadingIndicator.setVisible(false);
|
loadingIndicator.setVisible(false);
|
||||||
|
|
||||||
if (result.isSuccess() && result.getData().isPresent()) {
|
if (result.isSuccess() && result.getData().isPresent()) {
|
||||||
|
cz.jzitnik.util.ScrollUtils.enableSmoothScrolling(scrollPane);
|
||||||
RoomsPage page = result.getData().get();
|
RoomsPage page = result.getData().get();
|
||||||
allRooms = new ArrayList<>(page.getRoomReferences());
|
allRooms = new ArrayList<>(page.getRoomReferences());
|
||||||
// Sort by name
|
// Sort by name
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ public class GradesController extends DashboardBaseController {
|
|||||||
loadingIndicator.setVisible(false);
|
loadingIndicator.setVisible(false);
|
||||||
|
|
||||||
if (result.isSuccess() && result.getData().isPresent()) {
|
if (result.isSuccess() && result.getData().isPresent()) {
|
||||||
|
cz.jzitnik.util.ScrollUtils.enableSmoothScrolling(scrollPane);
|
||||||
scrollPane.setVisible(true);
|
scrollPane.setVisible(true);
|
||||||
currentPage = result.getData().get();
|
currentPage = result.getData().get();
|
||||||
renderAllSubjects();
|
renderAllSubjects();
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public class TeachersController extends DashboardBaseController {
|
|||||||
loadingIndicator.setVisible(false);
|
loadingIndicator.setVisible(false);
|
||||||
|
|
||||||
if (result.isSuccess() && result.getData().isPresent()) {
|
if (result.isSuccess() && result.getData().isPresent()) {
|
||||||
|
cz.jzitnik.util.ScrollUtils.enableSmoothScrolling(scrollPane);
|
||||||
TeachersPage page = result.getData().get();
|
TeachersPage page = result.getData().get();
|
||||||
allTeachers = new ArrayList<>(page.getTeachersReferences());
|
allTeachers = new ArrayList<>(page.getTeachersReferences());
|
||||||
allTeachers.sort((t1, t2) -> t1.getFullName().compareToIgnoreCase(t2.getFullName()));
|
allTeachers.sort((t1, t2) -> t1.getFullName().compareToIgnoreCase(t2.getFullName()));
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public class TimetableController extends DashboardBaseController {
|
|||||||
loadingIndicator.setVisible(false);
|
loadingIndicator.setVisible(false);
|
||||||
|
|
||||||
if (result.isSuccess() && result.getData().isPresent()) {
|
if (result.isSuccess() && result.getData().isPresent()) {
|
||||||
|
cz.jzitnik.util.ScrollUtils.enableSmoothScrolling(scrollPane);
|
||||||
scrollPane.setVisible(true);
|
scrollPane.setVisible(true);
|
||||||
currentPage = result.getData().get();
|
currentPage = result.getData().get();
|
||||||
renderTimetable();
|
renderTimetable();
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package cz.jzitnik.util;
|
||||||
|
|
||||||
|
import javafx.animation.KeyFrame;
|
||||||
|
import javafx.animation.KeyValue;
|
||||||
|
import javafx.animation.Timeline;
|
||||||
|
import javafx.scene.control.ScrollPane;
|
||||||
|
import javafx.scene.input.ScrollEvent;
|
||||||
|
import javafx.util.Duration;
|
||||||
|
|
||||||
|
public class ScrollUtils {
|
||||||
|
|
||||||
|
public static void enableSmoothScrolling(ScrollPane scrollPane) {
|
||||||
|
scrollPane.addEventFilter(ScrollEvent.SCROLL, event -> {
|
||||||
|
double deltaY = event.getDeltaY();
|
||||||
|
double contentHeight = scrollPane.getContent().getBoundsInLocal().getHeight();
|
||||||
|
double viewportHeight = scrollPane.getViewportBounds().getHeight();
|
||||||
|
|
||||||
|
// Calculate new VValue based on delta
|
||||||
|
double deltaV = (-deltaY * 2.0) / (contentHeight - viewportHeight);
|
||||||
|
double newValue = scrollPane.getVvalue() + deltaV;
|
||||||
|
|
||||||
|
// Constrain to [0, 1]
|
||||||
|
newValue = Math.max(0, Math.min(1, newValue));
|
||||||
|
|
||||||
|
// Animate
|
||||||
|
Timeline timeline = new Timeline();
|
||||||
|
KeyValue kv = new KeyValue(scrollPane.vvalueProperty(), newValue);
|
||||||
|
KeyFrame kf = new KeyFrame(Duration.millis(120), kv);
|
||||||
|
timeline.getKeyFrames().add(kf);
|
||||||
|
timeline.play();
|
||||||
|
|
||||||
|
event.consume();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user