mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +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:
@@ -24,6 +24,7 @@
|
||||
// LOVE
|
||||
#include "common/Module.h"
|
||||
#include "common/StringMap.h"
|
||||
#include "common/math.h"
|
||||
#include "image/ImageData.h"
|
||||
|
||||
// C++
|
||||
@@ -151,6 +152,8 @@ public:
|
||||
virtual void setPosition(int x, int y, int displayindex) = 0;
|
||||
virtual void getPosition(int &x, int &y, int &displayindex) = 0;
|
||||
|
||||
virtual Rect getSafeArea() const = 0;
|
||||
|
||||
virtual bool isOpen() const = 0;
|
||||
|
||||
virtual void setWindowTitle(const std::string &title) = 0;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -365,6 +365,16 @@ int w_getPosition(lua_State *L)
|
||||
return 3;
|
||||
}
|
||||
|
||||
int w_getSafeArea(lua_State *L)
|
||||
{
|
||||
Rect area = instance()->getSafeArea();
|
||||
lua_pushnumber(L, area.x);
|
||||
lua_pushnumber(L, area.y);
|
||||
lua_pushnumber(L, area.w);
|
||||
lua_pushnumber(L, area.h);
|
||||
return 4;
|
||||
}
|
||||
|
||||
int w_setIcon(lua_State *L)
|
||||
{
|
||||
image::ImageData *i = luax_checktype<image::ImageData>(L, 1);
|
||||
@@ -607,6 +617,7 @@ static const luaL_Reg functions[] =
|
||||
{ "getDesktopDimensions", w_getDesktopDimensions },
|
||||
{ "setPosition", w_setPosition },
|
||||
{ "getPosition", w_getPosition },
|
||||
{ "getSafeArea", w_getSafeArea },
|
||||
{ "setIcon", w_setIcon },
|
||||
{ "getIcon", w_getIcon },
|
||||
{ "setVSync", w_setVSync },
|
||||
|
||||
Reference in New Issue
Block a user