mirror of
https://github.com/love2d/love.git
synced 2026-08-18 11:44:15 +02:00
Add love.window.getSafeArea (resolves issue #1437). Returns a rectangle (x, y, w, h) inside the window which is known to be unobstructed by a system title bar, the iPhone X notch, etc. Useful for making sure UI elements can be seen by the user.
Currently it only has a proper implementation on iOS and will return the window's full size otherwise.
This commit is contained in:
+41
-3
@@ -31,6 +31,8 @@
|
||||
#include <vector>
|
||||
|
||||
#include <SDL_events.h>
|
||||
#include <SDL_video.h>
|
||||
#include <SDL_syswm.h>
|
||||
|
||||
static NSArray *getLovesInDocuments();
|
||||
static bool deleteFileInDocuments(NSString *filename);
|
||||
@@ -362,9 +364,45 @@ void setAudioMixWithOthers(bool mixEnabled)
|
||||
|
||||
bool hasBackgroundMusic()
|
||||
{
|
||||
if ([[AVAudioSession sharedInstance] respondsToSelector:@selector(secondaryAudioShouldBeSilencedHint)])
|
||||
return [[AVAudioSession sharedInstance] secondaryAudioShouldBeSilencedHint];
|
||||
return false;
|
||||
@autoreleasepool
|
||||
{
|
||||
AVAudioSession *session = [AVAudioSession sharedInstance];
|
||||
if ([session respondsToSelector:@selector(secondaryAudioShouldBeSilencedHint)])
|
||||
return session.secondaryAudioShouldBeSilencedHint;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Rect getSafeArea(SDL_Window *window)
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
Rect rect = {};
|
||||
SDL_GetWindowSize(window, &rect.w, &rect.h);
|
||||
|
||||
SDL_SysWMinfo info = {};
|
||||
SDL_VERSION(&info.version);
|
||||
if (SDL_GetWindowWMInfo(window, &info))
|
||||
{
|
||||
UIView *view = info.info.uikit.window.rootViewController.view;
|
||||
if (@available(iOS 11.0, tvOS 11.0, *))
|
||||
{
|
||||
UIEdgeInsets insets = view.safeAreaInsets;
|
||||
|
||||
rect.x += insets.left;
|
||||
rect.w -= insets.left;
|
||||
|
||||
rect.w -= insets.right;
|
||||
|
||||
rect.y += insets.top;
|
||||
rect.h -= insets.top;
|
||||
|
||||
rect.h -= insets.bottom;
|
||||
}
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
}
|
||||
|
||||
} // ios
|
||||
|
||||
Reference in New Issue
Block a user