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:
Alex Szpakowski
2018-12-26 00:34:14 -04:00
parent 1c853cbcc3
commit d41aca836e
6 changed files with 81 additions and 3 deletions
+14
View File
@@ -27,6 +27,10 @@
#include "common/android.h"
#endif
#ifdef LOVE_IOS
#include "common/ios.h"
#endif
// C++
#include <iostream>
#include <vector>
@@ -839,6 +843,16 @@ void Window::getPosition(int &x, int &y, int &displayindex)
}
}
Rect Window::getSafeArea() const
{
#ifdef LOVE_IOS
if (window != nullptr)
return love::ios::getSafeArea(window);
#endif
return {0, 0, getWidth(), getHeight()};
}
bool Window::isOpen() const
{
return open;
+2
View File
@@ -66,6 +66,8 @@ public:
void setPosition(int x, int y, int displayindex) override;
void getPosition(int &x, int &y, int &displayindex) override;
Rect getSafeArea() const override;
bool isOpen() const override;
void setWindowTitle(const std::string &title) override;