ref: 4cb40bf44feafa85d93450a7299f7014b4277f55
parent: e72d4fab36053ef7261f0cbab6c615a2a4981cee
author: phil9 <[email protected]>
date: Thu Oct 7 14:00:17 EDT 2021
add ellipsis to long text (thanks igor) no care was taken to make sure that text was fitting its rectangle and thus not overflowing on other elements. This needs a bit of rework to add an ellipsis at the beginning of the text for the path as the end is more significant
--- a/vdir.c
+++ b/vdir.c
@@ -25,6 +25,8 @@
Ekeyboard,
};
+const char ellipsis[] = "…";
+
char *home;
char path[256];
Dir* dirs;
@@ -267,6 +269,26 @@
return r;
}
+Point
+drawtext(Point p, Image *i, char* t, int n)
+{
+ int d;
+ char *s;
+ Rune rn;
+
+ d = stringwidth(font, " ")+stringwidth(font, ellipsis);
+ for(s = t; *s; s++){
+ if(p.x+d>=n){
+ string(screen, p, i, ZP, font, ellipsis);
+ break;
+ }else{
+ s += chartorune(&rn, s) - 1;
+ p = runestringn(screen, p, i, ZP, font, &rn, 1);
+ }
+ }
+ return p;
+}
+
void
drawdir(int n, int selected)
{
@@ -293,8 +315,8 @@
draw(screen, Rect(p.x, p.y+dy, p.x+12, p.y+dy+12), img, nil, ZP);
p.x += 12+4+Padding;
p.y += Padding;
- string(screen, p, viewfg, ZP, font, d.name);
- p.x = viewr.max.x - stringwidth(font, buf) - 3*Padding - Toolpadding;
+ p = drawtext(p, viewfg, d.name, viewr.max.x - stringwidth(font, buf) - 2*Padding - Toolpadding);
+ p.x = viewr.max.x - stringwidth(font, buf) - 2*Padding - Toolpadding;
string(screen, p, viewfg, ZP, font, buf);
}
@@ -327,7 +349,7 @@
p.x += Toolpadding;
p.y = toolr.min.y + (Toolpadding+16+Toolpadding-font->height)/2;
pathr = Rect(p.x, p.y, p.x + stringwidth(font, path), p.y + font->height);
- string(screen, p, toolfg, ZP, font, path);
+ p = drawtext(p, toolfg, path, screen->r.max.x - 2*(Toolpadding+16+Toolpadding));
p.x = screen->r.max.x - 2*(Toolpadding+16+Toolpadding);
p.y = screen->r.min.y + Toolpadding;
newdirr = drawbutton(&p, inewfolder);