popup: refine the input panel
This commit is contained in:
76
win.c
76
win.c
@@ -2,10 +2,6 @@
|
||||
#include "dat.h"
|
||||
#include "fn.h"
|
||||
|
||||
enum {
|
||||
Asciitofull = 0xFEE0,
|
||||
};
|
||||
|
||||
static xcb_connection_t *conn;
|
||||
static xcb_screen_t *scr;
|
||||
static xcb_window_t win;
|
||||
@@ -146,46 +142,6 @@ wininit(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
fill(u32int *buf, int n, u32int color)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < n; i++)
|
||||
buf[i] = color;
|
||||
}
|
||||
|
||||
static void
|
||||
drawkouho(Drawcmd *dc, int n, int w, int h)
|
||||
{
|
||||
char buf[32];
|
||||
int nmark, npre, sely, y, i;
|
||||
Str mark, num, *s;
|
||||
|
||||
if(w <= 0 || w > Imgw || h <= 0 || h > Imgh)
|
||||
return;
|
||||
fill(img, w * h, Colbg);
|
||||
npre = dc->pre.n != 0;
|
||||
if(npre)
|
||||
textdraw(img, w, h, 0, 0, &dc->pre);
|
||||
if(dc->sel >= 0 && dc->sel < n){
|
||||
sely = (npre + dc->sel) * Fontsz;
|
||||
fill(img + sely * w, Fontsz * w, Colsel);
|
||||
}
|
||||
for(i = 0, y = npre * Fontsz; i < n; i++, y += Fontsz){
|
||||
s = &dc->kouho[i];
|
||||
sclear(&num);
|
||||
sputr(&num, '1' + i + Asciitofull);
|
||||
textdraw(img, w, h, 0, y, &num);
|
||||
textdrawfit(img, w, h, 2*Fontsz, y, w - 2*Fontsz, s);
|
||||
}
|
||||
nmark = pagemarker(buf, sizeof buf, dc->first, n, dc->total);
|
||||
if(nmark != 0){
|
||||
sinit(&mark, buf, nmark);
|
||||
textdraw(img, w, h, 0, y, &mark);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
putimage(int w, int h)
|
||||
{
|
||||
@@ -207,32 +163,20 @@ winhide(void)
|
||||
static int
|
||||
winshow(Drawcmd *dc)
|
||||
{
|
||||
char buf[32];
|
||||
vlong width;
|
||||
int nmark, npre, px, py, w, h, i, n, maxw;
|
||||
Str mark;
|
||||
Popup p;
|
||||
int px, py;
|
||||
u32int vals[4];
|
||||
xcb_query_pointer_reply_t *ptr;
|
||||
xcb_query_pointer_cookie_t cookie;
|
||||
|
||||
n = min(max(dc->nkouho, 0), Maxdisp);
|
||||
npre = dc->pre.n != 0;
|
||||
if(n == 0 && npre == 0){
|
||||
if(dc->nkouho <= 0 && dc->pre.n == 0){
|
||||
return winhide();
|
||||
}
|
||||
maxw = textwidth(&dc->pre);
|
||||
for(i = 0; i < n; i++)
|
||||
maxw = max(maxw, textwidth(&dc->kouho[i]));
|
||||
nmark = pagemarker(buf, sizeof buf, dc->first, n, dc->total);
|
||||
if(nmark != 0){
|
||||
sinit(&mark, buf, nmark);
|
||||
maxw = max(maxw, textwidth(&mark));
|
||||
}
|
||||
vals[3] = h = (n + npre + (nmark != 0)) * Fontsz;
|
||||
width = (vlong)maxw + 3*Fontsz;
|
||||
vals[2] = w = min(min(max(width, 1), Imgw), scr->width_in_pixels);
|
||||
if(w <= 0 || w > Imgw || h <= 0 || h > Imgh)
|
||||
popuplayout(dc, scr->width_in_pixels, &p);
|
||||
if(p.w <= 0 || p.w > Imgw || p.h <= 0 || p.h > Imgh)
|
||||
return 0;
|
||||
vals[2] = p.w;
|
||||
vals[3] = p.h;
|
||||
px = py = 0;
|
||||
if(!dc->caret.valid){
|
||||
cookie = xcb_query_pointer(conn, scr->root);
|
||||
@@ -244,7 +188,7 @@ winshow(Drawcmd *dc)
|
||||
free(ptr);
|
||||
}
|
||||
popupposition(&dc->caret, px, py, scr->width_in_pixels,
|
||||
scr->height_in_pixels, w, h, &px, &py);
|
||||
scr->height_in_pixels, p.w, p.h, &px, &py);
|
||||
vals[1] = py;
|
||||
vals[0] = px;
|
||||
xcb_configure_window(conn, win,
|
||||
@@ -252,8 +196,8 @@ winshow(Drawcmd *dc)
|
||||
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
|
||||
vals);
|
||||
xcb_map_window(conn, win);
|
||||
drawkouho(dc, n, w, h);
|
||||
putimage(w, h);
|
||||
popupdraw(img, dc, &p);
|
||||
putimage(p.w, p.h);
|
||||
return xcb_flush(conn) > 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user