From 8ec0a618a1fd433057181474e2a59a4bac9da3a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 8 Jul 2005 01:41:38 +0000 Subject: [PATCH] Fixed truncate_middle(): could add ellipsis without any reason under some circumstances. Also, the first letter that is tested to be added to either side is taken from the side with less letters now, instead of the one with the bigger letter. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13552 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/InterfaceDefs.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/kits/interface/InterfaceDefs.cpp b/src/kits/interface/InterfaceDefs.cpp index 14cf6ac1d6..d31db3bbe8 100644 --- a/src/kits/interface/InterfaceDefs.cpp +++ b/src/kits/interface/InterfaceDefs.cpp @@ -1192,13 +1192,28 @@ truncate_middle(const char* source, char* dest, uint32 numChars, strcpy(dest, ""); return true; } + + // see if the gap between left/right is smaller than the ellipsis + + float totalWidth = rightWidth + leftWidth; + + for (uint32 i = left; i < right; i++) { + totalWidth += escapementArray[i]; + if (totalWidth > width) + break; + } + + if (totalWidth <= width) { + // the whole string fits! + return false; + } // The ellipsis now definitely fits, but let's // see if we can add another character - float totalWidth = ellipsisWidth + rightWidth + leftWidth; + totalWidth = ellipsisWidth + rightWidth + leftWidth; - if (escapementArray[left] < escapementArray[right]) { + if (left > numChars - right) { // try right letter first if (escapementArray[right] + totalWidth <= width) right--;