Skip to content

Commit 6b9641d

Browse files
Fix focus cycle through window
1 parent e5ccaa7 commit 6b9641d

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
@@ -162,7 +162,54 @@ TEST_CASE("[SceneTree][Control] Find next/prev valid focus") {
162162
CHECK_UNARY(ctrl->has_focus());
163163
}
164164

165-
SUBCASE("[SceneTree][Control] Has a sibling control but the parent node is not a control") {
165+
SUBCASE("[SceneTree][Control] Has a sibling control and the parent is a window") {
166+
Control *ctrl1 = memnew(Control);
167+
Control *ctrl2 = memnew(Control);
168+
Control *ctrl3 = memnew(Control);
169+
Window *win = SceneTree::get_singleton()->get_root();
170+
171+
ctrl1->set_focus_mode(Control::FocusMode::FOCUS_ALL);
172+
ctrl2->set_focus_mode(Control::FocusMode::FOCUS_ALL);
173+
ctrl3->set_focus_mode(Control::FocusMode::FOCUS_ALL);
174+
175+
ctrl2->add_child(ctrl3);
176+
win->add_child(ctrl1);
177+
win->add_child(ctrl2);
178+
179+
SUBCASE("[SceneTree][Control] Focus Next") {
180+
ctrl1->grab_focus();
181+
CHECK_UNARY(ctrl1->has_focus());
182+
183+
SEND_GUI_ACTION("ui_focus_next");
184+
CHECK_UNARY(ctrl2->has_focus());
185+
186+
SEND_GUI_ACTION("ui_focus_next");
187+
CHECK_UNARY(ctrl3->has_focus());
188+
189+
SEND_GUI_ACTION("ui_focus_next");
190+
CHECK_UNARY(ctrl1->has_focus());
191+
}
192+
193+
SUBCASE("[SceneTree][Control] Focus Prev") {
194+
ctrl1->grab_focus();
195+
CHECK_UNARY(ctrl1->has_focus());
196+
197+
SEND_GUI_ACTION("ui_focus_prev");
198+
CHECK_UNARY(ctrl3->has_focus());
199+
200+
SEND_GUI_ACTION("ui_focus_prev");
201+
CHECK_UNARY(ctrl2->has_focus());
202+
203+
SEND_GUI_ACTION("ui_focus_prev");
204+
CHECK_UNARY(ctrl1->has_focus());
205+
}
206+
207+
memdelete(ctrl3);
208+
memdelete(ctrl1);
209+
memdelete(ctrl2);
210+
}
211+
212+
SUBCASE("[SceneTree][Control] Has a sibling control but the parent node is not a control or window") {
166213
Control *other_ctrl = memnew(Control);
167214
intermediate->add_child(other_ctrl);
168215

0 commit comments

Comments
 (0)