Skip to content

Commit e384085

Browse files
committed
Add setting for when to show the focus state for mouse input
1 parent 7521044 commit e384085

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

core/config/project_settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,7 @@ ProjectSettings::ProjectSettings() {
16751675
#endif
16761676

16771677
GLOBAL_DEF_BASIC("gui/common/snap_controls_to_pixels", true);
1678-
GLOBAL_DEF("gui/common/always_show_focus_state", false);
1678+
GLOBAL_DEF(PropertyInfo(Variant::INT, "gui/common/show_focus_state_on_pointer_event", PROPERTY_HINT_ENUM, "Never,Control Supports Keyboard Input,Always"), 1);
16791679
GLOBAL_DEF_BASIC("gui/fonts/dynamic_fonts/use_oversampling", true);
16801680

16811681
GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/vsync/frame_queue_size", PROPERTY_HINT_RANGE, "2,3,1"), 2);

doc/classes/Control.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@
621621
<param index="0" name="hide_focus" type="bool" default="false" />
622622
<description>
623623
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. Has no effect if [member ProjectSettings.gui/common/always_show_focus_state] is set to [code]true[/code].
624+
If [param hide_focus] is [code]true[/code], the control will not visually show its focused state. Has no effect for [LineEdit] and [TextEdit] when [member ProjectSettings.gui/common/show_focus_state_on_pointer_event] is set to [code]Control Supports Keyboard Input[/code], or for any control when it is set to [code]Always[/code].
625625
[b]Note:[/b] Using this method together with [method Callable.call_deferred] makes it more reliable, especially when called inside [method Node._ready].
626626
</description>
627627
</method>

doc/classes/ProjectSettings.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,12 +1177,15 @@
11771177
<member name="filesystem/import/fbx2gltf/enabled.web" type="bool" setter="" getter="" default="false">
11781178
Override for [member filesystem/import/fbx2gltf/enabled] on the Web where FBX2glTF can't easily be accessed from Godot.
11791179
</member>
1180-
<member name="gui/common/always_show_focus_state" type="bool" setter="" getter="" default="false">
1181-
If [code]true[/code], [Control]s will always show if they're focused, even if said focus was gained via mouse/touch input.
1182-
</member>
11831180
<member name="gui/common/default_scroll_deadzone" type="int" setter="" getter="" default="0">
11841181
Default value for [member ScrollContainer.scroll_deadzone], which will be used for all [ScrollContainer]s unless overridden.
11851182
</member>
1183+
<member name="gui/common/show_focus_state_on_pointer_event" type="int" setter="" getter="" default="1">
1184+
Determines whether a [Control] should visually indicate focus when said focus is gained using a mouse or touch input.
1185+
- [b]Never[/b] ([code]0[/code]) show the focused state for mouse/touch input.
1186+
- [b]Control Supports Keyboard Input[/b] ([code]1[/code]) shows the focused state even when gained via mouse/touch input (similar to how browsers handle focus).
1187+
- [b]Always[/b] ([code]2[/code]) show the focused state, even if said focus was gained via mouse/touch input.
1188+
</member>
11861189
<member name="gui/common/snap_controls_to_pixels" type="bool" setter="" getter="" default="true">
11871190
If [code]true[/code], snaps [Control] node vertices to the nearest pixel to ensure they remain crisp even when the camera moves or zooms.
11881191
</member>

scene/gui/line_edit.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "line_edit.h"
3232

33+
#include "core/config/project_settings.h"
3334
#include "core/input/input_map.h"
3435
#include "core/os/keyboard.h"
3536
#include "core/os/os.h"
@@ -1343,7 +1344,7 @@ void LineEdit::_notification(int p_what) {
13431344
style->draw(ci, Rect2(Point2(), size));
13441345
}
13451346

1346-
if (has_focus(true)) {
1347+
if (has_focus(Engine::get_singleton()->is_editor_hint() || GLOBAL_GET_CACHED(int, "gui/common/show_focus_state_on_pointer_event") != 1)) {
13471348
theme_cache.focus->draw(ci, Rect2(Point2(), size));
13481349
}
13491350

scene/gui/text_edit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ void TextEdit::_notification(int p_what) {
945945
theme_cache.style_readonly->draw(ci, Rect2(Point2(), size));
946946
draw_caret = is_drawing_caret_when_editable_disabled();
947947
}
948-
if (has_focus(true)) {
948+
if (has_focus(Engine::get_singleton()->is_editor_hint() || GLOBAL_GET_CACHED(int, "gui/common/show_focus_state_on_pointer_event") != 1)) {
949949
theme_cache.style_focus->draw(ci, Rect2(Point2(), size));
950950
}
951951

scene/main/viewport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ void Viewport::_update_viewport_path() {
532532
}
533533

534534
bool Viewport::_can_hide_focus_state() {
535-
return Engine::get_singleton()->is_editor_hint() || !GLOBAL_GET_CACHED(bool, "gui/common/always_show_focus_state");
535+
return Engine::get_singleton()->is_editor_hint() || GLOBAL_GET_CACHED(int, "gui/common/show_focus_state_on_pointer_event") < 2;
536536
}
537537

538538
void Viewport::_on_settings_changed() {

0 commit comments

Comments
 (0)