From 80a7267f8c03a1c307b4f6b9bee1a906f53a0a01 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 18 Jul 2014 08:19:12 +0200 Subject: Fix selection in listbox_load_items() Call listbox_fix_sel() after setting an initial selection in listbox_load_items() to make sure we do not pick a caption row. Signed-off-by: Lukas Fleischer --- src/listbox.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/listbox.c b/src/listbox.c index 853dc03..c886dce 100644 --- a/src/listbox.c +++ b/src/listbox.c @@ -82,20 +82,18 @@ void listbox_set_cb_data(struct listbox *lb, void *cb_data) lb->cb_data = cb_data; } +static void listbox_fix_sel(struct listbox *, int); + void listbox_load_items(struct listbox *lb, int item_count) { int i, ch; lb->item_count = item_count; - if (item_count > 0 && lb->item_sel < 0) - lb->item_sel = 0; - - if (lb->item_sel >= item_count) - lb->item_sel = item_count - 1; - - if (item_count == 0) + if (item_count == 0) { + lb->item_sel = -1; return; + } free(lb->type); free(lb->ch); @@ -109,6 +107,14 @@ void listbox_load_items(struct listbox *lb, int item_count) lb->ch[item_count] = ch; wins_scrollwin_set_linecount(&(lb->sw), ch); + + if (item_count > 0 && lb->item_sel < 0) { + lb->item_sel = 0; + listbox_fix_sel(lb, 1); + } else if (lb->item_sel >= item_count) { + lb->item_sel = item_count - 1; + listbox_fix_sel(lb, -1); + } } void listbox_draw_deco(struct listbox *lb, int hilt) -- cgit v1.2.3-70-g09d2