-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
RichTextLabel: Add count and scroll functions for wrapped lines and paragraphs. #45128
Conversation
98049fa
to
c296dd4
Compare
I can't check if it fixes my issue, because |
…t` and `scroll_to_x` functions for wrapped lines and paragraphs (newlines).
c296dd4
to
e4651a4
Compare
Thanks! |
int RichTextLabel::get_line_count() const { | ||
return current_frame->lines.size(); | ||
int line_count = 0; | ||
for (int i = 0; i < main->lines.size(); i++) { | ||
line_count += main->lines[i].text_buf->get_line_count(); | ||
} | ||
return line_count; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is wrong, or should at least be made optional.
The actual amount of lines in a RTL and the amount of lines rendered is two different things.
When you want to get the line count of the number of lines the actual RLT contains, for example to remove a line in remove_line()
, you want the value of current_frame->lines.size()
, not including wrapped lines. If you include wrapped lines, you may be reporting a larger number of lines than actually exists. In which case you will exit out of remove_line()
early, since p_line > current_frame->lines.size()
I dont' really know the usecase for the number of lines rendered, which is what this PR does. But I think get_line_count()
should at least have a parameter to determine which value to obtain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_paragraph_count
should return number of lines without counting wrapped lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see... sorry, didn't catch that.
Were uses of the "legacy" get_line_count()
changed to get_paragraph_count()
within the rest of the codebase?
I'm also not sure about the naming... but I guess it works and I don't have better suggestions at this stage.
Can this port to 3.x ? |
seconding this, this is still a huge issue in 3.x |
Adds separate
get_total_x_count
,get_visible_x_count
andscroll_to_x
functions for wrapped lines and paragraphs (newlines).Old behavior:
get_line_count
andscroll_to_line functions
were counting newlines/paragraphs,get_visible_line_count
was counting lines before #40217, and paragraphs after.New behavior:
x_paragraph_x
functions count paragraphs (newlines or[p]
tags), andx_line_x
functions count wrapped lines.Fixes: #40982