-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turned safeAreaInsets into a JavaFX property
- Loading branch information
Showing
4 changed files
with
39 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,7 @@ | |
import elemental2.dom.*; | ||
import javafx.application.Application; | ||
import javafx.application.HostServices; | ||
import javafx.beans.property.DoubleProperty; | ||
import javafx.beans.property.SimpleDoubleProperty; | ||
import javafx.beans.property.*; | ||
import javafx.collections.ObservableList; | ||
import javafx.geometry.BoundingBox; | ||
import javafx.geometry.Bounds; | ||
|
@@ -257,8 +256,19 @@ public Application getApplication() { | |
return application; | ||
} | ||
|
||
private ObjectProperty<Insets> safeAreaInsetsProperty = null; | ||
|
||
@Override | ||
public Insets getSafeAreaInsets() { | ||
public ReadOnlyObjectProperty<Insets> safeAreaInsetsProperty() { | ||
if (safeAreaInsetsProperty == null) { | ||
safeAreaInsetsProperty = new SimpleObjectProperty<>(Insets.EMPTY); | ||
FXProperties.runNowAndOnPropertiesChange(this::updateSafeAreaInsets, | ||
getPrimaryStage().widthProperty(), getPrimaryStage().heightProperty()); | ||
} | ||
return safeAreaInsetsProperty; | ||
} | ||
|
||
public void updateSafeAreaInsets() { | ||
/* The following code is relying on this CSS rule present in [email protected] | ||
:root { | ||
--safe-area-inset-top: env(safe-area-inset-top); | ||
|
@@ -272,11 +282,11 @@ public Insets getSafeAreaInsets() { | |
String right = computedStyle.getPropertyValue("--safe-area-inset-right"); | ||
String bottom = computedStyle.getPropertyValue("--safe-area-inset-bottom"); | ||
String left = computedStyle.getPropertyValue("--safe-area-inset-left"); | ||
return new Insets( | ||
Numbers.doubleValue(Strings.removeSuffix(top, "px")), | ||
Numbers.doubleValue(Strings.removeSuffix(right, "px")), | ||
Numbers.doubleValue(Strings.removeSuffix(bottom, "px")), | ||
Numbers.doubleValue(Strings.removeSuffix(left, "px")) | ||
); | ||
safeAreaInsetsProperty.set(new Insets( | ||
Numbers.doubleValue(Strings.removeSuffix(top, "px")), | ||
Numbers.doubleValue(Strings.removeSuffix(right, "px")), | ||
Numbers.doubleValue(Strings.removeSuffix(bottom, "px")), | ||
Numbers.doubleValue(Strings.removeSuffix(left, "px")) | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters