added items count.

This commit is contained in:
Crony Akatsuki 2022-07-21 17:35:07 +02:00
parent ce3c2b5ce2
commit e8d03b97fe

27
dmenu.c
View File

@ -25,6 +25,8 @@
&& MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org))) && MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
#define LENGTH(X) (sizeof X / sizeof X[0]) #define LENGTH(X) (sizeof X / sizeof X[0])
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
#define NUMBERSMAXDIGITS 100
#define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1
/* define opaqueness */ /* define opaqueness */
#define OPAQUE 0xFFU #define OPAQUE 0xFFU
@ -38,6 +40,7 @@ struct item {
int out; int out;
}; };
static char numbers[NUMBERSBUFSIZE] = "";
static char text[BUFSIZ] = ""; static char text[BUFSIZ] = "";
static char *embed; static char *embed;
static int bh, mw, mh; static int bh, mw, mh;
@ -128,7 +131,7 @@ calcoffsets(void)
if (lines > 0) if (lines > 0)
n = lines * bh; n = lines * bh;
else else
n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">")); n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">") + TEXTW(numbers));
/* calculate which items will begin the next page and previous page */ /* calculate which items will begin the next page and previous page */
for (i = 0, next = curr; next; next = next->right) for (i = 0, next = curr; next; next = next->right)
if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n) if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
@ -175,6 +178,21 @@ drawitem(struct item *item, int x, int y, int w)
return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
} }
static void
recalculatenumbers()
{
unsigned int numer = 0, denom = 0;
struct item *item;
if (matchend) {
numer++;
for (item = matchend; item && item->left; item = item->left)
numer++;
}
for (item = items; item && item->text; item++)
denom++;
snprintf(numbers, NUMBERSBUFSIZE, "%d/%d", numer, denom);
}
static void static void
drawmenu(void) drawmenu(void)
{ {
@ -206,6 +224,7 @@ drawmenu(void)
drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0); drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0);
} }
recalculatenumbers();
if (lines > 0) { if (lines > 0) {
/* draw vertical list */ /* draw vertical list */
for (item = curr; item != next; item = item->right) for (item = curr; item != next; item = item->right)
@ -220,13 +239,15 @@ drawmenu(void)
} }
x += w; x += w;
for (item = curr; item != next; item = item->right) for (item = curr; item != next; item = item->right)
x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">"))); x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">") - TEXTW(numbers)));
if (next) { if (next) {
w = TEXTW(">"); w = TEXTW(">");
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0); drw_text(drw, mw - w - TEXTW(numbers), 0, w, bh, lrpad / 2, ">", 0);
} }
} }
drw_setscheme(drw, scheme[SchemeNorm]);
drw_text(drw, mw - TEXTW(numbers), 0, TEXTW(numbers), bh, lrpad / 2, numbers, 0);
drw_map(drw, win, 0, 0, mw, mh); drw_map(drw, win, 0, 0, mw, mh);
} }