Determining text width on a Label (SDK2)

Hello,

Is there any way to determine or calculate the text width of the rendered text on a Label using SDK2 / Scene Graph Components?

Thanks in advance for any advice.

Any luck with this?

Hello juantwc, I saw your post at the end of Beta Scene Graph components and it reminded me to check this thread as well.

No - I have not found a work-around to this yet. I will update this thread once a fix has been found. I encourage you to do the same if you find it first.

Cheers!

This would definitely be useful.

So, I think a rough answer that could be used as a work around, is that if you can update the label from the main thread, you could determine the size via roFont’s GetOneLineWidth, and take the result of that and use it to set the width of your label node.

Just updating this with our current workaround:

Set the label width to 0, or not at all
Set the font and size
Set the text, then:

bounding = label.boundingRect()
labelWidth = bounding[“width”]

You will still need to set the label width as follows (otherwise it stays at 0)
label.width = bounding[“width”]

Thanks for the workaround man, it is working well :slightly_smiling_face: