Display: add safeArea property

display.safeArea is a subset of display.bounds that accounts for notches, holes, or other display cutouts.
This commit is contained in:
Josh Tynjala
2025-01-30 15:55:47 -08:00
parent 70efb2a4ec
commit af2299670f
8 changed files with 144 additions and 15 deletions

View File

@@ -40,5 +40,12 @@ class Display
**/
public var supportedModes(default, null):Array<DisplayMode>;
/**
The area within the display's `bounds` where it is safe to render
content without being obscured by notches, holes, or other display
cutouts.
**/
public var safeArea(default, null):Rectangle;
@:noCompletion private function new() {}
}

View File

@@ -248,6 +248,22 @@ class System
display.bounds = new Rectangle(displayInfo.bounds.x, displayInfo.bounds.y, displayInfo.bounds.width, displayInfo.bounds.height);
display.orientation = displayInfo.orientation;
#if android
var getDisplaySafeArea = JNI.createStaticMethod("org/haxe/lime/GameActivity", "getDisplaySafeAreaInsets", "()[I");
var result = getDisplaySafeArea();
display.safeArea = new Rectangle(
display.bounds.x + result[0],
display.bounds.y + result[1],
display.bounds.width - result[0] - result[2],
display.bounds.height - result[1] - result[3]);
#else
display.safeArea = new Rectangle(
displayInfo.safeArea.x,
displayInfo.safeArea.y,
displayInfo.safeArea.width,
displayInfo.safeArea.height);
#end
#if ios
var tablet = NativeCFFI.lime_system_get_ios_tablet();
var scale = Application.current.window.scale;