From 1e9d241809c16818ddf585c9ef2ac035957fa174 Mon Sep 17 00:00:00 2001 From: Markus Sauermann <6299227+Sauermann@users.noreply.github.com> Date: Tue, 1 Aug 2023 14:44:45 +0200 Subject: [PATCH] Actually store safe-rect in embedder `sw` is a copy and not a reference. Add unit-test for this case. --- scene/main/viewport.cpp | 3 +-- tests/scene/test_viewport.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 94e5c075522..c0e54e4e2a3 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -3637,8 +3637,7 @@ void Viewport::subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_r int index = _sub_window_find(p_window); ERR_FAIL_COND(index == -1); - SubWindow sw = gui.sub_windows[index]; - sw.parent_safe_rect = p_rect; + gui.sub_windows.write[index].parent_safe_rect = p_rect; } Rect2i Viewport::subwindow_get_popup_safe_rect(Window *p_window) const { diff --git a/tests/scene/test_viewport.h b/tests/scene/test_viewport.h index a6b3b2c40cb..f0fdf655c01 100644 --- a/tests/scene/test_viewport.h +++ b/tests/scene/test_viewport.h @@ -756,6 +756,21 @@ TEST_CASE("[SceneTree][Viewport] Control mouse cursor shape") { } } +TEST_CASE("[SceneTree][Viewport] Embedded Windows") { + Window *root = SceneTree::get_singleton()->get_root(); + Window *w = memnew(Window); + + SUBCASE("[Viewport] Safe-rect of embedded Window") { + root->add_child(w); + root->subwindow_set_popup_safe_rect(w, Rect2i(10, 10, 10, 10)); + CHECK_EQ(root->subwindow_get_popup_safe_rect(w), Rect2i(10, 10, 10, 10)); + root->remove_child(w); + CHECK_EQ(root->subwindow_get_popup_safe_rect(w), Rect2i()); + } + + memdelete(w); +} + } // namespace TestViewport #endif // TEST_VIEWPORT_H