Is there an ellipsis / ellipsis procedure for shortening a button or label text in Firemonkey? For example, to rotate:
"C: \ a really \ really \ very long \ very long way \ even longer way" in "C: \ a really \ re ..." or "C: \ a really \ re ... path name"
There are subroutines in VCL, but it looks like Firemonkey's text size search will be more attractive.
I am using Firemonkey 2 on Delphi XE3
Thank you in advance
... Well, I created a clumsy procedure from Mike Sutton's advice. It only adds an ellipsis at the end of the first part of the line, but can be easily modified for middle or end ellipses. It also takes into account current objects. Font size and style.
Using:
ShortenText(Button1, 'Start of text blah blah blah blah the END is here'); procedure ShortenText(anFMXObject: TTextControl; newText: string); var aTextObj: TText; shortenTo: integer; modText: string; begin if Length(newText) > 2 then begin modText:= newText+'...'; aTextObj:=TText.Create(anFMXObject.Parent); aTextObj.Font.SetSettings(anFMXObject.Font.Family, anFMXObject.Font.Size, anFMXObject.Font.Style); aTextObj.WordWrap:= false; aTextObj.AutoSize:= true; aTextObj.Text:= newText; // this next bit generates the change necessary to redraw the new text (bug in XE3 as of Oct 2012) aTextObj.HorzTextAlign:= TTextAlign.taCenter; aTextObj.HorzTextAlign:= TTextAlign.taLeading; // now shorten the text: shortenTo:= round((Length(modText)/aTextObj.Width)*anFMXObject.Width)-1; modText:= LeftStr(modText, shortenTo-3)+'...'; anFMXObject.Text:= modText; FreeAndNil(aTextObj); end; end;
source share