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:
10
dat.h
10
dat.h
@@ -142,6 +142,11 @@ struct Drawcmd
|
|||||||
Caret caret;
|
Caret caret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Popup geometry from popuplayout: n rows from row0 of the candidates,
|
||||||
|
* each Fontsz tall; a section's y is -1 when it is absent. Numbers
|
||||||
|
* start at PopupPad, text at PopupPad+PopupNumw.
|
||||||
|
*/
|
||||||
typedef struct Popup Popup;
|
typedef struct Popup Popup;
|
||||||
struct Popup
|
struct Popup
|
||||||
{
|
{
|
||||||
@@ -152,14 +157,11 @@ struct Popup
|
|||||||
int prey;
|
int prey;
|
||||||
int sepy;
|
int sepy;
|
||||||
int rowsy;
|
int rowsy;
|
||||||
int numx;
|
|
||||||
int textx;
|
|
||||||
int textw;
|
int textw;
|
||||||
int markx;
|
|
||||||
int marky;
|
int marky;
|
||||||
|
int markx;
|
||||||
int markw;
|
int markw;
|
||||||
Str mark;
|
Str mark;
|
||||||
int selx;
|
|
||||||
int sely;
|
int sely;
|
||||||
int selw;
|
int selw;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -123,7 +123,6 @@ popuplayout(Drawcmd *dc, int areaw, int areah, Popup *p)
|
|||||||
p->prey = -1;
|
p->prey = -1;
|
||||||
p->sepy = -1;
|
p->sepy = -1;
|
||||||
p->rowsy = -1;
|
p->rowsy = -1;
|
||||||
p->markx = -1;
|
|
||||||
p->marky = -1;
|
p->marky = -1;
|
||||||
p->sely = -1;
|
p->sely = -1;
|
||||||
pad = PopupPad;
|
pad = PopupPad;
|
||||||
@@ -132,6 +131,8 @@ popuplayout(Drawcmd *dc, int areaw, int areah, Popup *p)
|
|||||||
if((nall == 0 && !npre) || areaw <= 0 || areah <= 0)
|
if((nall == 0 && !npre) || areaw <= 0 || areah <= 0)
|
||||||
return;
|
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);
|
total = max(dc->total, dc->first + nall);
|
||||||
markrow = dc->first > 0 || nall < total;
|
markrow = dc->first > 0 || nall < total;
|
||||||
p->n = fitrows(areah, npre, markrow, nall);
|
p->n = fitrows(areah, npre, markrow, nall);
|
||||||
@@ -143,13 +144,10 @@ popuplayout(Drawcmd *dc, int areaw, int areah, Popup *p)
|
|||||||
markrow = 0;
|
markrow = 0;
|
||||||
p->n = fitrows(areah, npre, markrow, nall);
|
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){
|
if(p->n == 0 && nall != 0){
|
||||||
p->n = 1;
|
npre = 0;
|
||||||
pad = 0;
|
pad = 0;
|
||||||
|
p->n = max(min(nall, areah / Fontsz), 1);
|
||||||
}
|
}
|
||||||
if(p->n != 0 && dc->sel >= p->n)
|
if(p->n != 0 && dc->sel >= p->n)
|
||||||
p->row0 = min(dc->sel - p->n + 1, nall - 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;
|
y += Fontsz;
|
||||||
}
|
}
|
||||||
p->h = min(y + pad, areah);
|
p->h = min(y + pad, areah);
|
||||||
p->numx = PopupPad;
|
p->textw = max(p->w - 2*PopupPad - PopupNumw, 0);
|
||||||
p->textx = PopupPad + PopupNumw;
|
|
||||||
p->textw = max(p->w - PopupPad - p->textx, 0);
|
|
||||||
if(markrow){
|
if(markrow){
|
||||||
p->markw = min(p->markw, max(p->w - 2*PopupPad, 0));
|
p->markw = min(p->markw, max(p->w - 2*PopupPad, 0));
|
||||||
p->markx = p->w - PopupPad - p->markw;
|
p->markx = p->w - PopupPad - p->markw;
|
||||||
}
|
}
|
||||||
p->selx = PopupPad;
|
|
||||||
p->selw = max(p->w - 2*PopupPad, 0);
|
p->selw = max(p->w - 2*PopupPad, 0);
|
||||||
if(dc->sel >= p->row0 && dc->sel < p->row0 + p->n)
|
if(dc->sel >= p->row0 && dc->sel < p->row0 + p->n)
|
||||||
p->sely = p->rowsy + (dc->sel - p->row0)*Fontsz;
|
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,
|
fillrect(img, p->w, p->h, PopupPad, p->sepy,
|
||||||
p->w - 2*PopupPad, PopupSep, Colsep);
|
p->w - 2*PopupPad, PopupSep, Colsep);
|
||||||
if(p->sely >= 0)
|
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);
|
p->selw, Fontsz, Colsel);
|
||||||
for(i = 0, y = p->rowsy; i < p->n; i++, y += Fontsz){
|
for(i = 0, y = p->rowsy; i < p->n; i++, y += Fontsz){
|
||||||
j = p->row0 + i;
|
j = p->row0 + i;
|
||||||
color = j == dc->sel ? Colselfg : Colfg;
|
color = j == dc->sel ? Colselfg : Colfg;
|
||||||
sclear(&num);
|
sclear(&num);
|
||||||
sputr(&num, '1' + j + Asciitofull);
|
sputr(&num, '1' + j + Asciitofull);
|
||||||
textdraw(img, p->w, p->h, p->numx, y,
|
textdraw(img, p->w, p->h, PopupPad, y,
|
||||||
min(PopupNumw, max(p->w - PopupPad - p->numx, 0)),
|
min(PopupNumw, max(p->w - 2*PopupPad, 0)), color, &num);
|
||||||
color, &num);
|
textdraw(img, p->w, p->h, PopupPad + PopupNumw, y, p->textw,
|
||||||
textdraw(img, p->w, p->h, p->textx, y, p->textw, color,
|
color, &dc->kouho[j]);
|
||||||
&dc->kouho[j]);
|
|
||||||
}
|
}
|
||||||
if(p->marky >= 0)
|
if(p->marky >= 0)
|
||||||
textdraw(img, p->w, p->h, p->markx, p->marky, p->markw,
|
textdraw(img, p->w, p->h, p->markx, p->marky, p->markw,
|
||||||
|
|||||||
@@ -166,10 +166,8 @@ popup_layout(struct ct *t)
|
|||||||
CT_EQ_INT(t, PopupPad, p.rowsy);
|
CT_EQ_INT(t, PopupPad, p.rowsy);
|
||||||
CT_EQ_INT(t, -1, p.marky);
|
CT_EQ_INT(t, -1, p.marky);
|
||||||
CT_EQ_INT(t, 2*PopupPad + 2*Fontsz, p.h);
|
CT_EQ_INT(t, 2*PopupPad + 2*Fontsz, p.h);
|
||||||
CT_EQ_INT(t, PopupPad, p.numx);
|
|
||||||
CT_EQ_INT(t, p.numx + PopupNumw, p.textx);
|
|
||||||
CT_EQ_INT(t, PopupTextw, p.textw);
|
CT_EQ_INT(t, PopupTextw, p.textw);
|
||||||
CT_EQ_INT(t, p.w - PopupPad, p.textx + p.textw);
|
CT_EQ_INT(t, p.w - PopupPad, PopupPad + PopupNumw + p.textw);
|
||||||
|
|
||||||
/* Preedit and candidates meet at one separator, with no empty rows. */
|
/* Preedit and candidates meet at one separator, with no empty rows. */
|
||||||
dc.pre = mkstr("preedit");
|
dc.pre = mkstr("preedit");
|
||||||
@@ -212,12 +210,9 @@ popup_layout(struct ct *t)
|
|||||||
CT_EQ_INT(t, 2*PopupBasew, p.w);
|
CT_EQ_INT(t, 2*PopupBasew, p.w);
|
||||||
CT_CHECK(t, p.h <= Imgh);
|
CT_CHECK(t, p.h <= Imgh);
|
||||||
CT_EQ_INT(t, p.w - PopupPad, p.markx + p.markw);
|
CT_EQ_INT(t, p.w - PopupPad, p.markx + p.markw);
|
||||||
CT_EQ_INT(t, PopupPad, p.selx);
|
|
||||||
CT_EQ_INT(t, p.w - 2*PopupPad, p.selw);
|
CT_EQ_INT(t, p.w - 2*PopupPad, p.selw);
|
||||||
CT_EQ_INT(t, p.rowsy + dc.sel*Fontsz, p.sely);
|
CT_EQ_INT(t, p.rowsy + dc.sel*Fontsz, p.sely);
|
||||||
CT_EQ_INT(t, PopupPad, p.numx);
|
CT_EQ_INT(t, p.w - PopupPad, PopupPad + PopupNumw + p.textw);
|
||||||
CT_EQ_INT(t, p.numx + PopupNumw, p.textx);
|
|
||||||
CT_EQ_INT(t, p.w - PopupPad, p.textx + p.textw);
|
|
||||||
|
|
||||||
img = emalloc(2*PopupBasew*Imgh*sizeof img[0]);
|
img = emalloc(2*PopupBasew*Imgh*sizeof img[0]);
|
||||||
popupdraw(img, &dc, &p);
|
popupdraw(img, &dc, &p);
|
||||||
@@ -232,7 +227,7 @@ popup_layout(struct ct *t)
|
|||||||
for(y = p.sely; y < p.sely + Fontsz; y++){
|
for(y = p.sely; y < p.sely + Fontsz; y++){
|
||||||
for(x = 0; x < p.w; x++){
|
for(x = 0; x < p.w; x++){
|
||||||
c = pixel(img, &p, x, y);
|
c = pixel(img, &p, x, y);
|
||||||
if(x < p.selx || x >= p.selx + p.selw){
|
if(x < PopupPad || x >= PopupPad + p.selw){
|
||||||
CT_EQ_UINT(t, Colbg, c);
|
CT_EQ_UINT(t, Colbg, c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -241,9 +236,9 @@ popup_layout(struct ct *t)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
CT_CHECK(t,
|
CT_CHECK(t,
|
||||||
(x >= p.numx && x < p.numx + PopupNumw) ||
|
(x >= PopupPad && x < PopupPad + PopupNumw) ||
|
||||||
(x >= p.textx && x < p.textx + p.textw));
|
(x >= (PopupPad + PopupNumw) && x < (PopupPad + PopupNumw) + p.textw));
|
||||||
if(x < p.numx + PopupNumw)
|
if(x < PopupPad + PopupNumw)
|
||||||
numink++;
|
numink++;
|
||||||
else
|
else
|
||||||
textink++;
|
textink++;
|
||||||
@@ -277,7 +272,7 @@ popup_layout(struct ct *t)
|
|||||||
CT_CHECK(t, p.textw > PopupTextw);
|
CT_CHECK(t, p.textw > PopupTextw);
|
||||||
CT_CHECK(t, n > p.textw);
|
CT_CHECK(t, n > p.textw);
|
||||||
CT_EQ_INT(t, PopupPad, p.rowsy);
|
CT_EQ_INT(t, PopupPad, p.rowsy);
|
||||||
CT_EQ_INT(t, p.w - PopupPad, p.textx + p.textw);
|
CT_EQ_INT(t, p.w - PopupPad, PopupPad + PopupNumw + p.textw);
|
||||||
popupdraw(img, &dc, &p);
|
popupdraw(img, &dc, &p);
|
||||||
ink = 0;
|
ink = 0;
|
||||||
for(y = p.rowsy; y < p.rowsy + Fontsz; y++){
|
for(y = p.rowsy; y < p.rowsy + Fontsz; y++){
|
||||||
@@ -285,7 +280,7 @@ popup_layout(struct ct *t)
|
|||||||
c = pixel(img, &p, x, y);
|
c = pixel(img, &p, x, y);
|
||||||
if(x < PopupPad || x >= p.w - PopupPad)
|
if(x < PopupPad || x >= p.w - PopupPad)
|
||||||
CT_EQ_UINT(t, Colbg, c);
|
CT_EQ_UINT(t, Colbg, c);
|
||||||
if(x >= p.textx && x < p.textx + p.textw &&
|
if(x >= (PopupPad + PopupNumw) && x < (PopupPad + PopupNumw) + p.textw &&
|
||||||
c != (Colbg & Rgbmask))
|
c != (Colbg & Rgbmask))
|
||||||
ink++;
|
ink++;
|
||||||
}
|
}
|
||||||
@@ -312,7 +307,7 @@ popup_layout(struct ct *t)
|
|||||||
popupdraw(img, &dc, &p);
|
popupdraw(img, &dc, &p);
|
||||||
numink = 0;
|
numink = 0;
|
||||||
for(y = p.rowsy; y < p.rowsy + Fontsz; y++)
|
for(y = p.rowsy; y < p.rowsy + Fontsz; y++)
|
||||||
for(x = p.numx; x < p.numx + PopupNumw; x++)
|
for(x = PopupPad; x < PopupPad + PopupNumw; x++)
|
||||||
if(pixel(img, &p, x, y) != (Colsel & Rgbmask))
|
if(pixel(img, &p, x, y) != (Colsel & Rgbmask))
|
||||||
numink++;
|
numink++;
|
||||||
markink = 0;
|
markink = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user