However, if the text is too long, I need to truncate it and add a suffix of ... that will just fit in the box.
I've attached some code I've used to test this. I think its: Obvious, simple, rather crude and probably very slow.
Can anyone suggest a more elegant and probably faster method?
Code: Select all
EnableExplicit
CompilerIf #PB_Compiler_Unicode
#XmlEncoding = #PB_UTF8
CompilerElse
#XmlEncoding = #PB_Ascii
CompilerEndIf
#Dialog = 0
#Xml = 0
Global XML1$, XML2$, Event.i
Runtime Enumeration Windows
#WinMain
#win2
EndEnumeration
Runtime Enumeration Gadgets
#DrawingTextTest
EndEnumeration
Procedure DoTest()
Protected h.i, w.i = 120, T$ = "This is a very long title To test" ;// Possibly a poor choice!
Protected DotDotDotLen.i, ThreeDots$
If StartDrawing(CanvasOutput(#DrawingTextTest))
h = TextHeight("Ay")
DotDotDotLen = TextWidth("...")
Box(20,20,120,h,$dddddd)
While TextWidth(T$) > 120 - DotDotDotLen
T$ = Left(T$,Len(T$) - 1)
ThreeDots$ = "..."
Wend
DrawText(20,20,T$ + ThreeDots$,$000000,$ffffff)
StopDrawing()
Else
MessageRequester("ERROR!","Cannot start drawing!")
EndIf
EndProcedure
Runtime Procedure SetUP()
DoTest()
EndProcedure
XML1$ = "<dialogs>"+
" <window id='#WinMain' name='Template' text='Window 1' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered |"+
" #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
" <canvas id='#DrawingTextTest' width='400' height='200' />"+
" </window>"+
"</dialogs>"
If CatchXML(#Xml, @XML1$, StringByteLength(XML1$), 0, #XmlEncoding) And XMLStatus(#Xml) = #PB_XML_Success
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "Template")
SetUp()
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
Else
Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf