Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Level 7

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.
0 Kudos
6 Replies
Highlighted
Level 7

Re: Determining text width on a Label (SDK2)

Any luck with this?
0 Kudos
Highlighted
Level 7

Re: Determining text width on a Label (SDK2)

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!
0 Kudos
Level 8

Re: Determining text width on a Label (SDK2)

This would definitely be useful.
0 Kudos
Highlighted
Level 8

Re: Determining text width on a Label (SDK2)

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.
0 Kudos
Highlighted
Level 7

Re: Determining text width on a Label (SDK2)

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"]
0 Kudos
Highlighted
Level 7

Re: Determining text width on a Label (SDK2)

Thanks for the workaround man, it is working well Smiley Happy
0 Kudos