ref: ffe0c0231021825e2e942da02c58786215248ce3
parent: 4763cea22d8104b9fe1b3ef69885bd226512dbac
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Dec 5 09:40:48 EST 2019
adjust column width based on tag info
--- a/zuke.c
+++ b/zuke.c
@@ -55,6 +55,8 @@
static Mousectl *mctl;
static Keyboardctl *kctl;
static int entering;
+static int colwidth[3];
+static int mincolwidth[3];
#pragma varargck type "P" int
static int
@@ -77,12 +79,34 @@
}
static void
+adjustcolumns(void)
+{
+ int i, x, total;
+
+ if(mincolwidth[0] == 0){
+ mincolwidth[0] = mincolwidth[1] = mincolwidth[2] = 1;
+ for(i = 0; i < plnum; i++){
+ if((x = stringwidth(f, pl[i].artist[0])) > mincolwidth[0])
+ mincolwidth[0] = x;
+ if((x = stringwidth(f, pl[i].album)) > mincolwidth[1])
+ mincolwidth[1] = x;
+ if((x = stringwidth(f, pl[i].title)) > mincolwidth[2])
+ mincolwidth[2] = x;
+ }
+ }
+
+ total = mincolwidth[0] + mincolwidth[1] + mincolwidth[2];
+ for(i = 0; i < nelem(mincolwidth); i++)
+ colwidth[i] = (Dx(screen->r) - 8) * mincolwidth[i] / total;
+}
+
+static void
redraw(Image *screen, int new)
{
Image *col;
Point p, sp;
Rectangle sel, r;
- int i, colwidth, left, scrollcenter;
+ int i, left, scrollcenter;
char tmp[32];
if(entering)
@@ -94,7 +118,7 @@
draw(screen, screen->r, cola, nil, ZP);
scrollsz = Dy(screen->r) / f->height - 1;
- colwidth = (Dx(screen->r) - 8) / 3; /* 3 = artist, album, title */
+ adjustcolumns();
left = screen->r.min.x;
if(scrollsz < plnum){ /* add a scrollbar */
p.x = sp.x = screen->r.min.x + Scrollwidth;
@@ -116,12 +140,12 @@
left += Scrollwidth + 4;
}
- p.x = sp.x = left + colwidth + 4;
+ p.x = sp.x = left + colwidth[0] + 4;
p.y = 0;
sp.y = screen->r.max.y;
- line(screen, p, sp, Endsquare, Endsquare, 0, cola, ZP);
+ line(screen, p, sp, Endsquare, Endsquare, 0, colb, ZP);
- p.x = sp.x = left + colwidth + 8 + colwidth + 4;
+ p.x = sp.x = left + colwidth[0] + 8 + colwidth[1] + 4;
p.y = 0;
sp.y = screen->r.max.y;
line(screen, p, sp, Endsquare, Endsquare, 0, colb, ZP);
@@ -151,17 +175,17 @@
r = screen->r;
p.x = left + 2;
- sel.max.x = p.x + colwidth;
+ sel.max.x = p.x + colwidth[0];
replclipr(screen, 0, sel);
string(screen, p, col, sp, f, pl[i].artist[0]);
- p.x += colwidth + 8;
+ p.x += colwidth[0] + 8;
sel.min.x = p.x;
- sel.max.x = p.x + colwidth;
+ sel.max.x = p.x + colwidth[1];
replclipr(screen, 0, sel);
string(screen, p, col, sp, f, pl[i].album);
- p.x += colwidth + 8;
+ p.x += colwidth[1] + 8;
sel.min.x = p.x;
- sel.max.x = p.x + colwidth;
+ sel.max.x = p.x + colwidth[2];
replclipr(screen, 0, sel);
string(screen, p, col, sp, f, pl[i].title);