Skip to content

Commit 835f087

Browse files
committed
Hide Control focus when given via mouse input
1 parent 6c9aa4c commit 835f087

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+181
-84
lines changed

doc/classes/Control.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Godot propagates input events via viewports. Each [Viewport] is responsible for propagating [InputEvent]s to their child nodes. As the [member SceneTree.root] is a [Window], this already happens automatically for all UI elements in your game.
1212
Input events are propagated through the [SceneTree] from the root node to all child nodes by calling [method Node._input]. For UI elements specifically, it makes more sense to override the virtual method [method _gui_input], which filters out unrelated input events, such as by checking z-order, [member mouse_filter], focus, or if the event was inside of the control's bounding box.
1313
Call [method accept_event] so no other node receives the event. Once you accept an input, it becomes handled so [method Node._unhandled_input] will not process it.
14-
Only one [Control] node can be in focus. Only the node in focus will receive events. To get the focus, call [method grab_focus]. [Control] nodes lose focus when another node grabs it, or if you hide the node in focus.
14+
Only one [Control] node can be in focus. Only the node in focus will receive events. To get the focus, call [method grab_focus]. [Control] nodes lose focus when another node grabs it, or if you hide the node in focus. Focus will not be represented visually if gained via mouse/touch input, only appearing with keyboard/gamepad input (for accessibility), or via [method grab_focus].
1515
Sets [member mouse_filter] to [constant MOUSE_FILTER_IGNORE] to tell a [Control] node to ignore mouse or touch events. You'll need it if you place an icon on top of a button.
1616
[Theme] resources change the control's appearance. The [member theme] of a [Control] node affects all of its direct and indirect children (as long as a chain of controls is uninterrupted). To override some of the theme items, call one of the [code]add_theme_*_override[/code] methods, like [method add_theme_font_override]. You can also override theme items in the Inspector.
1717
[b]Note:[/b] Theme items are [i]not[/i] [Object] properties. This means you can't access their values using [method Object.get] and [method Object.set]. Instead, use the [code]get_theme_*[/code] and [code]add_theme_*_override[/code] methods provided by this class.
@@ -618,15 +618,19 @@
618618
</method>
619619
<method name="grab_focus">
620620
<return type="void" />
621+
<param index="0" name="hide_focus" type="bool" default="false" />
621622
<description>
622623
Steal the focus from another control and become the focused control (see [member focus_mode]).
624+
If [param hide_focus] is [code]true[/code], the control will not visually show its focused state.
623625
[b]Note:[/b] Using this method together with [method Callable.call_deferred] makes it more reliable, especially when called inside [method Node._ready].
624626
</description>
625627
</method>
626628
<method name="has_focus" qualifiers="const">
627629
<return type="bool" />
630+
<param index="0" name="ignore_hidden_focus" type="bool" default="false" />
628631
<description>
629632
Returns [code]true[/code] if this is the current focused control. See [member focus_mode].
633+
If [param ignore_hidden_focus] is [code]true[/code], controls that have its focus hidden will always return [code]false[/code]. Hidden focus happens automatically when controls gain focus via mouse input, or manually with [method grab_focus] with [code]hide_focus[/code] set to [code]true[/code].
630634
</description>
631635
</method>
632636
<method name="has_theme_color" qualifiers="const">

