Skip to content

Commit 1fd9117

Browse files
committed
Add function to get iOS insets
1 parent 3a8204f commit 1fd9117

File tree

7 files changed

+36
-2
lines changed

7 files changed

+36
-2
lines changed

src/core/include/growl/core/api/graphics_api.h

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Shader;
1515
class ShaderPack;
1616
class Texture;
1717
class TextureAtlas;
18+
struct WindowSafeAreaInsets;
1819

1920
class GraphicsAPI {
2021

@@ -47,6 +48,8 @@ class GraphicsAPI {
4748
createShader(const std::string& fragment_src) = 0;
4849
virtual Result<std::unique_ptr<Shader>>
4950
createShader(const ShaderPack& shader_pack) = 0;
51+
52+
virtual WindowSafeAreaInsets getSafeAreaInsets() = 0;
5053
};
5154

5255
} // namespace Growl

src/core/include/growl/core/graphics/batch.h

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class Batch {
2323
Batch& operator=(Batch&&) = default;
2424

2525
virtual void clear(float r, float g, float b) = 0;
26+
virtual void clear(Color color) {
27+
clear(color.r, color.g, color.b);
28+
}
2629
virtual void begin() = 0;
2730
virtual void end() = 0;
2831

src/core/include/growl/core/graphics/window.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33
#include "growl/core/error.h"
44
namespace Growl {
55

6+
struct WindowSafeAreaInsets {
7+
float top;
8+
float bottom;
9+
float left;
10+
float right;
11+
};
12+
613
class Window {
714
public:
815
virtual ~Window() = default;
9-
virtual void flip() {};
10-
virtual void getSize(int* w, int* h) {};
16+
virtual void flip() {}
17+
virtual void getSize(int* w, int* h) {}
18+
virtual WindowSafeAreaInsets getSafeAreaInsets() {
19+
return WindowSafeAreaInsets{0, 0, 0, 0};
20+
}
1121

1222
virtual void* getMetalLayer() {
1323
return nullptr;

src/plugins/ios/src/ios_window.h

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class IOSWindow final : public Window {
1212

1313
void* getMetalLayer() override;
1414

15+
virtual WindowSafeAreaInsets getSafeAreaInsets() override;
16+
1517
private:
1618
UIWindow* native;
1719
};

src/plugins/ios/src/ios_window.mm

+8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
#include "ios_window.h"
22

33
using Growl::IOSWindow;
4+
using Growl::WindowSafeAreaInsets;
45

56
void* IOSWindow::getMetalLayer() {
67
return native.rootViewController.view.layer;
78
}
9+
10+
WindowSafeAreaInsets IOSWindow::getSafeAreaInsets() {
11+
auto insets = native.safeAreaInsets;
12+
return WindowSafeAreaInsets{
13+
static_cast<float>(insets.top), static_cast<float>(insets.bottom),
14+
static_cast<float>(insets.left), static_cast<float>(insets.right)};
15+
}

src/plugins/metal/src/metal_graphics.h

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class MetalGraphicsAPI : public GraphicsAPIInternal {
5656
return window.get();
5757
}
5858

59+
WindowSafeAreaInsets getSafeAreaInsets() override {
60+
return getWindow()->getSafeAreaInsets();
61+
}
62+
5963
id<MTLCommandBuffer> getCommandBuffer() {
6064
return command_buffer;
6165
}

src/plugins/opengl/src/opengl_graphics.h

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class OpenGLGraphicsAPI : public GraphicsAPIInternal {
5757
Result<std::unique_ptr<Shader>>
5858
createShader(const ShaderPack& shader_pack) override;
5959

60+
WindowSafeAreaInsets getSafeAreaInsets() override {
61+
return getWindow()->getSafeAreaInsets();
62+
}
63+
6064
Window* getWindow() override {
6165
return window.get();
6266
}

0 commit comments

Comments
 (0)