aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bts.c11
-rw-r--r--dat.h3
-rw-r--r--menulist.c13
3 files changed, 19 insertions, 8 deletions
diff --git a/bts.c b/bts.c
index aa63a4b..1f72a14 100644
--- a/bts.c
+++ b/bts.c
@@ -955,6 +955,9 @@ processcmd(char *cmd)
Point2 cell;
uchar buf[BY2MAP];
int i, idx;
+ struct {
+ int high, off;
+ } menuparams;
if(debug)
fprint(2, "rcvd '%s'\n", cmd);
@@ -987,6 +990,8 @@ processcmd(char *cmd)
break;
case CMmatches:
if(!matches->filling){
+ menuparams.high = matches->high;
+ menuparams.off = matches->off;
matches->clear(matches);
matches->filling = 1;
}
@@ -997,8 +1002,12 @@ processcmd(char *cmd)
smprint("%s vs %s", cb->f[2], cb->f[3]));
break;
case CMendmatches:
- if(matches->filling)
+ if(matches->filling){
+ matches->high = min(menuparams.high, matches->nentries-1);
+ matches->off = menuparams.off > matches->nentries - matches->maxvis?
+ 0: menuparams.off;
matches->filling = 0;
+ }
break;
case CMwatching:
match.id = strtoul(cb->f[1], nil, 10);
diff --git a/dat.h b/dat.h
index f442103..c0a3e2f 100644
--- a/dat.h
+++ b/dat.h
@@ -236,8 +236,9 @@ struct Menulist
Mlist;
char *title;
Rectangle r, sr; /* content and scroll rects */
+ int maxvis; /* max amount of visible entries */
int high; /* [-1,nitems) where -1 is none */
- int off; /* entry offset ∈ [0, nitems-Maxvisitems] */
+ int off; /* entry offset ∈ [0, nitems-maxvis] */
void (*add)(Menulist*, int, char*);
void (*clear)(Menulist*);
diff --git a/menulist.c b/menulist.c
index bafaeea..a8075fb 100644
--- a/menulist.c
+++ b/menulist.c
@@ -32,7 +32,7 @@ menulist_add(Menulist *ml, int id, char *title)
ml->r.max.x = ml->r.min.x + ew;
}
- if(ml->nentries > Maxvisitems){
+ if(ml->nentries > ml->maxvis){
ml->sr.min = subpt(ml->r.min, Pt(Scrollwidth+2*Menuborder,0));
ml->sr.max = Pt(ml->r.min.x-2*Menuborder, ml->r.max.y);
}else if(ml->nentries > 1)
@@ -74,7 +74,7 @@ menulist_update(Menulist *ml, Mousectl *mc, Channel *drawchan)
if(ml->nentries < 1)
return -1;
- r = ml->nentries > Maxvisitems? Rpt(ml->sr.min, ml->r.max): ml->r;
+ r = ml->nentries > ml->maxvis? Rpt(ml->sr.min, ml->r.max): ml->r;
selected = -1;
if(ptinrect(mc->xy, r)){
@@ -88,7 +88,7 @@ menulist_update(Menulist *ml, Mousectl *mc, Channel *drawchan)
lastlmbms = mc->msec;
}
}
- if(mc->buttons != oldm.buttons && ml->nentries > Maxvisitems)
+ if(mc->buttons != oldm.buttons && ml->nentries > ml->maxvis)
/* scrolling */
switch(mc->buttons){
case 1: if(!ptinrect(mc->xy, ml->sr)) break;
@@ -97,7 +97,7 @@ menulist_update(Menulist *ml, Mousectl *mc, Channel *drawchan)
break;
case 4: if(!ptinrect(mc->xy, ml->sr)) break;
case 16:
- ml->off = min(ml->off + (mc->xy.y - ml->sr.min.y)/(font->height+Vspace), ml->nentries-Maxvisitems);
+ ml->off = min(ml->off + (mc->xy.y - ml->sr.min.y)/(font->height+Vspace), ml->nentries-ml->maxvis);
break;
}
}
@@ -145,10 +145,10 @@ menulist_draw(Menulist *ml, Image *dst)
}
/* draw scroll */
- if(ml->nentries > Maxvisitems){
+ if(ml->nentries > ml->maxvis){
border(dst, ml->sr, -Menuborder, bc, ZP);
draw(dst, ml->sr, display->black, nil, ZP);
- draw(dst, Rpt(addpt(ml->sr.min, Pt(0,ml->off*Dy(ml->sr)/ml->nentries)), Pt(ml->sr.max.x,ml->sr.min.y + (ml->off+Maxvisitems)*Dy(ml->sr)/ml->nentries)), display->white, nil, ZP);
+ draw(dst, Rpt(addpt(ml->sr.min, Pt(0,ml->off*Dy(ml->sr)/ml->nentries)), Pt(ml->sr.max.x,ml->sr.min.y + (ml->off+ml->maxvis)*Dy(ml->sr)/ml->nentries)), display->white, nil, ZP);
}
}
@@ -164,6 +164,7 @@ newmenulist(int topmargin, char *title)
w = max(stringwidth(font, title), stringwidth(font, none));
ml->r.min = Pt(SCRW/2 - w/2, topmargin);
ml->r.max = addpt(ml->r.min, Pt(w, font->height+Vspace));
+ ml->maxvis = Maxvisitems;
ml->high = -1;
ml->add = menulist_add;
ml->clear = menulist_clear;