popup: keep only computed geometry in Popup; one fallback for slivers

numx, textx and selx were compile-time constants stored per layout;
the number column starts at PopupPad and text at PopupPad+PopupNumw,
which dat.h now says once. The height fallback tried dropping the
marker, then the preedit, then the padding as three separate refits;
below one padded row it now shows as many bare rows as fit, at least
one, which is what those steps added up to.
This commit is contained in:
2026-08-16 18:27:24 +09:00
parent 68678283cd
commit 3f1ff03b94
3 changed files with 25 additions and 34 deletions

View File

@@ -123,7 +123,6 @@ popuplayout(Drawcmd *dc, int areaw, int areah, Popup *p)
p->prey = -1;
p->sepy = -1;
p->rowsy = -1;
p->markx = -1;
p->marky = -1;
p->sely = -1;
pad = PopupPad;
@@ -132,6 +131,8 @@ popuplayout(Drawcmd *dc, int areaw, int areah, Popup *p)
if((nall == 0 && !npre) || areaw <= 0 || areah <= 0)
return;
/* Rows first; a page marker when they do not all fit; and in a
* sliver of a work area the selected row alone, unpadded. */
total = max(dc->total, dc->first + nall);
markrow = dc->first > 0 || nall < total;
p->n = fitrows(areah, npre, markrow, nall);
@@ -143,13 +144,10 @@ popuplayout(Drawcmd *dc, int areaw, int areah, Popup *p)
markrow = 0;
p->n = fitrows(areah, npre, markrow, nall);
}
if(p->n == 0 && npre && nall != 0){
npre = 0;
p->n = fitrows(areah, npre, markrow, nall);
}
if(p->n == 0 && nall != 0){
p->n = 1;
npre = 0;
pad = 0;
p->n = max(min(nall, areah / Fontsz), 1);
}
if(p->n != 0 && dc->sel >= p->n)
p->row0 = min(dc->sel - p->n + 1, nall - p->n);
@@ -189,14 +187,11 @@ popuplayout(Drawcmd *dc, int areaw, int areah, Popup *p)
y += Fontsz;
}
p->h = min(y + pad, areah);
p->numx = PopupPad;
p->textx = PopupPad + PopupNumw;
p->textw = max(p->w - PopupPad - p->textx, 0);
p->textw = max(p->w - 2*PopupPad - PopupNumw, 0);
if(markrow){
p->markw = min(p->markw, max(p->w - 2*PopupPad, 0));
p->markx = p->w - PopupPad - p->markw;
}
p->selx = PopupPad;
p->selw = max(p->w - 2*PopupPad, 0);
if(dc->sel >= p->row0 && dc->sel < p->row0 + p->n)
p->sely = p->rowsy + (dc->sel - p->row0)*Fontsz;
@@ -221,18 +216,17 @@ popupdraw(u32int *img, Drawcmd *dc, Popup *p)
fillrect(img, p->w, p->h, PopupPad, p->sepy,
p->w - 2*PopupPad, PopupSep, Colsep);
if(p->sely >= 0)
fillrect(img, p->w, p->h, p->selx, p->sely,
fillrect(img, p->w, p->h, PopupPad, p->sely,
p->selw, Fontsz, Colsel);
for(i = 0, y = p->rowsy; i < p->n; i++, y += Fontsz){
j = p->row0 + i;
color = j == dc->sel ? Colselfg : Colfg;
sclear(&num);
sputr(&num, '1' + j + Asciitofull);
textdraw(img, p->w, p->h, p->numx, y,
min(PopupNumw, max(p->w - PopupPad - p->numx, 0)),
color, &num);
textdraw(img, p->w, p->h, p->textx, y, p->textw, color,
&dc->kouho[j]);
textdraw(img, p->w, p->h, PopupPad, y,
min(PopupNumw, max(p->w - 2*PopupPad, 0)), color, &num);
textdraw(img, p->w, p->h, PopupPad + PopupNumw, y, p->textw,
color, &dc->kouho[j]);
}
if(p->marky >= 0)
textdraw(img, p->w, p->h, p->markx, p->marky, p->markw,