From cf75caeb612ac9b3a1fadf8a63c1632c941d2655 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Sun, 30 Oct 2016 11:42:24 +0100 Subject: Fix listbox_fix_visible_region() Make sure that listbox_fix_visible_region() always updates the visible region to show the entire list if it fits into the box. Also, reuse listbox_fix_visible_region() in listbox_resize() instead of duplicating the code. Signed-off-by: Lukas Fleischer --- src/listbox.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/listbox.c b/src/listbox.c index a620adb..94c07ba 100644 --- a/src/listbox.c +++ b/src/listbox.c @@ -60,6 +60,25 @@ void listbox_delete(struct listbox *lb) mem_free(lb->ch); } +static void listbox_fix_visible_region(struct listbox *lb) +{ + unsigned last_line = lb->ch[lb->item_count] - 1; + int i; + + wins_scrollwin_ensure_visible(&(lb->sw), lb->ch[lb->item_sel]); + wins_scrollwin_ensure_visible(&(lb->sw), lb->ch[lb->item_sel + 1] - 1); + + i = lb->item_sel - 1; + while (i >= 0 && lb->type[i] != LISTBOX_ROW_TEXT) { + wins_scrollwin_ensure_visible(&(lb->sw), lb->ch[i]); + wins_scrollwin_ensure_visible(&(lb->sw), lb->ch[i + 1] - 1); + i++; + } + + if (wins_scrollwin_is_visible(&(lb->sw), last_line)) + wins_scrollwin_set_lower(&(lb->sw), last_line); +} + void listbox_resize(struct listbox *lb, int y, int x, int h, int w) { EXIT_IF(lb == NULL, "null pointer"); @@ -68,13 +87,7 @@ void listbox_resize(struct listbox *lb, int y, int x, int h, int w) if (lb->item_sel < 0) return; - unsigned last_line = lb->ch[lb->item_count] - 1; - - if (wins_scrollwin_is_visible(&(lb->sw), last_line)) - wins_scrollwin_set_lower(&(lb->sw), last_line); - - wins_scrollwin_ensure_visible(&(lb->sw), lb->ch[lb->item_sel]); - wins_scrollwin_ensure_visible(&(lb->sw), lb->ch[lb->item_sel + 1] - 1); + listbox_fix_visible_region(lb); } void listbox_set_cb_data(struct listbox *lb, void *cb_data) @@ -163,21 +176,6 @@ static void listbox_fix_sel(struct listbox *lb, int direction) } } -static void listbox_fix_visible_region(struct listbox *lb) -{ - int i; - - wins_scrollwin_ensure_visible(&(lb->sw), lb->ch[lb->item_sel]); - wins_scrollwin_ensure_visible(&(lb->sw), lb->ch[lb->item_sel + 1] - 1); - - i = lb->item_sel - 1; - while (i >= 0 && lb->type[i] != LISTBOX_ROW_TEXT) { - wins_scrollwin_ensure_visible(&(lb->sw), lb->ch[i]); - wins_scrollwin_ensure_visible(&(lb->sw), lb->ch[i + 1] - 1); - i++; - } -} - void listbox_set_sel(struct listbox *lb, unsigned pos) { lb->item_sel = pos; -- cgit v1.2.3-70-g09d2