From 9ee82ebe1ddd790d69c401f5fe4b26934ec6138a Mon Sep 17 00:00:00 2001 From: Michael Alexsander Date: Sun, 24 Sep 2023 02:18:17 -0300 Subject: [PATCH] Fix tooltips behaving incorrectly on `Tree` nodes --- scene/main/viewport.cpp | 26 +++++++++++++------------- scene/main/viewport.h | 1 + 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 9472c752738..368fd8fae02 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1414,6 +1414,8 @@ void Viewport::_gui_sort_roots() { void Viewport::_gui_cancel_tooltip() { gui.tooltip_control = nullptr; + gui.tooltip_text = ""; + if (gui.tooltip_timer.is_valid()) { gui.tooltip_timer->release_connections(); gui.tooltip_timer = Ref(); @@ -1470,18 +1472,20 @@ void Viewport::_gui_show_tooltip() { // Get the Control under cursor and the relevant tooltip text, if any. Control *tooltip_owner = nullptr; - String tooltip_text = _gui_get_tooltip( + gui.tooltip_text = _gui_get_tooltip( gui.tooltip_control, gui.tooltip_control->get_global_transform().xform_inv(gui.last_mouse_pos), &tooltip_owner); - tooltip_text = tooltip_text.strip_edges(); - if (tooltip_text.is_empty()) { + gui.tooltip_text = gui.tooltip_text.strip_edges(); + + if (gui.tooltip_text.is_empty()) { return; // Nothing to show. } // Remove previous popup if we change something. if (gui.tooltip_popup) { memdelete(gui.tooltip_popup); + gui.tooltip_popup = nullptr; } if (!tooltip_owner) { @@ -1497,14 +1501,14 @@ void Viewport::_gui_show_tooltip() { // Controls can implement `make_custom_tooltip` to provide their own tooltip. // This should be a Control node which will be added as child to a TooltipPanel. - Control *base_tooltip = tooltip_owner->make_custom_tooltip(tooltip_text); + Control *base_tooltip = tooltip_owner->make_custom_tooltip(gui.tooltip_text); // If no custom tooltip is given, use a default implementation. if (!base_tooltip) { gui.tooltip_label = memnew(Label); gui.tooltip_label->set_theme_type_variation(SNAME("TooltipLabel")); gui.tooltip_label->set_auto_translate(gui.tooltip_control->is_auto_translating()); - gui.tooltip_label->set_text(tooltip_text); + gui.tooltip_label->set_text(gui.tooltip_text); base_tooltip = gui.tooltip_label; panel->connect("mouse_entered", callable_mp(this, &Viewport::_gui_cancel_tooltip)); } @@ -1935,23 +1939,19 @@ void Viewport::_gui_input_event(Ref p_event) { mm->set_velocity(velocity); mm->set_relative(rel); + // Nothing pressed. if (mm->get_button_mask().is_empty()) { - // Nothing pressed. - bool is_tooltip_shown = false; if (gui.tooltip_popup) { if (gui.tooltip_control) { String tooltip = _gui_get_tooltip(over, gui.tooltip_control->get_global_transform().xform_inv(mpos)); tooltip = tooltip.strip_edges(); - if (tooltip.length() == 0) { + + if (tooltip.is_empty() || tooltip != gui.tooltip_text) { _gui_cancel_tooltip(); - } else if (gui.tooltip_label) { - if (tooltip == gui.tooltip_label->get_text()) { - is_tooltip_shown = true; - } } else { - is_tooltip_shown = true; // Nothing to compare against, likely using custom control, so if it changes there is nothing we can do. + is_tooltip_shown = true; } } else { _gui_cancel_tooltip(); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index a32077a489e..65777c973f5 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -368,6 +368,7 @@ private: Control *tooltip_control = nullptr; Window *tooltip_popup = nullptr; Label *tooltip_label = nullptr; + String tooltip_text; Point2 tooltip_pos; Point2 last_mouse_pos; Point2 drag_accum;