From 5dbe75fb2473500280e0294604d2b1ba7c692b2e Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Mon, 31 Jan 2022 15:10:25 +0200 Subject: [PATCH] slightly better "ellipsis in center" rendering --- src/x11drawtabs.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/x11drawtabs.c b/src/x11drawtabs.c index eb8373b..d19c047 100644 --- a/src/x11drawtabs.c +++ b/src/x11drawtabs.c @@ -65,15 +65,17 @@ static void xDrawStringEllCenter (int x, int y, int width, int fontset, const ch xDrawStringPart(x, y, fontset, str, bytelen); } else { // need to write it with ellipsis - int ellen = xStringWidth(fontset, "...", 3); - int wmid = width/2-ellen/2; + const char *estr = "..."; + const int estrlen = (int)strlen(estr); + const int ellen = xStringWidth(fontset, estr, estrlen); + const int wmid = width/2-ellen/2; int left_cnt, right_start, blen; // calculate left_cnt left_cnt = 0; while (left_cnt < charlen) { int ww = xStringWidth(fontset, str, charp[left_cnt+1]); - if (ww > wmid) break; ++left_cnt; + if (ww > wmid) break; } // draw left part if (left_cnt > 0) xDrawStringPart(x, y, fontset, str, charp[left_cnt]); @@ -83,9 +85,9 @@ static void xDrawStringEllCenter (int x, int y, int width, int fontset, const ch while (right_start > 0) { int clen = charp[right_start]-charp[right_start-1]; int ww = xStringWidth(fontset, str+charp[right_start-1], blen+clen); - if (ww > wmid) break; --right_start; blen += clen; + if (ww > wmid) break; } // draw right part if (right_start > 0) { @@ -93,7 +95,7 @@ static void xDrawStringEllCenter (int x, int y, int width, int fontset, const ch xDrawStringPart(x+width-ww, y, fontset, str+charp[right_start], blen); } // draw ellipsis - xDrawStringPart(x+(width-ellen)/2, y, fontset, "...", 3); + xDrawStringPart(x+(width-ellen)/2, y, fontset, estr, estrlen); } } } -- 2.11.4.GIT