Skip to content

Commit 2859546

Browse files
committed
Merge pull request #96721 from aXu-AP/tooltip-distance
Fix tooltip appearing in old place, on movement
2 parents 23fc8e2 + be349fa commit 2859546

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

scene/main/viewport.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,21 +1931,19 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
19311931
}
19321932
}
19331933

1934-
// If the tooltip timer isn't running, start it.
1935-
// Otherwise, only reset the timer if the mouse has moved more than 5 pixels.
1936-
if (!is_tooltip_shown && over->can_process() &&
1937-
(gui.tooltip_timer.is_null() ||
1938-
Math::is_zero_approx(gui.tooltip_timer->get_time_left()) ||
1939-
mm->get_relative().length() > 5.0)) {
1940-
if (gui.tooltip_timer.is_valid()) {
1941-
gui.tooltip_timer->release_connections();
1942-
gui.tooltip_timer = Ref<SceneTreeTimer>();
1934+
// Reset the timer if the mouse has moved more than 5 pixels or has entered a new control.
1935+
if (!is_tooltip_shown && over->can_process()) {
1936+
Vector2 new_tooltip_pos = over->get_screen_transform().xform(pos);
1937+
if (over != gui.tooltip_control || gui.tooltip_pos.distance_squared_to(new_tooltip_pos) > 25) {
1938+
if (gui.tooltip_timer.is_valid()) {
1939+
gui.tooltip_timer->release_connections();
1940+
}
1941+
gui.tooltip_control = over;
1942+
gui.tooltip_pos = new_tooltip_pos;
1943+
gui.tooltip_timer = get_tree()->create_timer(gui.tooltip_delay);
1944+
gui.tooltip_timer->set_ignore_time_scale(true);
1945+
gui.tooltip_timer->connect("timeout", callable_mp(this, &Viewport::_gui_show_tooltip));
19431946
}
1944-
gui.tooltip_control = over;
1945-
gui.tooltip_pos = over->get_screen_transform().xform(pos);
1946-
gui.tooltip_timer = get_tree()->create_timer(gui.tooltip_delay);
1947-
gui.tooltip_timer->set_ignore_time_scale(true);
1948-
gui.tooltip_timer->connect("timeout", callable_mp(this, &Viewport::_gui_show_tooltip));
19491947
}
19501948
}
19511949

0 commit comments

Comments
 (0)