popup: stabilize the input panel width
This commit is contained in:
3
dat.h
3
dat.h
@@ -21,6 +21,7 @@ enum
|
|||||||
PopupPad = 4,
|
PopupPad = 4,
|
||||||
PopupSep = 1,
|
PopupSep = 1,
|
||||||
PopupNumw = Fontsz,
|
PopupNumw = Fontsz,
|
||||||
|
PopupTextw = 12*Fontsz,
|
||||||
Maxrunes = 64,
|
Maxrunes = 64,
|
||||||
Maxutf = Maxrunes * UTFmax + 1,
|
Maxutf = Maxrunes * UTFmax + 1,
|
||||||
};
|
};
|
||||||
@@ -30,7 +31,7 @@ enum
|
|||||||
Maxclients = 64,
|
Maxclients = 64,
|
||||||
Maxkouho = 32,
|
Maxkouho = 32,
|
||||||
Maxdisp = 9,
|
Maxdisp = 9,
|
||||||
Imgw = (Maxrunes + 3) * Fontsz,
|
Imgw = 2*PopupPad + PopupNumw + PopupTextw,
|
||||||
Imgh = 2*PopupPad + (Maxdisp + 2)*Fontsz + PopupSep,
|
Imgh = 2*PopupPad + (Maxdisp + 2)*Fontsz + PopupSep,
|
||||||
|
|
||||||
Colfg = 0x000000,
|
Colfg = 0x000000,
|
||||||
|
|||||||
@@ -44,9 +44,8 @@ void
|
|||||||
popuplayout(Drawcmd *dc, int screenw, Popup *p)
|
popuplayout(Drawcmd *dc, int screenw, Popup *p)
|
||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
vlong width;
|
|
||||||
Str mark;
|
Str mark;
|
||||||
int i, maxw, nmark, npre, roww, y;
|
int nmark, npre, y;
|
||||||
|
|
||||||
memset(p, 0, sizeof *p);
|
memset(p, 0, sizeof *p);
|
||||||
p->prey = -1;
|
p->prey = -1;
|
||||||
@@ -60,19 +59,8 @@ popuplayout(Drawcmd *dc, int screenw, Popup *p)
|
|||||||
if(p->n == 0 && !npre)
|
if(p->n == 0 && !npre)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
maxw = npre ? textwidth(&dc->pre) : 0;
|
p->w = min(Imgw, max(screenw, 0));
|
||||||
roww = 0;
|
|
||||||
for(i = 0; i < p->n; i++)
|
|
||||||
roww = max(roww, textwidth(&dc->kouho[i]));
|
|
||||||
if(p->n != 0)
|
|
||||||
maxw = max(maxw, PopupNumw + roww);
|
|
||||||
nmark = pagemarker(buf, sizeof buf, dc->first, p->n, dc->total);
|
nmark = pagemarker(buf, sizeof buf, dc->first, p->n, dc->total);
|
||||||
if(nmark != 0){
|
|
||||||
sinit(&mark, buf, nmark);
|
|
||||||
maxw = max(maxw, textwidth(&mark));
|
|
||||||
}
|
|
||||||
width = (vlong)maxw + 2*PopupPad;
|
|
||||||
p->w = min(min(max(width, 1), Imgw), max(screenw, 0));
|
|
||||||
|
|
||||||
y = PopupPad;
|
y = PopupPad;
|
||||||
if(npre){
|
if(npre){
|
||||||
@@ -96,6 +84,7 @@ popuplayout(Drawcmd *dc, int screenw, Popup *p)
|
|||||||
p->textx = PopupPad + PopupNumw;
|
p->textx = PopupPad + PopupNumw;
|
||||||
p->textw = max(p->w - PopupPad - p->textx, 0);
|
p->textw = max(p->w - PopupPad - p->textx, 0);
|
||||||
if(nmark != 0){
|
if(nmark != 0){
|
||||||
|
sinit(&mark, buf, nmark);
|
||||||
p->markw = min(textwidth(&mark), max(p->w - 2*PopupPad, 0));
|
p->markw = min(textwidth(&mark), max(p->w - 2*PopupPad, 0));
|
||||||
p->markx = p->w - PopupPad - p->markw;
|
p->markx = p->w - PopupPad - p->markw;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ popup_layout(struct ct *t)
|
|||||||
CT_EQ_INT(t, strlen(markers[i].want), n);
|
CT_EQ_INT(t, strlen(markers[i].want), n);
|
||||||
CT_CHECK(t, strcmp(markers[i].want, buf) == 0);
|
CT_CHECK(t, strcmp(markers[i].want, buf) == 0);
|
||||||
}
|
}
|
||||||
|
CT_EQ_INT(t, 12*Fontsz, PopupTextw);
|
||||||
|
CT_EQ_INT(t, 2*PopupPad + PopupNumw + PopupTextw, Imgw);
|
||||||
CT_EQ_INT(t, 2*PopupPad + (1 + Maxdisp + 1)*Fontsz + PopupSep,
|
CT_EQ_INT(t, 2*PopupPad + (1 + Maxdisp + 1)*Fontsz + PopupSep,
|
||||||
Imgh);
|
Imgh);
|
||||||
|
|
||||||
@@ -137,7 +139,8 @@ popup_layout(struct ct *t)
|
|||||||
|
|
||||||
/* Preedit only. */
|
/* Preedit only. */
|
||||||
dc.pre = mkstr("preedit");
|
dc.pre = mkstr("preedit");
|
||||||
popuplayout(&dc, Imgw, &p);
|
popuplayout(&dc, 2*Imgw, &p);
|
||||||
|
CT_EQ_INT(t, Imgw, p.w);
|
||||||
CT_EQ_INT(t, PopupPad, p.prey);
|
CT_EQ_INT(t, PopupPad, p.prey);
|
||||||
CT_EQ_INT(t, -1, p.sepy);
|
CT_EQ_INT(t, -1, p.sepy);
|
||||||
CT_EQ_INT(t, -1, p.rowsy);
|
CT_EQ_INT(t, -1, p.rowsy);
|
||||||
@@ -150,7 +153,8 @@ popup_layout(struct ct *t)
|
|||||||
dc.nkouho = 2;
|
dc.nkouho = 2;
|
||||||
dc.kouho[0] = mkstr("short");
|
dc.kouho[0] = mkstr("short");
|
||||||
dc.kouho[1] = mkstr("candidate");
|
dc.kouho[1] = mkstr("candidate");
|
||||||
popuplayout(&dc, Imgw, &p);
|
popuplayout(&dc, 2*Imgw, &p);
|
||||||
|
CT_EQ_INT(t, Imgw, p.w);
|
||||||
CT_EQ_INT(t, -1, p.prey);
|
CT_EQ_INT(t, -1, p.prey);
|
||||||
CT_EQ_INT(t, -1, p.sepy);
|
CT_EQ_INT(t, -1, p.sepy);
|
||||||
CT_EQ_INT(t, PopupPad, p.rowsy);
|
CT_EQ_INT(t, PopupPad, p.rowsy);
|
||||||
@@ -158,11 +162,13 @@ popup_layout(struct ct *t)
|
|||||||
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, PopupPad, p.numx);
|
||||||
CT_EQ_INT(t, p.numx + PopupNumw, p.textx);
|
CT_EQ_INT(t, p.numx + PopupNumw, p.textx);
|
||||||
|
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, p.textx + 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");
|
||||||
popuplayout(&dc, Imgw, &p);
|
popuplayout(&dc, 2*Imgw, &p);
|
||||||
|
CT_EQ_INT(t, Imgw, p.w);
|
||||||
CT_EQ_INT(t, PopupPad, p.prey);
|
CT_EQ_INT(t, PopupPad, p.prey);
|
||||||
CT_EQ_INT(t, p.prey + Fontsz, p.sepy);
|
CT_EQ_INT(t, p.prey + Fontsz, p.sepy);
|
||||||
CT_EQ_INT(t, p.sepy + PopupSep, p.rowsy);
|
CT_EQ_INT(t, p.sepy + PopupSep, p.rowsy);
|
||||||
@@ -183,7 +189,7 @@ popup_layout(struct ct *t)
|
|||||||
for(i = 0; i < Maxdisp; i++)
|
for(i = 0; i < Maxdisp; i++)
|
||||||
dc.kouho[i] = mkstr(i == dc.sel ? "M" : "candidate");
|
dc.kouho[i] = mkstr(i == dc.sel ? "M" : "candidate");
|
||||||
dc.kouho[0] = longrow;
|
dc.kouho[0] = longrow;
|
||||||
popuplayout(&dc, Imgw, &p);
|
popuplayout(&dc, 2*Imgw, &p);
|
||||||
CT_EQ_INT(t, Maxdisp, p.n);
|
CT_EQ_INT(t, Maxdisp, p.n);
|
||||||
CT_EQ_INT(t, PopupPad, p.prey);
|
CT_EQ_INT(t, PopupPad, p.prey);
|
||||||
CT_EQ_INT(t, p.prey + Fontsz, p.sepy);
|
CT_EQ_INT(t, p.prey + Fontsz, p.sepy);
|
||||||
@@ -191,8 +197,7 @@ popup_layout(struct ct *t)
|
|||||||
CT_EQ_INT(t, p.rowsy + Maxdisp*Fontsz, p.marky);
|
CT_EQ_INT(t, p.rowsy + Maxdisp*Fontsz, p.marky);
|
||||||
CT_EQ_INT(t, p.marky + Fontsz + PopupPad, p.h);
|
CT_EQ_INT(t, p.marky + Fontsz + PopupPad, p.h);
|
||||||
CT_EQ_INT(t, Imgh, p.h);
|
CT_EQ_INT(t, Imgh, p.h);
|
||||||
CT_CHECK(t, p.w > 2*PopupPad + PopupNumw);
|
CT_EQ_INT(t, Imgw, p.w);
|
||||||
CT_CHECK(t, p.w <= Imgw);
|
|
||||||
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, PopupPad, p.selx);
|
||||||
@@ -255,7 +260,9 @@ popup_layout(struct ct *t)
|
|||||||
dc.nkouho = 1;
|
dc.nkouho = 1;
|
||||||
dc.kouho[0] = longrow;
|
dc.kouho[0] = longrow;
|
||||||
n = textwidth(&longrow);
|
n = textwidth(&longrow);
|
||||||
popuplayout(&dc, 6*Fontsz, &p);
|
popuplayout(&dc, 2*Imgw, &p);
|
||||||
|
CT_EQ_INT(t, Imgw, p.w);
|
||||||
|
CT_EQ_INT(t, PopupTextw, p.textw);
|
||||||
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, p.textx + p.textw);
|
||||||
@@ -273,5 +280,8 @@ popup_layout(struct ct *t)
|
|||||||
}
|
}
|
||||||
CT_CHECK(t, ink > 0);
|
CT_CHECK(t, ink > 0);
|
||||||
CT_EQ_INT(t, n, textwidth(&longrow));
|
CT_EQ_INT(t, n, textwidth(&longrow));
|
||||||
|
|
||||||
|
popuplayout(&dc, Imgw - 1, &p);
|
||||||
|
CT_EQ_INT(t, Imgw - 1, p.w);
|
||||||
free(img);
|
free(img);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user