aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-10-01 12:16:12 +0000
committerrodri <rgl@antares-labs.eu>2023-10-01 12:16:12 +0000
commita6de25225e1f8958e9efab47ecd1134263d661b3 (patch)
treeb682b21b45e8eed2e3e8fec84c3157c4ca2ed9f8
parent44a3faf02ec337da6377fa9a00e4ea7cb7d4e913 (diff)
downloadbattleship-a6de25225e1f8958e9efab47ecd1134263d661b3.tar.gz
battleship-a6de25225e1f8958e9efab47ecd1134263d661b3.tar.bz2
battleship-a6de25225e1f8958e9efab47ecd1134263d661b3.zip
fixed a Menulist.update bug where it would return 0 when there were no entries.
-rw-r--r--menulist.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/menulist.c b/menulist.c
index 9b439fa..90eaa31 100644
--- a/menulist.c
+++ b/menulist.c
@@ -68,10 +68,16 @@ menulist_update(Menulist *ml, Mousectl *mc, Channel *drawchan)
/* redundant from bts.c:/^mouse\(, but it's necessary to avoid overdrawing */
static Mouse oldm;
static ulong lastlmbms;
+ Rectangle r;
int selected;
+ if(ml->nentries < 1)
+ return -1;
+
+ r = ml->nentries < Maxvisitems? ml->r: Rpt(ml->sr.min, ml->r.max);
+
selected = -1;
- if(ptinrect(mc->xy, Rpt(ml->sr.min, ml->r.max))){
+ if(ptinrect(mc->xy, r)){
if(ptinrect(mc->xy, ml->r)){
/* item highlighting and selection */
ml->high = ml->off + (mc->xy.y - ml->r.min.y)/(font->height+Vspace);