changeset 24979:476d4922566a

Make page up and down with proper page size instead of always 10 rows.
author ulion
date Sat, 10 Nov 2007 02:01:41 +0000
parents 334ccebe77c4
children 19e208a0296d
files libmenu/menu_list.c libmenu/menu_list.h
diffstat 2 files changed, 16 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/libmenu/menu_list.c	Fri Nov 09 21:52:23 2007 +0000
+++ b/libmenu/menu_list.c	Sat Nov 10 02:01:41 2007 +0000
@@ -78,30 +78,32 @@
   need_h = count * (mpriv->vspace + vo_font->height) - mpriv->vspace;
   if( need_h + th > dh) {
     int start,end;
-    int maxl = (dh + mpriv->vspace - th) / (mpriv->vspace + vo_font->height);
-    if(maxl < 4) {
+    mpriv->disp_lines = (dh + mpriv->vspace - th) / (mpriv->vspace + vo_font->height);
+    if(mpriv->disp_lines < 4) {
       th = 0;
-      maxl = (dh + mpriv->vspace) / ( vo_font->height + mpriv->vspace);
+      mpriv->disp_lines = (dh + mpriv->vspace) / ( vo_font->height + mpriv->vspace);
     }
     // Too smoll
-    if(maxl < 1) return;
-    need_h = maxl*(mpriv->vspace + vo_font->height) - mpriv->vspace;
+    if(mpriv->disp_lines < 1) return;
+    need_h = mpriv->disp_lines*(mpriv->vspace + vo_font->height) - mpriv->vspace;
 
-    start = sidx - (maxl/2);
+    start = sidx - (mpriv->disp_lines/2);
     if(start < 0) start = 0;
-    end = start + maxl;
+    end = start + mpriv->disp_lines;
     if(end > count) {
       end = count;
-      if(end - start < maxl)
-	start = end - maxl < 0 ? 0 : end - maxl;
+      if(end - start < mpriv->disp_lines)
+	start = end - mpriv->disp_lines < 0 ? 0 : end - mpriv->disp_lines;
     }
     m = mpriv->menu;
     for(i = 0 ; m->next && i < start ; ) {
       if(!m->hide) i++;
       m = m->next;
     }
-  } else
+  } else {
     m = mpriv->menu;
+    mpriv->disp_lines = count;
+  }
 
   bg_w = need_w+2*mpriv->minb;
   if(th > 0) {
@@ -219,13 +221,13 @@
       mpriv->current = m;
     break;
   case KEY_PAGE_UP:
-    for(i = 0, m = mpriv->current ; m && m->prev && i < 10 ; m = m->prev, i++)
+    for(i = 0, m = mpriv->current ; m && m->prev && i < mpriv->disp_lines ; m = m->prev, i++)
       /**/;
     if(m)
       mpriv->current = m;
     break;
   case KEY_PAGE_DOWN:
-    for(i = 0, m = mpriv->current ; m && m->next && i < 10 ; m = m->next, i++)
+    for(i = 0, m = mpriv->current ; m && m->next && i < mpriv->disp_lines ; m = m->next, i++)
       /**/;
     if(m)
       mpriv->current = m;
--- a/libmenu/menu_list.h	Fri Nov 09 21:52:23 2007 +0000
+++ b/libmenu/menu_list.h	Sat Nov 10 02:01:41 2007 +0000
@@ -28,6 +28,7 @@
   int x,y;
   int w,h;
   int vspace, minb;
+  int disp_lines;
   char* ptr;
   int title_bg,title_bg_alpha;
   int item_bg,item_bg_alpha;
@@ -55,6 +56,7 @@
   -1,-1, \
   0,0, \
   5, 3, \
+  0, \
   NULL, \
   0xFF, 0xFF, \
   0xFF, 0xFF, \