Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
valicode
Visitor

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 6
juantwc
Visitor

Re: Determining text width on a Label (SDK2)

Any luck with this?
0 Kudos
valicode
Visitor

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
brybott
Visitor

Re: Determining text width on a Label (SDK2)

This would definitely be useful.
0 Kudos
brybott
Visitor

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
valicode
Visitor

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"]
apl001
Visitor

Re: Determining text width on a Label (SDK2)

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