editor/gui/code_editor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,10 +599,10 @@ void FindReplaceBar::_show_search(bool p_with_replace, bool p_show_only) {
599599

600600
if (focus_replace) {
601601
search_text->deselect();
602-
callable_mp((Control *)replace_text, &Control::grab_focus).call_deferred();
602+
callable_mp((Control *)replace_text, &Control::grab_focus).call_deferred(false);
603603
} else {
604604
replace_text->deselect();
605-
callable_mp((Control *)search_text, &Control::grab_focus).call_deferred();
605+
callable_mp((Control *)search_text, &Control::grab_focus).call_deferred(false);
606606
}
607607

608608
if (on_one_line) {

editor/gui/create_dialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ void CreateDialog::_notification(int p_what) {
563563

564564
case NOTIFICATION_VISIBILITY_CHANGED: {
565565
if (is_visible()) {
566-
callable_mp((Control *)search_box, &Control::grab_focus).call_deferred(); // Still not visible.
566+
callable_mp((Control *)search_box, &Control::grab_focus).call_deferred(false); // Still not visible.
567567
search_box->select_all();
568568
} else {
569569
EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "create_new_node", Rect2(get_position(), get_size()));

editor/gui/editor_spin_slider.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void EditorSpinSlider::_draw_spin_slider() {
340340
}
341341
}
342342

343-
if (has_focus()) {
343+
if (has_focus(true)) {
344344
Ref<StyleBox> focus = get_theme_stylebox(SNAME("focus"), SNAME("LineEdit"));
345345
draw_style_box(focus, Rect2(Vector2(), size));
346346
}
@@ -683,7 +683,7 @@ void EditorSpinSlider::_focus_entered() {
683683
value_input->set_focus_next(find_next_valid_focus()->get_path());
684684
value_input->set_focus_previous(find_prev_valid_focus()->get_path());
685685
callable_mp((CanvasItem *)value_input_popup, &CanvasItem::show).call_deferred();
686-
callable_mp((Control *)value_input, &Control::grab_focus).call_deferred();
686+
callable_mp((Control *)value_input, &Control::grab_focus).call_deferred(false);
687687
callable_mp(value_input, &LineEdit ::select_all).call_deferred();
688688
emit_signal("value_focus_entered");
689689
}

editor/inspector/editor_properties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2897,7 +2897,7 @@ void EditorPropertyNodePath::_menu_option(int p_idx) {
28972897
const NodePath &np = _get_node_path();
28982898
edit->set_text(String(np));
28992899
edit->show();
2900-
callable_mp((Control *)edit, &Control::grab_focus).call_deferred();
2900+
callable_mp((Control *)edit, &Control::grab_focus).call_deferred(false);
29012901
} break;
29022902

29032903
case ACTION_SELECT: {

editor/project_manager/project_dialog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ void ProjectDialog::show_dialog(bool p_reset_name) {
813813
renderer_container->hide();
814814
default_files_container->hide();
815815

816-
callable_mp((Control *)project_name, &Control::grab_focus).call_deferred();
816+
callable_mp((Control *)project_name, &Control::grab_focus).call_deferred(false);
817817
callable_mp(project_name, &LineEdit::select_all).call_deferred();
818818
} else {
819819
if (p_reset_name) {
@@ -865,7 +865,7 @@ void ProjectDialog::show_dialog(bool p_reset_name) {
865865
renderer_container->show();
866866
default_files_container->show();
867867

868-
callable_mp((Control *)project_name, &Control::grab_focus).call_deferred();
868+
callable_mp((Control *)project_name, &Control::grab_focus).call_deferred(false);
869869
callable_mp(project_name, &LineEdit::select_all).call_deferred();
870870
} else if (mode == MODE_INSTALL) {
871871
set_title(TTR("Install Project:") + " " + zip_title);
@@ -878,7 +878,7 @@ void ProjectDialog::show_dialog(bool p_reset_name) {
878878
renderer_container->hide();
879879
default_files_container->hide();
880880

881-
callable_mp((Control *)project_path, &Control::grab_focus).call_deferred();
881+
callable_mp((Control *)project_path, &Control::grab_focus).call_deferred(false);
882882
} else if (mode == MODE_DUPLICATE) {
883883
set_title(TTRC("Duplicate Project"));
884884
set_ok_button_text(TTRC("Duplicate"));
@@ -891,7 +891,7 @@ void ProjectDialog::show_dialog(bool p_reset_name) {
891891
edit_check_box->hide();
892892
}
893893

894-
callable_mp((Control *)project_name, &Control::grab_focus).call_deferred();
894+
callable_mp((Control *)project_name, &Control::grab_focus).call_deferred(false);
895895
callable_mp(project_name, &LineEdit::select_all).call_deferred();
896896
}
897897

editor/run/embedded_process.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ void EmbeddedProcess::_check_focused_process_id() {
415415
if (modal_window->get_mode() == Window::MODE_MINIMIZED) {
416416
modal_window->set_mode(Window::MODE_WINDOWED);
417417
}
418-
callable_mp(modal_window, &Window::grab_focus).call_deferred();
418+
callable_mp(modal_window, &Window::grab_focus).call_deferred(false);
419419
}
420420
}
421421
}

editor/scene/2d/tiles/tile_set_editor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ void TileSourceInspectorPlugin::_show_id_edit_dialog(Object *p_for_source) {
997997
edited_source = p_for_source;
998998
id_input->set_value(p_for_source->get("id"));
999999
id_edit_dialog->popup_centered(Vector2i(400, 0) * EDSCALE);
1000-
callable_mp((Control *)id_input->get_line_edit(), &Control::grab_focus).call_deferred();
1000+
callable_mp((Control *)id_input->get_line_edit(), &Control::grab_focus).call_deferred(false);
10011001
}
10021002

10031003
void TileSourceInspectorPlugin::_confirm_change_id() {

editor/scene/canvas_item_editor_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2797,7 +2797,7 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
27972797

27982798
// Grab focus
27992799
if (!viewport->has_focus() && (!get_viewport()->gui_get_focus_owner() || !get_viewport()->gui_get_focus_owner()->is_text_field())) {
2800-
callable_mp((Control *)viewport, &Control::grab_focus).call_deferred();
2800+
callable_mp((Control *)viewport, &Control::grab_focus).call_deferred(false);
28012801
}
28022802
}
28032803

editor/scene/connections_dialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ void ConnectDialog::_update_warning_label() {
485485
}
486486

487487
void ConnectDialog::_post_popup() {
488-
callable_mp((Control *)dst_method, &Control::grab_focus).call_deferred();
488+
callable_mp((Control *)dst_method, &Control::grab_focus).call_deferred(false);
489489
callable_mp(dst_method, &LineEdit::select_all).call_deferred();
490490
}
491491

0 commit comments

Comments
 (0)