0

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?

Nas Banov
  • 28,347
  • 6
  • 48
  • 67
Otavio Macedo
  • 1,542
  • 1
  • 13
  • 34

1 Answers1

2

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
Roberto14
  • 689
  • 6
  • 20
  • Thanks a lot! Now the question is: in your example, you hardcoded the button width. Is there any way to programmatically tell the width of buttons in the springboard screen? – Otavio Macedo Jun 19 '15 at 14:14
  • There is no way to tell the width of the buttons programmatically as far as I am aware. – Pieter Siekerman Aug 24 '15 at 14:32
  • You can tell the width and position of any screen item via [ifSGNodeBoundingRect](https://developer.roku.com/docs/references/brightscript/interfaces/ifsgnodeboundingrect.md) – Dejay Clayton Jul 29 '20 at 01:21