jlfreund
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2013
01:30 AM
Word wrapped DrawText
Hi,
I am using DrawText on an roScreen, and was wondering if there is any utility function to handle word wrapping? Currently, I have to measure and layout each line. I see nice text layout and justification in other screens (like roParagraphScreen) so there must be some internal utility code for this somewhere, but I need the performance and flexibility of drawing on roScreen.
I am using DrawText on an roScreen, and was wondering if there is any utility function to handle word wrapping? Currently, I have to measure and layout each line. I see nice text layout and justification in other screens (like roParagraphScreen) so there must be some internal utility code for this somewhere, but I need the performance and flexibility of drawing on roScreen.
4 REPLIES 4

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2013
09:15 AM
Re: Word wrapped DrawText
There isn't any builtin function that does this, but if it helps, here's one that I wrote.
--Mark
--Mark
function SplitBlockText(text as String, width as Integer, font as Object) as Object
lines = []
line = 0
while true
while text.Mid(line,1) = " "
line = line + 1
end while
end_line = line
while true
if end_line >= text.Len() then
if end_line > line then lines.Push(text.Mid(line, end_line-line))
return lines
end if
e = EndWord(text, end_line)
if font.GetOneLineWidth(text.Mid(line, e-line), width) >= width then
lines.Push(text.Mid(line, end_line-line))
line = end_line
exit while
end if
end_line = e
end while
end while
end function
function EndWord(text as String, index as Integer) as Integer
for p = index to text.Len()
if text.Mid(p,1) <> " " then exit for
end for
for p = p to text.Len()
if text.Mid(p,1) = " " then exit for
end for
return p
end function

Komag
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2014
04:41 AM
Re: Word wrapped DrawText
I could really use this ability, but I'm not quite sure how to use the functions. I know the basic idea of calling a function, passing parameters, but could you (or someone) show a full example code of these word wrapping functions in use?

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2014
10:38 AM
Re: Word wrapped DrawText
Something like this (untested):
' screen is an roScreen
' font is an roFont
' text is the string you want to draw
' text_color is the color of the text
' xpos,ypos is the position at which you want to draw
' width is the width you want to draw
lines = SplitBlockText(text, width, font)
font_height = font.GetOneLineHeight()
foreach line in lines
screen.DrawText(line, xpos, ypos, font_color, font)
ypos = ypos + font_height
end for

Komag
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2014
02:38 PM
Re: Word wrapped DrawText
Thank you, I'll work on that 🙂