Checking for button title overflows in Brightscript

320 views Asked by At

In Roku's library, to add a button to a spring board screen, you use the method (see doc):

AddButton(buttonID as Integer, title as String) as Boolean

If title overflows the button width, it will automatically truncate the text and append "...". But is it possible to programmatically check whether there was an overflow or not?

1

There are 1 answers

3
Roberto14 On BEST ANSWER

There isn't a nicely way to check that, but as workaround you have two options: check the string length for a maximum safe length or use GetOneLineWidth() method.

For the second option, you must know button's width, font family and fontsize, eg:

button_width = 450    'px

reg = CreateObject("roFontRegistry")    
arialFont = reg.GetFont("Arial", reg.GetDefaultFontSize(), false, false)
title_width = arialFont.GetOneLineWidth(titleString, 1280)    'maxWidth set to screen width

if title_width > button_width then
    'do your logic here
end if