Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Window's _get_contents_minimum_size() to scripting #80178

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/classes/Window.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<tutorials>
</tutorials>
<methods>
<method name="_get_contents_minimum_size" qualifiers="virtual const">
<return type="Vector2" />
<description>
Virtual method to be implemented by the user. Overrides the value returned by [method get_contents_minimum_size].
</description>
</method>
<method name="add_theme_color_override">
<return type="void" />
<param index="0" name="name" type="StringName" />
Expand Down Expand Up @@ -92,6 +98,7 @@
<return type="Vector2" />
<description>
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].
</description>
</method>
<method name="get_flag" qualifiers="const">
Expand Down
6 changes: 5 additions & 1 deletion scene/main/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines +1751 to +1752
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it going to be wasteful to always run the default _get_contents_minimum_size() before the virtual call? How heavy is that call?

Not tested, but this might be better for performance:

Suggested change
Vector2 ms = _get_contents_minimum_size();
GDVIRTUAL_CALL(_get_contents_minimum_size, ms);
Vector2 ms;
if (GDVIRTUAL_CALL(_get_contents_minimum_size, ms) {
return ms;
}
return _get_contents_minimum_size();

return ms;
}

Size2 Window::get_clamped_minimum_size() const {
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 4 additions & 1 deletion scene/main/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ class Window : public Viewport {
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);

Expand All @@ -217,6 +216,8 @@ class Window : public Viewport {
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,
Expand Down Expand Up @@ -409,6 +410,8 @@ class Window : public Viewport {
Rect2i get_parent_rect() const;
virtual DisplayServer::WindowID get_window_id() const override;

virtual Size2 _get_contents_minimum_size() const;

Window();
~Window();
};
Expand Down
1 change: 1 addition & 0 deletions scene/scene_string_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down
1 change: 1 addition & 0 deletions scene/scene_string_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class SceneStringNames {
StringName _window_input;
StringName _window_unhandled_input;
StringName window_input;
StringName _get_contents_minimum_size;

StringName theme_changed;
StringName shader_overrides_group;
Expand Down