summaryrefslogtreecommitdiffstats
path: root/platform/ios
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2024-01-19 20:46:26 +0200
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2024-02-13 18:38:53 +0200
commitee53ae28dff4ca227ba970c733bf89d53f432141 (patch)
treee06843f4904ae6aafeeb99b1beaade6a96dff74e /platform/ios
parente92d55bbf417aa9f4592a863cb5b2c7ba0740e21 (diff)
downloadredot-engine-ee53ae28dff4ca227ba970c733bf89d53f432141.tar.gz
Add method to get "base" system UI color (macOS/Windows) and system theme change callback.
Diffstat (limited to 'platform/ios')
-rw-r--r--platform/ios/display_server_ios.h8
-rw-r--r--platform/ios/display_server_ios.mm10
-rw-r--r--platform/ios/godot_view.mm17
3 files changed, 33 insertions, 2 deletions
diff --git a/platform/ios/display_server_ios.h b/platform/ios/display_server_ios.h
index 3efd2498d4..6f66783a47 100644
--- a/platform/ios/display_server_ios.h
+++ b/platform/ios/display_server_ios.h
@@ -77,6 +77,8 @@ class DisplayServerIOS : public DisplayServer {
Callable input_event_callback;
Callable input_text_callback;
+ Callable system_theme_changed;
+
int virtual_keyboard_height = 0;
void perform_event(const Ref<InputEvent> &p_event);
@@ -109,6 +111,8 @@ public:
void send_window_event(DisplayServer::WindowEvent p_event) const;
void _window_callback(const Callable &p_callable, const Variant &p_arg) const;
+ void emit_system_theme_changed();
+
// MARK: - Input
// MARK: Touches and Apple Pencil
@@ -145,6 +149,7 @@ public:
virtual bool is_dark_mode_supported() const override;
virtual bool is_dark_mode() const override;
+ virtual void set_system_theme_change_callback(const Callable &p_callable) override;
virtual Rect2i get_display_safe_area() const override;
@@ -159,8 +164,7 @@ public:
virtual Vector<DisplayServer::WindowID> get_window_list() const override;
- virtual WindowID
- get_window_at_screen_position(const Point2i &p_position) const override;
+ virtual WindowID get_window_at_screen_position(const Point2i &p_position) const override;
virtual int64_t window_get_native_handle(HandleType p_handle_type, WindowID p_window = MAIN_WINDOW_ID) const override;
diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm
index 2895dffdfa..ed69b91fdd 100644
--- a/platform/ios/display_server_ios.mm
+++ b/platform/ios/display_server_ios.mm
@@ -387,6 +387,16 @@ bool DisplayServerIOS::is_dark_mode() const {
}
}
+void DisplayServerIOS::set_system_theme_change_callback(const Callable &p_callable) {
+ system_theme_changed = p_callable;
+}
+
+void DisplayServerIOS::emit_system_theme_changed() {
+ if (system_theme_changed.is_valid()) {
+ system_theme_changed.call();
+ }
+}
+
Rect2i DisplayServerIOS::get_display_safe_area() const {
UIEdgeInsets insets = UIEdgeInsetsZero;
UIView *view = AppDelegate.viewController.godotView;
diff --git a/platform/ios/godot_view.mm b/platform/ios/godot_view.mm
index ff8a4f8921..4b87863fc5 100644
--- a/platform/ios/godot_view.mm
+++ b/platform/ios/godot_view.mm
@@ -167,6 +167,23 @@ static const float earth_gravity = 9.80665;
}
}
+- (void)system_theme_changed {
+ DisplayServerIOS *ds = (DisplayServerIOS *)DisplayServer::get_singleton();
+ if (ds) {
+ ds->emit_system_theme_changed();
+ }
+}
+
+- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
+ if (@available(iOS 13.0, *)) {
+ [super traitCollectionDidChange:previousTraitCollection];
+
+ if ([UITraitCollection currentTraitCollection].userInterfaceStyle != previousTraitCollection.userInterfaceStyle) {
+ [self system_theme_changed];
+ }
+ }
+}
+
- (void)stopRendering {
if (!self.isActive) {
return;