1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

add gui_drag_threshold for viewports

This commit is contained in:
hannes
2025-09-04 05:43:10 +02:00
parent ab6c6eece8
commit 89aa5137b8
6 changed files with 29 additions and 1 deletions

View File

@@ -1712,6 +1712,7 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("gui/timers/tooltip_delay_sec.editor_hint", 0.5);
#endif
GLOBAL_DEF("gui/common/drag_threshold", 10);
GLOBAL_DEF_BASIC("gui/common/snap_controls_to_pixels", true);
GLOBAL_DEF(PropertyInfo(Variant::INT, "gui/common/show_focus_state_on_pointer_event", PROPERTY_HINT_ENUM, "Never,Control Supports Keyboard Input,Always"), 1);
GLOBAL_DEF_BASIC("gui/fonts/dynamic_fonts/use_oversampling", true);

View File

@@ -1189,6 +1189,9 @@
<member name="gui/common/default_scroll_deadzone" type="int" setter="" getter="" default="0">
Default value for [member ScrollContainer.scroll_deadzone], which will be used for all [ScrollContainer]s unless overridden.
</member>
<member name="gui/common/drag_threshold" type="int" setter="" getter="" default="10">
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].
</member>
<member name="gui/common/show_focus_state_on_pointer_event" type="int" setter="" getter="" default="1">
Determines whether a [Control] should visually indicate focus when said focus is gained using a mouse or touch input.
- [b]Never[/b] ([code]0[/code]) show the focused state for mouse/touch input.

View File

@@ -353,6 +353,9 @@
<member name="gui_disable_input" type="bool" setter="set_disable_input" getter="is_input_disabled" default="false">
If [code]true[/code], the viewport will not receive input events.
</member>
<member name="gui_drag_threshold" type="int" setter="set_drag_threshold" getter="get_drag_threshold" default="10">
The minimum distance the mouse cursor must move while pressed before a drag operation begins.
</member>
<member name="gui_embed_subwindows" type="bool" setter="set_embedding_subwindows" getter="is_embedding_subwindows" default="false">
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.
</member>

View File

@@ -4414,6 +4414,9 @@ int Main::start() {
bool snap_controls = GLOBAL_GET("gui/common/snap_controls_to_pixels");
sml->get_root()->set_snap_controls_to_pixels(snap_controls);
int drag_threshold = GLOBAL_GET("gui/common/drag_threshold");
sml->get_root()->set_drag_threshold(drag_threshold);
bool font_oversampling = GLOBAL_GET("gui/fonts/dynamic_fonts/use_oversampling");
sml->get_root()->set_use_oversampling(font_oversampling);

View File

@@ -2016,7 +2016,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
if (!gui.drag_attempted && gui.mouse_focus && section_root && !section_root->gui.global_dragging && (mm->get_button_mask().has_flag(MouseButtonMask::LEFT))) {
gui.drag_accum += mm->get_relative();
float len = gui.drag_accum.length();
if (len > 10) {
if (len > gui.drag_threshold) {
{ // Attempt grab, try parent controls too.
CanvasItem *ci = gui.mouse_focus;
while (ci) {
@@ -4136,6 +4136,16 @@ TypedArray<Window> Viewport::get_embedded_subwindows() const {
return windows;
}
void Viewport::set_drag_threshold(int p_threshold) {
ERR_MAIN_THREAD_GUARD
gui.drag_threshold = p_threshold;
}
int Viewport::get_drag_threshold() const {
ERR_READ_THREAD_GUARD_V(10);
return gui.drag_threshold;
}
void Viewport::subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_rect) {
int index = _sub_window_find(p_window);
ERR_FAIL_COND(index == -1);
@@ -5033,6 +5043,9 @@ void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_embedding_subwindows"), &Viewport::is_embedding_subwindows);
ClassDB::bind_method(D_METHOD("get_embedded_subwindows"), &Viewport::get_embedded_subwindows);
ClassDB::bind_method(D_METHOD("set_drag_threshold", "threshold"), &Viewport::set_drag_threshold);
ClassDB::bind_method(D_METHOD("get_drag_threshold"), &Viewport::get_drag_threshold);
ClassDB::bind_method(D_METHOD("set_canvas_cull_mask", "mask"), &Viewport::set_canvas_cull_mask);
ClassDB::bind_method(D_METHOD("get_canvas_cull_mask"), &Viewport::get_canvas_cull_mask);
@@ -5158,6 +5171,7 @@ void Viewport::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_disable_input"), "set_disable_input", "is_input_disabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_snap_controls_to_pixels"), "set_snap_controls_to_pixels", "is_snap_controls_to_pixels_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_embed_subwindows"), "set_embedding_subwindows", "is_embedding_subwindows");
ADD_PROPERTY(PropertyInfo(Variant::INT, "gui_drag_threshold"), "set_drag_threshold", "get_drag_threshold");
ADD_GROUP("SDF", "sdf_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "sdf_oversize", PROPERTY_HINT_ENUM, "100%,120%,150%,200%"), "set_sdf_oversize", "get_sdf_oversize");
ADD_PROPERTY(PropertyInfo(Variant::INT, "sdf_scale", PROPERTY_HINT_ENUM, "100%,50%,25%"), "set_sdf_scale", "get_sdf_scale");

View File

@@ -401,6 +401,7 @@ private:
bool drag_successful = false;
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.
bool embed_subwindows_hint = false;
int drag_threshold = 10;
Window *subwindow_focused = nullptr;
Window *currently_dragged_subwindow = nullptr;
@@ -706,6 +707,9 @@ public:
void subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_rect);
Rect2i subwindow_get_popup_safe_rect(Window *p_window) const;
void set_drag_threshold(int p_threshold);
int get_drag_threshold() const;
Viewport *get_parent_viewport() const;
Window *get_base_window();