popup: place and bound the input panel

This commit is contained in:
2026-08-14 20:00:36 +09:00
parent 7619d2bd9d
commit 193ed009bd
6 changed files with 97 additions and 10 deletions

View File

@@ -178,8 +178,8 @@ font_render(struct ct *t)
{
static char *plain[] = { "A", "", "", "", "", "𠀋" };
u32int *buf, *mem;
Str a, heart, missing;
int i, w;
Str a, heart, longrow, missing;
int i, natural, w, x, y;
mem = emalloc((Testn + 2 * Guard) * sizeof mem[0]);
fillpixels(mem, Testn + 2 * Guard, guardcolor);
@@ -216,6 +216,21 @@ font_render(struct ct *t)
checkclip(t, mem, Fontsz, -Fontsz / 2, &a);
checkclip(t, mem, Fontsz, Testh - Fontsz / 2, &a);
longrow = mkstr("abcdefghijklmnopqrstuvwxyz");
natural = textwidth(&longrow);
CT_CHECK(t, natural > 2*Fontsz);
fillpixels(buf, Testn, Colbg);
textdrawfit(buf, Testw, Testh, 2*Fontsz, Fontsz,
2*Fontsz, &longrow);
CT_CHECK(t, hasink(buf, Testn, Colbg));
for(y = Fontsz; y < 2*Fontsz; y++){
for(x = 0; x < 2*Fontsz; x++)
CT_EQ_UINT(t, Colbg, buf[y * Testw + x] & Rgbmask);
for(x = 4*Fontsz; x < Testw; x++)
CT_EQ_UINT(t, Colbg, buf[y * Testw + x] & Rgbmask);
}
CT_EQ_INT(t, natural, textwidth(&longrow));
missing = mkstr("\xF4\x8F\xBF\xBF");
for(i = 0; i < 32; i++){
textdraw(buf, Testw, Testh, Fontsz, Fontsz, &heart);

View File

@@ -22,11 +22,38 @@ popup_layout(struct ct *t)
caret.y = 590;
popupposition(&caret, 0, 0, 800, 600, 100, 60, &x, &y);
CT_EQ_INT(t, 700, x);
CT_EQ_INT(t, 540, y);
CT_EQ_INT(t, 530, y);
/* Neither side fits: choose above, then clamp to the screen. */
caret.x = 20;
caret.y = 30;
caret.h = 20;
popupposition(&caret, 0, 0, 80, 80, 100, 100, &x, &y);
CT_EQ_INT(t, 0, x);
CT_EQ_INT(t, 0, y);
caret.x = 70;
caret.y = 80;
caret.h = 0;
popupposition(&caret, 0, 0, 800, 600, 100, 60, &x, &y);
CT_EQ_INT(t, 70, x);
CT_EQ_INT(t, 80, y);
caret.h = -20;
popupposition(&caret, 0, 0, 800, 600, 100, 60, &x, &y);
CT_EQ_INT(t, 70, x);
CT_EQ_INT(t, 80, y);
caret.x = INT_MIN;
caret.y = INT_MAX;
caret.h = INT_MAX;
popupposition(&caret, 0, 0, 800, 600, 100, 60, &x, &y);
CT_EQ_INT(t, 0, x);
CT_EQ_INT(t, 540, y);
caret.x = INT_MAX;
caret.y = INT_MIN;
caret.h = INT_MIN;
popupposition(&caret, 0, 0, INT_MAX, INT_MAX,
INT_MAX, INT_MAX, &x, &y);
CT_EQ_INT(t, 0, x);
CT_EQ_INT(t, 0, y);
}