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

get_visible_line_count() on RichTextLabel returns the good value only after it was drawn. #37912

Closed
Darenn opened this issue Apr 15, 2020 · 1 comment
Labels

Comments

@Darenn
Copy link
Contributor

Darenn commented Apr 15, 2020

Godot version:
3.2.1
OS/device including version:
Windows 10
Issue description:
get_visible_line_count() on RichTextLabel returns the good value only after it was drawn.
I've checked the code, it seem like the only place the visible_line_count is updated is in richtextlabel.cpp line 1024. As you can see, it's when the label receives the NOTIFICATION_DRAW. The issue #18722 seems about the same subject, but I don't think it's returning a wrong value, it's just not returning it when we think it should.

So let's say you want to put some text in the label, then resize the label relative to the number of lines, you have to wait the next draw with yield but then, for one frame your label won't be resized, it can be seen at runtime. Maybe it can be avoided by moving the label out of the canvas for a frame, resize it, wait a frame, then move it back where it should.

Another workaround that works well for me was to use propagate_notification(NOTIFICATION_DRAW) just before my resize code, this way the visible_line_count is updated. But it can trigger an error about not having the right to draw outside of _draw() (sorry I don't have the exact error code, happens only once)

If it is intended behaviour, I think the doc really should mention it. If not, maybe it is possible to calculate visible_line_count before drawing the label? I really don't know as I don't understand how's the code working.

I'm not used to submit issues but I hope it can be of help!

Steps to reproduce:
Open the project below and open the Control scene. I've made a working function and not working function that you comment/uncomment to test the workaround and the "intuitive" way.

Minimal reproduction project:
LabelBug.zip

@Calinou
Copy link
Member

Calinou commented Apr 15, 2020

Duplicate of #36381.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants