Forum Discussion

idunno's avatar
idunno
Visitor
13 years ago

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?
  • 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.
  • 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?
  • "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.