Skip to content

Commit

Permalink
Considered Gluon perfect scrolling on mobiles in getVerticalScrollbar…
Browse files Browse the repository at this point in the history
…ExtraWidth()
  • Loading branch information
salmonb committed Dec 8, 2023
1 parent 8b2559f commit a38e66c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
6 changes: 6 additions & 0 deletions webfx-kit/webfx-kit-openjfx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
<version>0.1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>dev.webfx</groupId>
<artifactId>webfx-platform-os</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>dev.webfx</groupId>
<artifactId>webfx-platform-scheduler</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.webfx.kit.launcher.spi.impl.openjfx;

import dev.webfx.kit.launcher.spi.FastPixelReaderWriter;
import dev.webfx.platform.os.OperatingSystem;
import javafx.application.Application;
import javafx.application.HostServices;
import javafx.geometry.Bounds;
Expand All @@ -19,7 +20,7 @@
*/
public final class JavaFxWebFxKitLauncherProvider extends WebFxKitLauncherProviderBase {

private static List<Runnable> readyRunnables = new ArrayList<>();
private static List<Runnable> onReadyRunnables = new ArrayList<>();
private static Factory<Application> applicationFactory;

private static Stage primaryStage;
Expand All @@ -31,7 +32,8 @@ public JavaFxWebFxKitLauncherProvider() {

@Override
public double getVerticalScrollbarExtraWidth() {
return 16;
// OpenJFX has a 15px bar width on desktops, but Gluon provides a perfect scrollbar on mobiles (not introducing extra space)
return OperatingSystem.isMobile() ? 0 : 15;
}

@Override
Expand Down Expand Up @@ -66,24 +68,24 @@ private static void onJavaFxToolkitReady() {

@Override
public boolean isReady() {
return readyRunnables == null;
return onReadyRunnables == null;
}

@Override
public void onReady(Runnable runnable) {
synchronized (JavaFxWebFxKitLauncherProvider.class) {
if (readyRunnables != null)
readyRunnables.add(runnable);
if (onReadyRunnables != null)
onReadyRunnables.add(runnable);
else
super.onReady(runnable);
}
}

private static void executeReadyRunnables() {
synchronized (JavaFxWebFxKitLauncherProvider.class) {
if (readyRunnables != null) {
List<Runnable> runnables = readyRunnables;
readyRunnables = null;
if (onReadyRunnables != null) {
List<Runnable> runnables = onReadyRunnables;
onReadyRunnables = null;
//runnables.forEach(Runnable::run); doesn't work on Android
for (Runnable runnable : runnables)
runnable.run();
Expand Down Expand Up @@ -128,8 +130,8 @@ public Bounds measureText(String text, Font font) {

@Override
public double measureBaselineOffset(Font font) {
Text text = new Text("Baseline text");
text.setFont(font);
return text.getBaselineOffset();
measurementText.setText("Baseline text");
measurementText.setFont(font);
return measurementText.getBaselineOffset();
}
}
1 change: 1 addition & 0 deletions webfx-kit/webfx-kit-openjfx/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
requires webfx.kit.javafxgraphics.peers;
requires webfx.kit.javafxgraphics.peers.base;
requires webfx.kit.launcher;
requires webfx.platform.os;
requires webfx.platform.scheduler;
requires webfx.platform.uischeduler;
requires webfx.platform.util;
Expand Down

0 comments on commit a38e66c

Please sign in to comment.