From 6b9641d36408c1066fbad2ae828431f3a024b9dd Mon Sep 17 00:00:00 2001 From: HolonProduction Date: Tue, 11 Mar 2025 12:46:46 +0100 Subject: [PATCH] Fix focus cycle through window --- scene/gui/dialogs.cpp | 2 +- tests/scene/test_control.h | 49 +++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index d09ce9d7220..a79ba285e9a 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -467,7 +467,7 @@ AcceptDialog::AcceptDialog() { message_label->set_anchor(SIDE_BOTTOM, Control::ANCHOR_END); add_child(message_label, false, INTERNAL_MODE_FRONT); - add_child(buttons_hbox, false, INTERNAL_MODE_FRONT); + add_child(buttons_hbox, false, INTERNAL_MODE_BACK); buttons_hbox->add_spacer(); ok_button = memnew(Button); diff --git a/tests/scene/test_control.h b/tests/scene/test_control.h index df498b94194..f442126d30e 100644 --- a/tests/scene/test_control.h +++ b/tests/scene/test_control.h @@ -162,7 +162,54 @@ TEST_CASE("[SceneTree][Control] Find next/prev valid focus") { CHECK_UNARY(ctrl->has_focus()); } - SUBCASE("[SceneTree][Control] Has a sibling control but the parent node is not a control") { + SUBCASE("[SceneTree][Control] Has a sibling control and the parent is a window") { + Control *ctrl1 = memnew(Control); + Control *ctrl2 = memnew(Control); + Control *ctrl3 = memnew(Control); + Window *win = SceneTree::get_singleton()->get_root(); + + ctrl1->set_focus_mode(Control::FocusMode::FOCUS_ALL); + ctrl2->set_focus_mode(Control::FocusMode::FOCUS_ALL); + ctrl3->set_focus_mode(Control::FocusMode::FOCUS_ALL); + + ctrl2->add_child(ctrl3); + win->add_child(ctrl1); + win->add_child(ctrl2); + + SUBCASE("[SceneTree][Control] Focus Next") { + ctrl1->grab_focus(); + CHECK_UNARY(ctrl1->has_focus()); + + SEND_GUI_ACTION("ui_focus_next"); + CHECK_UNARY(ctrl2->has_focus()); + + SEND_GUI_ACTION("ui_focus_next"); + CHECK_UNARY(ctrl3->has_focus()); + + SEND_GUI_ACTION("ui_focus_next"); + CHECK_UNARY(ctrl1->has_focus()); + } + + SUBCASE("[SceneTree][Control] Focus Prev") { + ctrl1->grab_focus(); + CHECK_UNARY(ctrl1->has_focus()); + + SEND_GUI_ACTION("ui_focus_prev"); + CHECK_UNARY(ctrl3->has_focus()); + + SEND_GUI_ACTION("ui_focus_prev"); + CHECK_UNARY(ctrl2->has_focus()); + + SEND_GUI_ACTION("ui_focus_prev"); + CHECK_UNARY(ctrl1->has_focus()); + } + + memdelete(ctrl3); + memdelete(ctrl1); + memdelete(ctrl2); + } + + SUBCASE("[SceneTree][Control] Has a sibling control but the parent node is not a control or window") { Control *other_ctrl = memnew(Control); intermediate->add_child(other_ctrl);