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

Editor: Fix AssetLib is not updating size and stuck #86051

Closed
wants to merge 1 commit into from
Closed

Editor: Fix AssetLib is not updating size and stuck #86051

wants to merge 1 commit into from

Conversation

GrammAcc
Copy link
Contributor

@GrammAcc GrammAcc commented Dec 11, 2023

This is an enhancement to the fix originally provided in #80555.

When I submitted the original PR I did not account for resizing the editor window at runtime, so the number of columns for asset lib search results was recalculating on resize, but the asset title truncation threshold was not being recalculated, so columns were not spacing correctly after resizing the editor.

I added a simple for loop to the NOTIFICATION_RESIZE event of the EditorAssetLibrary class that loops through the currently displayed assets and recalculates their title truncation length. I just used a for loop over the asset_items->get_child_count and fetched each EditorAssetLibraryItem with asset_items->get_child since I wanted to avoid explicit memory allocation inside the notification handler.

Please let me know if this is not a good solution or if the use of static_cast is discouraged.

I tested this solution locally, and it fixes the problems I mentioned in #84471 (comment).

I think this will fix the scaling problem as reported in #84471 (comment) since it forces recalculation of the asset titles, but I am unable to confirm for sure since I can't test this on Windows.

This PR doesn't resolve the TODO:

https://github.com/godotengine/godot/blob/15a03ed98e63590c85dac62405d785e1b7ca7fed/editor/plugins/asset_library_editor_plugin.cpp#L67C1-L67C53

I haven't figured out exactly how to get the font size with TextServer yet, so I will submit a separate PR for that small refactor eventually. I wanted to submit this fix now though since this fixes an actual flaw in the original.

@GrammAcc
Copy link
Contributor Author

Forgot to run clang-format. 🤦‍♂️ Just amended with formatting fixed.

@GrammAcc
Copy link
Contributor Author

Okay, this is strange. This was working before rebasing over latest master, but now it's not recalculating every time I resize the editor. I'm going to mark this as a draft and I will request review after I have taken a closer look at this.

@GrammAcc GrammAcc marked this pull request as draft December 12, 2023 00:08
@GrammAcc GrammAcc marked this pull request as ready for review December 12, 2023 01:33
@GrammAcc
Copy link
Contributor Author

GrammAcc commented Dec 12, 2023

Okay, this should be ready for review now. The problem was that the clamp_width method was originally written with the assumption that it would be called on object initialization, so it was overriding the tooltip with the truncated version of the title text and wasn't handling the case of resizing to a larger size and un-truncating. I think I just wasn't paying close enough attention when I tested this before rebasing.

I got this fixed and amended my commit.

I also updated the commit message with the details of the edits I made to the clamp_width method.

Please let me know if you have any questions about the implementation. Thanks!

@AThousandShips AThousandShips added this to the 4.3 milestone Dec 12, 2023
@Calinou Calinou added topic:assetlib cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release labels Dec 12, 2023
@ckdarby
Copy link

ckdarby commented Jan 2, 2024

@GrammAcc, It looks like it'll fix my issue on Linux using a tile manager. I'll keep you posted when it gets merged and 4.3 comes out. Thanks for putting in the work.

@GrammAcc GrammAcc marked this pull request as draft January 9, 2024 13:56
@GrammAcc
Copy link
Contributor Author

GrammAcc commented Jan 9, 2024

I realized this morning that there is a better way to ensure that we don't overwrite the tooltip text with the truncated text. I currently have an if check for it in the clamp_width method, but I think it would be best to just set it in the configure method where the title text is set and then not worry about it, so I will update this PR over my lunch break today with a better design.

Also, I am working through the Accelerated C++ book in order to improve my contribution efficiency and quality, so hopefully my future PRs will be easier to review. :)

This is an enhancement to the fix originally provided in #80555.

When I submitted the original PR I did not account for resizing the
editor window at runtime, so the number of columns for asset lib search
results was recalculating on resize, but the asset title truncation
threshold was not being recalculated, so columns were not spacing
correctly after resizing the editor.

I added a simple for loop to the NOTIFICATION_RESIZE event of the
EditorAssetLibrary class that loops through the currently displayed
assets and recalculates their title truncation length. I just used a for
loop over the `asset_items->get_child_count` and fetched each
EditorAssetLibraryItem with `asset_items->get_child` since I wanted to
avoid explicit memory allocation inside the notification handler.

I also modified the `EditorAssetLibraryItem::clamp_width` method that I
originally added in #80555 to fix a couple of bugs:
  - When the method was called during a resize, it would set the tooltip
    text to the current value of the title's truncated text, so we lost
    the full text tooltip on resize if the title's text was truncated
    previously.
  - If resizing to a smaller column width that caused truncation of the
    title text, then resizing to a larger width that did not need
    truncation, the title text would not reset to the full text, so we
    ended up with truncated titles when we had the space for the full
    text.

I changed this to set the tooltip text in the
`EditorAssetLibraryItem::configure` method, so it isn't updated when
resizing the editor. Since the tooltip text is now guaranteed to be the
full title text, I used it in the `clamp_width` method to determine the
size of the text for clamping the width.

I was unable to reproduce the specific scaling problems reported in
#84471 (comment),
and I think that specific problem may be Windows-specific. However, I am
unable to confirm this since I do not have a Windows machine to test on,
and I could not get Godot to run inside a virtual machine.

I think that this commit will likely fix the issue as reported in #84471
since it forces recalculation of the truncation threshold on
NOTIFICATION_RESIZE, but I can't confirm without being able to reproduce
that issue on my machine.

In any case, this commit fixes a UX problem with the previous fix
provided in #80555 by ensuring consistent UI scaling and layout when
resizing the editor at runtime, so I think it is worth adding to the
engine independent of any specific issue.
@GrammAcc GrammAcc marked this pull request as ready for review January 9, 2024 20:02
@GrammAcc
Copy link
Contributor Author

GrammAcc commented Jan 9, 2024

I updated the PR with a better implementation. Details are in the commit message. I removed the full_title_text private member of the EditorAssetLibraryItem that I had originally added and used the tooltip text as the full text instead. By moving the set_tooltip_text call into the configure method, I don't have to worry about the tooltip accidentally getting updated during the clamp_width call, so this works fine as an invariant. Let me know if there are any problems with this approach. Thanks!

@GrammAcc
Copy link
Contributor Author

I'm closing this since #88761 was merged and seems to solve the same problem.

@GrammAcc GrammAcc closed this Apr 13, 2024
@akien-mga akien-mga added archived and removed cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release labels Apr 13, 2024
@AThousandShips AThousandShips removed this from the 4.3 milestone Apr 13, 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.

5 participants