From b67e47ca98ee0b41eb4d5ffeb145fc426a6b415b Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Thu, 2 Jan 2025 10:44:59 +0100 Subject: [PATCH] diplay working (perfect display) --- display.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/display.c b/display.c index 8199fcc..fbc03ce 100644 --- 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); } } -- 2.30.2