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

Update the ui_text code to have less duplications and simplier renderer #8854

Closed
wants to merge 8 commits into from

Conversation

Districh-ru
Copy link
Collaborator

This PR changes the fheroes2::Text behavior to calculate text parameters only once and then use them for width, height, rows count and rendering.

This PR changes all texts rendering including buttons text.

@Districh-ru Districh-ru added the improvement New feature, request or improvement label Jun 21, 2024
@Districh-ru Districh-ru added this to the 1.1.1 milestone Jun 21, 2024
@Districh-ru Districh-ru self-assigned this Jun 21, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Clang-Tidy found issue(s) with the introduced code (1/2)

src/fheroes2/gui/ui_text.h Outdated Show resolved Hide resolved
src/fheroes2/gui/ui_text.h Outdated Show resolved Hide resolved
src/fheroes2/gui/ui_text.h Outdated Show resolved Hide resolved
src/fheroes2/gui/ui_text.h Outdated Show resolved Hide resolved
src/fheroes2/gui/ui_text.h Outdated Show resolved Hide resolved
src/fheroes2/gui/ui_text.h Outdated Show resolved Hide resolved
src/fheroes2/gui/ui_text.h Outdated Show resolved Hide resolved
src/fheroes2/gui/ui_text.cpp Show resolved Hide resolved
src/fheroes2/gui/ui_text.cpp Show resolved Hide resolved
src/fheroes2/gui/ui_text.h Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Clang-Tidy found issue(s) with the introduced code (2/2)

src/fheroes2/gui/ui_text.h Show resolved Hide resolved
src/fheroes2/gui/ui_text.h Show resolved Hide resolved
src/fheroes2/gui/ui_text.h Show resolved Hide resolved
src/fheroes2/gui/ui_text.h Outdated Show resolved Hide resolved
src/fheroes2/gui/ui_text.h Outdated Show resolved Hide resolved
src/fheroes2/gui/ui_text.h Outdated Show resolved Hide resolved
src/fheroes2/gui/ui_text.h Outdated Show resolved Hide resolved
@Districh-ru Districh-ru marked this pull request as ready for review June 22, 2024 12:04
@Districh-ru Districh-ru requested a review from ihhub June 22, 2024 12:04
@ihhub
Copy link
Owner

ihhub commented Jun 24, 2024

Hi @Districh-ru , would you be okay to merge this change after 1.1.1 release? I am worried that since we are getting close to the release we might face some issues with such a big change.

Copy link
Owner

@ihhub ihhub left a comment

Choose a reason for hiding this comment

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

Hi @Districh-ru , I would like to understand the scope of these changes and the intention. Is it correct to say that this pull request does 2 things:

  • speed up things by caching some data
  • simplifies rendering

I have a question regarding the first part. Could you please explain little bit more for a better understanding of these changes?

Comment on lines +140 to +145
int32_t rows( const int32_t maxWidth ) const
{
const_cast<TextBase *>( this )->setMaxWidth( maxWidth );

return static_cast<int32_t>( _textLineInfos.size() );
}
Copy link
Owner

Choose a reason for hiding this comment

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

Could you please explain the benefit of doing this except have little extra performance boost? I see 2 issues with this approach:

  • using const_cast which is very dangerous and could lead to a lot of problem with code execution and also debugging.
  • we are doing something which shouldn't be done inside this function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ho, @ihhub.
Thanks for highlighting these issues!
Yes we have the performance boost: we do not call getMultiRowInfo() many times for each width(), height(), row() and draw() methods.
And we don not have to maintain the three copies of the almost the same code, but not the same in all places. - This was the main issue I was trying to solve because it was not always easy to understand how to act in the each "almost the same" code part and to remember to do all the changes in all three duplications. :)
Wу already had some barely noticeable issues: width calculation for the width() function and for rendering was different and the results could slightly differ.
Now all text "info" is calculated once and all functions will now use the same data.
We also could not use the results of the TextLineInfo outside this code for the cursor placing and probably some other functions.

I used const_cast for the compatibility with the other code and was planning to update this code after we have have checked this drastic changes. I'll do this changes now to get rid of the const_cast. Also I'll add the text alignment setting: it would simplify the rendering parts.

@ihhub
Copy link
Owner

ihhub commented Jun 24, 2024

Additionally, I noticed that the text is rendered differently with these changes. Is it intentional?

@Districh-ru
Copy link
Collaborator Author

Additionally, I noticed that the text is rendered differently with these changes. Is it intentional?

If you are talking about the MultiFontText: previously the next line offset was considered as the biggest line height of all texts. IMHO it was done to easily calculate text height ( lines_count * line_height ).
Now the next line offset is the height of the current font in which the \n is used: like it is used to work in most modern text editors. It can be changed to the previous implementation if it is needed. It can be discussed.

If this differences are in the fheroes2::Text then please let me now where it is - I'll fix it.

@Districh-ru Districh-ru marked this pull request as draft June 24, 2024 15:49
@Districh-ru Districh-ru modified the milestones: 1.1.1, 1.1.2 Jun 24, 2024
@ihhub ihhub modified the milestones: 1.1.2, 1.1.3 Sep 15, 2024
@Districh-ru
Copy link
Collaborator Author

Closing this PR in favor of #9116

@Districh-ru Districh-ru deleted the ui_text-rework branch October 2, 2024 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement New feature, request or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants