From f270163ab0296011bdff057924f7c14e6683c311 Mon Sep 17 00:00:00 2001 From: Michael Alexsander Date: Wed, 2 Aug 2023 13:53:37 -0300 Subject: [PATCH] Expose `Window`'s `_get_contents_minimum_size()` to scripting --- doc/classes/Window.xml | 7 +++++++ scene/main/window.cpp | 6 +++++- scene/main/window.h | 5 ++++- scene/scene_string_names.cpp | 1 + scene/scene_string_names.h | 1 + 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml index 5790fc347a4..82498b9ba47 100644 --- a/doc/classes/Window.xml +++ b/doc/classes/Window.xml @@ -10,6 +10,12 @@ + + + + Virtual method to be implemented by the user. Overrides the value returned by [method get_contents_minimum_size]. + + @@ -92,6 +98,7 @@ Returns the combined minimum size from the child [Control] nodes of the window. Use [method child_controls_changed] to update it when children nodes have changed. + The value returned by this method can be overridden with [method _get_contents_minimum_size]. diff --git a/scene/main/window.cpp b/scene/main/window.cpp index bd51f8eeaf0..06ac7495b9c 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -1748,7 +1748,9 @@ Rect2i Window::fit_rect_in_parent(Rect2i p_rect, const Rect2i &p_parent_rect) co Size2 Window::get_contents_minimum_size() const { ERR_READ_THREAD_GUARD_V(Size2()); - return _get_contents_minimum_size(); + Vector2 ms = _get_contents_minimum_size(); + GDVIRTUAL_CALL(_get_contents_minimum_size, ms); + return ms; } Size2 Window::get_clamped_minimum_size() const { @@ -2760,6 +2762,8 @@ void Window::_bind_methods() { BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_OTHER_SCREEN); BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_SCREEN_WITH_MOUSE_FOCUS); BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_SCREEN_WITH_KEYBOARD_FOCUS); + + GDVIRTUAL_BIND(_get_contents_minimum_size); } Window::Window() { diff --git a/scene/main/window.h b/scene/main/window.h index 24142b8a911..18ddd896625 100644 --- a/scene/main/window.h +++ b/scene/main/window.h @@ -205,7 +205,6 @@ protected: virtual void _update_theme_item_cache(); virtual void _post_popup() {} - virtual Size2 _get_contents_minimum_size() const; static void _bind_methods(); void _notification(int p_what); @@ -217,6 +216,8 @@ protected: virtual void add_child_notify(Node *p_child) override; virtual void remove_child_notify(Node *p_child) override; + GDVIRTUAL0RC(Vector2, _get_contents_minimum_size) + public: enum { NOTIFICATION_VISIBILITY_CHANGED = 30, @@ -409,6 +410,8 @@ public: Rect2i get_parent_rect() const; virtual DisplayServer::WindowID get_window_id() const override; + virtual Size2 _get_contents_minimum_size() const; + Window(); ~Window(); }; diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp index 87835a9522f..f0971f1a340 100644 --- a/scene/scene_string_names.cpp +++ b/scene/scene_string_names.cpp @@ -199,6 +199,7 @@ SceneStringNames::SceneStringNames() { _window_input = StaticCString::create("_window_input"); window_input = StaticCString::create("window_input"); _window_unhandled_input = StaticCString::create("_window_unhandled_input"); + _get_contents_minimum_size = StaticCString::create("_get_contents_minimum_size"); theme_changed = StaticCString::create("theme_changed"); parameters_base_path = "parameters/"; diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h index ad1135e24c3..f31cf7b8816 100644 --- a/scene/scene_string_names.h +++ b/scene/scene_string_names.h @@ -210,6 +210,7 @@ public: StringName _window_input; StringName _window_unhandled_input; StringName window_input; + StringName _get_contents_minimum_size; StringName theme_changed; StringName shader_overrides_group;