"ttown253" wrote:
What I'm trying to figure out is how to get it to stop displaying text if there are too many lines. It's not doing anything about the height of the TargetRect. It will just keep printing the text, albeit the correct width, on several lines well beneath the TargetRect.
Is there any way to solve this issue without complex coding, text width analysis, etc
If you do decide to use an roImageCanvas, compute the height for your text rectangle by taking the number of lines of text you want in each rectangle multiplied by GetOneLineHeight(). By drawing another text rectangle immediately adjacent to the one with overflowing text, as long as its background is completely filled, you will over-write any overflow text from the previous text rectangle, as demonstrated in the following code (which does require you to use a custom font):
function Main()
fontFile = "pkg:/fonts/Font.ttf" ' From: http://www.dafont.com/liberation-sans.font
fontName = "Liberation Sans"
fontSize = 24
fr = CreateObject ("roFontRegistry")
fr.Register (fontFile)
fontObject = fr.GetFont (fontName, fontSize, false, false)
fontString = fr.Get (fontName, fontSize, false, false)
lineH = fontObject.GetOneLineHeight ()
nLines = 3
rectH = nLines * lineH
canvas = CreateObject("roImageCanvas")
canvas.SetLayer(0, [
{
Color: "#FF0000",
TargetRect: {x: 200, y: 200, h: rectH, w: 400}
},
{
Text: "Hello this is a long sentence about something I will see on TV someday and this is a continuation of that sentence which will wrap beneath the target rectangle",
TextAttrs: {font: fontString, color: "#FFFFFF", valign: "Top", halign: "Left"},
TargetRect: {x: 200, y: 200, h: rectH, w: 400}
},
{
' The next grid element over-writes any overflow from the previous element
Color: "#00FF00",
TargetRect: {x: 200, y: 200 + rectH, h: rectH, w: 400}
},
{
Text: "This is the next sentence",
TextAttrs: {font: fontString, color: "#FFFFFF", valign: "Top", halign: "Left"},
TargetRect: {x: 200, y: 200 + rectH, h: rectH, w: 400}
}
])
port = CreateObject("roMessagePort")
canvas.SetMessagePort(port)
canvas.Show()
while true
event = Wait(0, port)
if (event.IsRemoteKeyPressed())
index = event.GetIndex()
if (index = 6) ' Press OK to exit
exit while
end if
end if
end while
end function