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: 
idunno
Visitor

How Do I Stop Text Wrapping

When I use targetRect to place text on a canvas, if the text is too long, it wraps to the next line. I have several targetRects, organized vertically with the text taken from an rss feed. This means that if the text taken from the feed is too long, the words go to the next line and get jumbled up with the text in the other targetRects, making it impossible to read, so I was wondering if there was any way to keep the text from wrapping to the next line, like somehow saying that the text can only use two horizontal lines?
0 Kudos
6 REPLIES 6
destruk
Streaming Star

Re: How Do I Stop Text Wrapping

You could check the string length -
if len(variable)>40 then
variable=variable.left(40)
end if

This will truncate the text of the value to 40 characters.
0 Kudos
idunno
Visitor

Re: How Do I Stop Text Wrapping

I appreciate the suggestion, but I've already tried that. The problem is, if two long words are placed on the same line the second word is kicked down to the next line. For example, only 20 characters can be on a line, and my layout only allow two lines, so you would think I would be able to allow 40 character, however, if the words in the targetRect are Illinois Christian Association Conference Meets Tuesday, the text would appear as

Illinois Christian '19 Numbers Demonstrate number of characters on each line including "spaces"
Association '12
Conferenc '9

and go over my two line limit. I was hoping there was a way to limit number of lines used.
0 Kudos
RokuMarkn
Visitor

Re: How Do I Stop Text Wrapping

The most accurate way to do this would be to call GetOneLineWidth() repeatedly on successively longer substrings of the string you want to print, until you reach the rectangle width, then print that final substring. Something like this (just off the top of my head, not tested):


function GetPrintable(font as Object, str as String, width as Integer) as String
for i = 1 to Len(str)
ss = str.Left(i)
if font.GetOneLineWidth(ss, 99999) > width then return str.Left(i-1)
end for
return str
end function
0 Kudos
idunno
Visitor

Re: How Do I Stop Text Wrapping

Please explain the font variable to me, for example where do I get it from?
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: How Do I Stop Text Wrapping

"idunno" wrote:
Please explain the font variable to me, for example where do I get it from?


The font variable there is an instance of the roFont component: http://sdkdocs.roku.com/display/RokuSDKv43/roFont
0 Kudos
idunno
Visitor

Re: How Do I Stop Text Wrapping

This works, except for some reason whenever there is an apostrophe it messes up the length counter and just prints the whole thing. Is this a known problem, or a mistake I have made?
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.