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

Correctly display tooltips for buttons in Tree when they overlap cell content (reverted) #79792

Merged
merged 1 commit into from
Sep 4, 2023

Conversation

Miguel0312
Copy link
Contributor

Closes #79629

I copied the 3.x behavior for the SceneTree: once the width becomes too small, the overflowing text of the node's name is hidden.

TooltipBug

The way I found to do this is by creating a second column in the TreeItem and adding the buttons to this column to make sure that there is no overlap. I also set the clip property of the first column to false in order to hide the overflow

@YuriSizov
Copy link
Contributor

YuriSizov commented Jul 24, 2023

That doesn't really solve the problem and also introduces an ugly visual bug. If buttons that overlap text don't show their tooltips and instead the text content's tooltip is shown, then we should make sure that the elements which are visually on top contribute to the tooltip ahead of the elements which are below.

See Tree::get_tooltip and check if it tests for buttons too late, instead.

@Miguel0312 Miguel0312 requested a review from a team as a code owner July 27, 2023 18:53
@Miguel0312
Copy link
Contributor Author

I found the bug. The get_tooltip function didn't take into account the fact that when we have an h_bar the button is not at the end of the TreeItem. I just had to take the offset between the size of the item and the size of the element being displayed. Now we have the following:
TooltipBug2

@YuriSizov YuriSizov changed the title SceneTree no longer display wrong tooltips Correctly display tooltips for buttons in Tree when they overlap cell content Jul 27, 2023
scene/gui/tree.cpp Outdated Show resolved Hide resolved
@YuriSizov YuriSizov requested review from YuriSizov and a team July 31, 2023 14:01
@YuriSizov
Copy link
Contributor

YuriSizov commented Aug 3, 2023

Okay, so after looking through the logic and the suggested change I think that the solution should be to add position to the Button struct and cache it during the drawing step. Then use it here to determine if we are over the button or not. The logic for determining the exact placement of each button is rather complex and it's counter-productive to try and replicate it or approximate its values by some other means.

The change needs to happen in Tree::draw_item around the code that draws the button texture, as that's where we have the exact position and size. We can even cache entire Rect2, as the size can also be limited by other factors and not come from the texture itself. Then the check in the get_tooltip method can just try to see if this rect includes our position.

Edit: It may also help to simplify the code that checks for buttons being pressed.

Copy link
Contributor

@YuriSizov YuriSizov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

@Miguel0312
Copy link
Contributor Author

I modified the implementation to use the cache as explained on the comment above. The result is the same as before (it also works for vertical-scrolling):
TooltipBug3

@YuriSizov YuriSizov self-requested a review August 24, 2023 11:35
Copy link
Contributor

@YuriSizov YuriSizov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost ready, but you've removed a bit too much. Make sure to test with multicolumn Trees.

I would also recommend rebasing against the current master, as your base commit is over a month old.

Edit: Oh, and please amend the commit message. The title of the PR is a good option.

scene/gui/tree.cpp Outdated Show resolved Hide resolved
scene/gui/tree.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@YuriSizov YuriSizov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

There are still some inconsistencies regarding buttons' position when we detect clicks, but it's a pre-existing issue that's unrelated to this. I'll take a look as a follow-up to this PR.

@akien-mga akien-mga merged commit 92da5a7 into godotengine:master Sep 4, 2023
@akien-mga
Copy link
Member

Thanks!

@akien-mga akien-mga changed the title Correctly display tooltips for buttons in Tree when they overlap cell content Correctly display tooltips for buttons in Tree when they overlap cell content (reverted) Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Editor : Scene Tree icons' tooltips dont match icon when narrow
4 participants