Skip to content

Commit 3c06526

Browse files
committed
Merge pull request #103967 from HolonProduction/window-focus
GUI: Fix focus cycle through window
2 parents 11cb814 + 6b9641d commit 3c06526

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

scene/gui/dialogs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ AcceptDialog::AcceptDialog() {
467467
message_label->set_anchor(SIDE_BOTTOM, Control::ANCHOR_END);
468468
add_child(message_label, false, INTERNAL_MODE_FRONT);
469469

470-
add_child(buttons_hbox, false, INTERNAL_MODE_FRONT);
470+
add_child(buttons_hbox, false, INTERNAL_MODE_BACK);
471471

472472
buttons_hbox->add_spacer();
473473
ok_button = memnew(Button);

tests/scene/test_control.h

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,54 @@ TEST_CASE("[SceneTree][Control] Find next/prev valid focus") {
218218
CHECK_UNARY(ctrl->has_focus());
219219
}
220220

221-
SUBCASE("[SceneTree][Control] Has a sibling control but the parent node is not a control") {
221+
SUBCASE("[SceneTree][Control] Has a sibling control and the parent is a window") {
222+
Control *ctrl1 = memnew(Control);
223+
Control *ctrl2 = memnew(Control);
224+
Control *ctrl3 = memnew(Control);
225+
Window *win = SceneTree::get_singleton()->get_root();
226+
227+
ctrl1->set_focus_mode(Control::FocusMode::FOCUS_ALL);
228+
ctrl2->set_focus_mode(Control::FocusMode::FOCUS_ALL);
229+
ctrl3->set_focus_mode(Control::FocusMode::FOCUS_ALL);
230+
231+
ctrl2->add_child(ctrl3);
232+
win->add_child(ctrl1);
233+
win->add_child(ctrl2);
234+
235+
SUBCASE("[SceneTree][Control] Focus Next") {
236+
ctrl1->grab_focus();
237+
CHECK_UNARY(ctrl1->has_focus());
238+
239+
SEND_GUI_ACTION("ui_focus_next");
240+
CHECK_UNARY(ctrl2->has_focus());
241+
242+
SEND_GUI_ACTION("ui_focus_next");
243+
CHECK_UNARY(ctrl3->has_focus());
244+
245+
SEND_GUI_ACTION("ui_focus_next");
246+
CHECK_UNARY(ctrl1->has_focus());
247+
}
248+
249+
SUBCASE("[SceneTree][Control] Focus Prev") {
250+
ctrl1->grab_focus();
251+
CHECK_UNARY(ctrl1->has_focus());
252+
253+
SEND_GUI_ACTION("ui_focus_prev");
254+
CHECK_UNARY(ctrl3->has_focus());
255+
256+
SEND_GUI_ACTION("ui_focus_prev");
257+
CHECK_UNARY(ctrl2->has_focus());
258+
259+
SEND_GUI_ACTION("ui_focus_prev");
260+
CHECK_UNARY(ctrl1->has_focus());
261+
}
262+
263+
memdelete(ctrl3);
264+
memdelete(ctrl1);
265+
memdelete(ctrl2);
266+
}
267+
268+
SUBCASE("[SceneTree][Control] Has a sibling control but the parent node is not a control or window") {
222269
Control *other_ctrl = memnew(Control);
223270
intermediate->add_child(other_ctrl);
224271

0 commit comments

Comments
 (0)