From 0b46ad4faaee1ce982a64413b57406e43cb83e88 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 19 May 2014 11:07:52 +0200 Subject: Avoid blank space after the last list box item Automatically scroll down the list box when resizing creates some blank space below the list of items. Signed-off-by: Lukas Fleischer --- src/calcurse.h | 2 ++ src/listbox.c | 5 +++++ src/wins.c | 12 ++++++++++++ 3 files changed, 19 insertions(+) diff --git a/src/calcurse.h b/src/calcurse.h index cb083df..4b804c3 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -1100,7 +1100,9 @@ void wins_scrollwin_draw_deco(struct scrollwin *, int); void wins_scrollwin_display(struct scrollwin *); void wins_scrollwin_up(struct scrollwin *, int); void wins_scrollwin_down(struct scrollwin *, int); +int wins_scrollwin_is_visible(struct scrollwin *, unsigned); void wins_scrollwin_ensure_visible(struct scrollwin *, unsigned); +void wins_scrollwin_set_lower(struct scrollwin *, unsigned); void wins_resize(void); void wins_resize_panels(void); void wins_show(WINDOW *, const char *); diff --git a/src/listbox.c b/src/listbox.c index 7f67fe4..5cdc9a1 100644 --- a/src/listbox.c +++ b/src/listbox.c @@ -68,6 +68,11 @@ 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); } diff --git a/src/wins.c b/src/wins.c index 0d8160a..14616aa 100644 --- a/src/wins.c +++ b/src/wins.c @@ -386,6 +386,12 @@ void wins_scrollwin_down(struct scrollwin *sw, int amount) sw->line_off = sw->line_num - inner_h; } +int wins_scrollwin_is_visible(struct scrollwin *sw, unsigned line) +{ + int inner_h = sw->h - (conf.compact_panels ? 2 : 4); + return ((line >= sw->line_off) && (line < sw->line_off + inner_h)); +} + void wins_scrollwin_ensure_visible(struct scrollwin *sw, unsigned line) { int inner_h = sw->h - (conf.compact_panels ? 2 : 4); @@ -396,6 +402,12 @@ void wins_scrollwin_ensure_visible(struct scrollwin *sw, unsigned line) sw->line_off = line - inner_h + 1; } +void wins_scrollwin_set_lower(struct scrollwin *sw, unsigned line) +{ + int inner_h = sw->h - (conf.compact_panels ? 2 : 4); + sw->line_off = MAX((int)line - inner_h + 1, 0); +} + void wins_resize_panels(void) { wins_get_config(); -- cgit v1.2.3