diplay working (perfect display)
authorLaurent Mazet <mazet@softndesign.org>
Thu, 2 Jan 2025 09:44:59 +0000 (10:44 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Thu, 2 Jan 2025 09:44:59 +0000 (10:44 +0100)
display.c

index 8199fcca1d05bd39c721ae595de1e00094a91acf..fbc03ced3285dcb3482a78d93ff762c433b046a9 100644 (file)
--- a/display.c
+++ b/display.c
@@ -119,19 +119,28 @@ int helpwindow (char *msg, int xoffset, int yoffset)
 
 void displaywindow (window_t *win, list_t *list, int index)
 {
-    int i;
+    int i, j;
+
+    _dobound (win->xsize, win->ysize, win->xoffset, win->yoffset);
+
     int nbcols = win->xsize / (list->width + 1);
     VERBOSE (DEBUG, fprintf (stderr, "nbcols: %d\n", nbcols));
     int width = win->xsize / nbcols;
     VERBOSE (DEBUG, fprintf (stderr, "width: %d\n", width));
     int n = (list->nb + nbcols - 1) / nbcols;
     VERBOSE (DEBUG, fprintf (stderr, "n: %d\n", n));
-    _dobound (win->xsize, win->ysize, win->xoffset, win->yoffset);
-    int rem = list->nb - nbcols * n;
+    int rem = list->nb - nbcols * (list->nb / nbcols);
+    VERBOSE (DEBUG, fprintf (stderr, "rem: %d\n", rem));
 
-    for (i = 0; i < list->nb; i++) {
-        int j = (i % n) - index;
-        if ((j >= 0) && (j < win->ysize)) {
+    for (i = j = 0; i < list->nb; i++, j++) {
+        if ((j + 1 ) % n == 0) {
+            if (rem > 0) {
+                rem--;
+            } else {
+                j++;
+            }
+        }
+        if ((j % n >= index) && (j % n < win->ysize + index)) {
             elem_t *elem = list->tab + i;
             switch (elem->type) {
             case type_unkn_e:
@@ -159,7 +168,7 @@ void displaywindow (window_t *win, list_t *list, int index)
                set_color (red);
                break;
             }
-            mvaddstr (win->yoffset + j, win->xoffset + (i / n) * width, elem->name);
+            mvaddstr (win->yoffset + (j % n) - index, win->xoffset + (j / n) * width, elem->name);
             set_color (white);
         }
     }