You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Godot version:
3.2.1
OS/device including version:
Windows 10
Issue description:
get_visible_line_count()
onRichTextLabel
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 theNOTIFICATION_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 thevisible_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
The text was updated successfully, but these errors were encountered: