diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2024-01-19 20:46:26 +0200 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2024-02-13 18:38:53 +0200 |
commit | ee53ae28dff4ca227ba970c733bf89d53f432141 (patch) | |
tree | e06843f4904ae6aafeeb99b1beaade6a96dff74e /platform/ios | |
parent | e92d55bbf417aa9f4592a863cb5b2c7ba0740e21 (diff) | |
download | redot-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.h | 8 | ||||
-rw-r--r-- | platform/ios/display_server_ios.mm | 10 | ||||
-rw-r--r-- | platform/ios/godot_view.mm | 17 |
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; |