Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tooltips behaving incorrectly on Tree nodes #82226

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SceneTreeTimer>();
Expand Down Expand Up @@ -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.
}

YeldhamDev marked this conversation as resolved.
Show resolved Hide resolved
// Remove previous popup if we change something.
if (gui.tooltip_popup) {
memdelete(gui.tooltip_popup);
gui.tooltip_popup = nullptr;
}

if (!tooltip_owner) {
Expand All @@ -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));
}
Expand Down Expand Up @@ -1935,23 +1939,19 @@ void Viewport::_gui_input_event(Ref<InputEvent> 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();
Expand Down
1 change: 1 addition & 0 deletions scene/main/viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ class Viewport : public Node {
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;
Expand Down