Skip to content

Commit 08db7dd

Browse files
committed
Merge pull request #110245 from Armynator/add-min-gui-drag-distance
Make minimum drag distance configurable for gui elements
2 parents 0fe71c1 + 89aa513 commit 08db7dd

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

core/config/project_settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,7 @@ ProjectSettings::ProjectSettings() {
17121712
GLOBAL_DEF("gui/timers/tooltip_delay_sec.editor_hint", 0.5);
17131713
#endif
17141714

1715+
GLOBAL_DEF("gui/common/drag_threshold", 10);
17151716
GLOBAL_DEF_BASIC("gui/common/snap_controls_to_pixels", true);
17161717
GLOBAL_DEF(PropertyInfo(Variant::INT, "gui/common/show_focus_state_on_pointer_event", PROPERTY_HINT_ENUM, "Never,Control Supports Keyboard Input,Always"), 1);
17171718
GLOBAL_DEF_BASIC("gui/fonts/dynamic_fonts/use_oversampling", true);

doc/classes/ProjectSettings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,9 @@
11891189
<member name="gui/common/default_scroll_deadzone" type="int" setter="" getter="" default="0">
11901190
Default value for [member ScrollContainer.scroll_deadzone], which will be used for all [ScrollContainer]s unless overridden.
11911191
</member>
1192+
<member name="gui/common/drag_threshold" type="int" setter="" getter="" default="10">
1193+
The minimum distance the mouse cursor must move while pressed before a drag operation begins in the default viewport. For custom viewports see [member Viewport.gui_drag_threshold].
1194+
</member>
11921195
<member name="gui/common/show_focus_state_on_pointer_event" type="int" setter="" getter="" default="1">
11931196
Determines whether a [Control] should visually indicate focus when said focus is gained using a mouse or touch input.
11941197
- [b]Never[/b] ([code]0[/code]) show the focused state for mouse/touch input.

doc/classes/Viewport.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@
353353
<member name="gui_disable_input" type="bool" setter="set_disable_input" getter="is_input_disabled" default="false">
354354
If [code]true[/code], the viewport will not receive input events.
355355
</member>
356+
<member name="gui_drag_threshold" type="int" setter="set_drag_threshold" getter="get_drag_threshold" default="10">
357+
The minimum distance the mouse cursor must move while pressed before a drag operation begins.
358+
</member>
356359
<member name="gui_embed_subwindows" type="bool" setter="set_embedding_subwindows" getter="is_embedding_subwindows" default="false">
357360
If [code]true[/code], sub-windows (popups and dialogs) will be embedded inside application window as control-like nodes. If [code]false[/code], they will appear as separate windows handled by the operating system.
358361
</member>

main/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4414,6 +4414,9 @@ int Main::start() {
44144414
bool snap_controls = GLOBAL_GET("gui/common/snap_controls_to_pixels");
44154415
sml->get_root()->set_snap_controls_to_pixels(snap_controls);
44164416

4417+
int drag_threshold = GLOBAL_GET("gui/common/drag_threshold");
4418+
sml->get_root()->set_drag_threshold(drag_threshold);
4419+
44174420
bool font_oversampling = GLOBAL_GET("gui/fonts/dynamic_fonts/use_oversampling");
44184421
sml->get_root()->set_use_oversampling(font_oversampling);
44194422

scene/main/viewport.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
20162016
if (!gui.drag_attempted && gui.mouse_focus && section_root && !section_root->gui.global_dragging && (mm->get_button_mask().has_flag(MouseButtonMask::LEFT))) {
20172017
gui.drag_accum += mm->get_relative();
20182018
float len = gui.drag_accum.length();
2019-
if (len > 10) {
2019+
if (len > gui.drag_threshold) {
20202020
{ // Attempt grab, try parent controls too.
20212021
CanvasItem *ci = gui.mouse_focus;
20222022
while (ci) {
@@ -4136,6 +4136,16 @@ TypedArray<Window> Viewport::get_embedded_subwindows() const {
41364136
return windows;
41374137
}
41384138

4139+
void Viewport::set_drag_threshold(int p_threshold) {
4140+
ERR_MAIN_THREAD_GUARD
4141+
gui.drag_threshold = p_threshold;
4142+
}
4143+
4144+
int Viewport::get_drag_threshold() const {
4145+
ERR_READ_THREAD_GUARD_V(10);
4146+
return gui.drag_threshold;
4147+
}
4148+
41394149
void Viewport::subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_rect) {
41404150
int index = _sub_window_find(p_window);
41414151
ERR_FAIL_COND(index == -1);
@@ -5033,6 +5043,9 @@ void Viewport::_bind_methods() {
50335043
ClassDB::bind_method(D_METHOD("is_embedding_subwindows"), &Viewport::is_embedding_subwindows);
50345044
ClassDB::bind_method(D_METHOD("get_embedded_subwindows"), &Viewport::get_embedded_subwindows);
50355045

5046+
ClassDB::bind_method(D_METHOD("set_drag_threshold", "threshold"), &Viewport::set_drag_threshold);
5047+
ClassDB::bind_method(D_METHOD("get_drag_threshold"), &Viewport::get_drag_threshold);
5048+
50365049
ClassDB::bind_method(D_METHOD("set_canvas_cull_mask", "mask"), &Viewport::set_canvas_cull_mask);
50375050
ClassDB::bind_method(D_METHOD("get_canvas_cull_mask"), &Viewport::get_canvas_cull_mask);
50385051

@@ -5158,6 +5171,7 @@ void Viewport::_bind_methods() {
51585171
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_disable_input"), "set_disable_input", "is_input_disabled");
51595172
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_snap_controls_to_pixels"), "set_snap_controls_to_pixels", "is_snap_controls_to_pixels_enabled");
51605173
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_embed_subwindows"), "set_embedding_subwindows", "is_embedding_subwindows");
5174+
ADD_PROPERTY(PropertyInfo(Variant::INT, "gui_drag_threshold"), "set_drag_threshold", "get_drag_threshold");
51615175
ADD_GROUP("SDF", "sdf_");
51625176
ADD_PROPERTY(PropertyInfo(Variant::INT, "sdf_oversize", PROPERTY_HINT_ENUM, "100%,120%,150%,200%"), "set_sdf_oversize", "get_sdf_oversize");
51635177
ADD_PROPERTY(PropertyInfo(Variant::INT, "sdf_scale", PROPERTY_HINT_ENUM, "100%,50%,25%"), "set_sdf_scale", "get_sdf_scale");

scene/main/viewport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ class Viewport : public Node {
401401
bool drag_successful = false;
402402
Control *target_control = nullptr; // Control that the mouse is over in the innermost nested Viewport. Only used in root-Viewport and SubViewports, that are not children of a SubViewportContainer.
403403
bool embed_subwindows_hint = false;
404+
int drag_threshold = 10;
404405

405406
Window *subwindow_focused = nullptr;
406407
Window *currently_dragged_subwindow = nullptr;
@@ -706,6 +707,9 @@ class Viewport : public Node {
706707
void subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_rect);
707708
Rect2i subwindow_get_popup_safe_rect(Window *p_window) const;
708709

710+
void set_drag_threshold(int p_threshold);
711+
int get_drag_threshold() const;
712+
709713
Viewport *get_parent_viewport() const;
710714
Window *get_base_window();
711715

0 commit comments

Comments
 (0)