Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 9 of 9 total
Thread Ellipsis ...
Tue, May 3 2016 12:59 AMPermanent Link

Trinione

Hi Tim:
Can a TextEllipsis property (True/False maybe) be added to the Label, Edit, MultiLineEdit, Button and any other relevant component?

It would do wonders for the GUI.

If anyone has a way to do this, taking font size into consideration, please share.

Thanks.
Tue, May 3 2016 1:20 AMPermanent Link

Richard Harding

Wise Nutrition Coaching

Can you copy and paste the ellipsis character from Windows Character Map or use Alt 0133 to insert the ellipsis?

Richard
Tue, May 3 2016 4:19 AMPermanent Link

Matthew Jones

Trinione wrote:

> If anyone has a way to do this, taking font size into consideration,
> please share.

It's that taking font size into consideration that is the bite. Also
whether you want to be clever on that, which you probably do to prevent
rude words.

Basically, there is a big problem with this as it eats time, and that's
generally not good. You also have to decide which way to go, from small
to large, large to small, or binary chop. The core though is easy in
EWB using the TInterfaceManager.ContentWidth (available through the
global). And example is:


procedure SizeCheck(chkBox : TCheckBox);
begin
  chkBox.Width := 32 + InterfaceManager.ContentWidth(chkBox.Font,
chkBox.Caption, caLeft, False, 0);
end;


My much more basic version which just cuts to a given string length (or
the nearest space) and not according to actual display size, is:

function TruncateText(szText : String; nTargetLen : Integer) : String;
var
   nLastSpacePos : integer;
   nPos : Integer;
begin                       
   nTargetLen := 20;
   if Length(szText) < nTargetLen then
   begin     
       Result := szText;
   end
   else
   begin
       nLastSpacePos := 0;
       nPos := nTargetLen;
       while nPos > 0 do
       begin
           if szText[nPos] = ' ' then
           begin
               nLastSpacePos := nPos;
               break;
           end;
           dec(nPos);
       end;          
       if nLastSpacePos > 0 then
       begin
           Result := Copy(szText, 1, nLastSpacePos) + '...';
       end
       else
       begin
           Result := Copy(szText, 1, nTargetLen) + '...';
       end;
   end;
end;


Like I say, it aims to cut at a space, which prevents a lot of
unfortunate incidents with rude words made from innocent ones. I'll
leave those to your imaginations...


--

Matthew Jones
Tue, May 3 2016 3:34 PMPermanent Link

Trinione

Thank you both.

Thanks for the example, especially as I didn't know how to implement ContentWidth. I shall test the SizeCheck routine, if it adds time then I shall have to truncate text as faster is better for something like this.

I wonder if Tim can work some of his magic and add a Ellipsis Property to relevant components though?
Wed, May 4 2016 4:35 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

<< Can a TextEllipsis property (True/False maybe) be added to the Label, Edit, MultiLineEdit, Button and any other relevant component? >>

Sure, I can add it to the base Format property of all UI elements.  That way, anything that surfaces that property will get this new sub-property.

Tim Young
Elevate Software
www.elevatesoft.com
Thu, May 5 2016 4:08 AMPermanent Link

Matthew Jones

Tim Young [Elevate Software] wrote:

> << Can a TextEllipsis property (True/False maybe) be added to the
> Label, Edit, MultiLineEdit, Button and any other relevant component?
> >>
>
> Sure, I can add it to the base Format property of all UI elements.
> That way, anything that surfaces that property will get this new
> sub-property.

Can I suggest you make it an enum, rather than true false? That way it
can be expanded (by you or ourselves) at some point. The obvious one is
end-ellipsis, but path shrinking ("C:\Data\...\MyFile.txt") is common
too, and maybe others. The enum with just "off" and "trailing" would
allow for expansion later.


--

Matthew Jones
Fri, May 6 2016 7:44 AMPermanent Link

Matthew Jones

Matthew Jones wrote:

> function TruncateText(szText : String; nTargetLen : Integer) : String;

I'll leave it as an exercise for the reader to work out the stupid
mistake in that function...  (It will be obvious when you try to use
it...)

--

Matthew Jones
Fri, May 6 2016 10:16 AMPermanent Link

Trinione

<< > function TruncateText(szText : String; nTargetLen : Integer) : String;

I'll leave it as an exercise for the reader to work out the stupid
mistake in that function...  (It will be obvious when you try to use
it...) >>
--

LOL. I did wonder about it, and focused on the SizeText routine instead. Smile
Fri, May 6 2016 10:37 AMPermanent Link

Matthew Jones

Trinione wrote:

> LOL. I did wonder about it, and focused on the SizeText routine
> instead. Smile

Hey, it wasn't that bad! It works fine, but the first thing it does is
ignore the parameter for the length and set it to 20. Easy line to
delete.

--

Matthew Jones
Image