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

roScreen drawText Line Break

I have a function for use with roImageCanvas that takes a sentence pulled from an xml file, cuts the length of the sentence to a certain pixel width, and prints it on the screen. I have been using the function with setlayer to print the words across two horizontal lines, since the setLayer text metadata automatically moves the rest of the sentence to the next line when printed. I am now converting my program to use roScreen instead, and I was wondering if there was a way to make the drawText function automatically go to the next line when the sentence reached a certain width, or if there is a way to force a line break in a string so that the text is spread over two lines?
0 Kudos
4 REPLIES 4
kbenson
Visitor

Re: roScreen drawText Line Break

If you have to calculate the line length yourself, you may find hints and/or suitable pseudo-code here: viewtopic.php?f=34&t=35607&start=0&hilit=wrap
-- GandK Labs
Check out Reversi! in the channel store!
0 Kudos
TheEndless
Channel Surfer

Re: roScreen drawText Line Break

For roScreen, you'll need to do the wrapping yourself. You can get the current width using the GetOneLineWidth() method of the roFont object. If you split the text into individual words, you can concatenate until GetOneLineWidth() exceeds the desired line width, then move to the next line. Using this method also gives you enough information to do right, center, and left alignment, and if you wanted to get really fancy, possibly even justification.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
idunno
Visitor

Re: roScreen drawText Line Break

If you split the text into individual words, you can concatenate until GetOneLineWidth() exceeds the desired line width, then move to the next line.


How do you move to the next line? Is there a command?
0 Kudos
TheEndless
Channel Surfer

Re: roScreen drawText Line Break

"idunno" wrote:
If you split the text into individual words, you can concatenate until GetOneLineWidth() exceeds the desired line width, then move to the next line.


How do you move to the next line? Is there a command?

Use font.GetOneLineHeight() to determine how far to increase the Y value to move to the next line. You'd need to track the coordinates you're using with DrawText in your code.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
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.