summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2016-10-30 11:42:24 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2016-10-30 11:56:02 +0100
commitcf75caeb612ac9b3a1fadf8a63c1632c941d2655 (patch)
treefdd78f3aadc86b218a0c5b17539f6c75f7e856de /src
parent0d74c14fd19adcf87103b1fc8815c1901ea9f67a (diff)
downloadcalcurse-cf75caeb612ac9b3a1fadf8a63c1632c941d2655.tar.gz
calcurse-cf75caeb612ac9b3a1fadf8a63c1632c941d2655.zip
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 <lfleischer@calcurse.org>
Diffstat (limited to 'src')
-rw-r--r--src/listbox.c42
1 files 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;