From 11f2de1a29ce3df9f661898436b3db2868137bf9 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sun, 9 Feb 2020 09:18:26 -0500 Subject: Add The Scroll Bar --- ui.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'ui.c') diff --git a/ui.c b/ui.c index b4a2dee..28749c8 100644 --- a/ui.c +++ b/ui.c @@ -48,6 +48,7 @@ static WINDOW *status; static WINDOW *input; +static WINDOW *scrollBar; enum { BufferCap = 512 }; struct Buffer { @@ -119,6 +120,10 @@ static struct Window *windowFor(size_t id) { return window; } +static bool windowScrolled(struct Window *window) { + return window->scroll < BufferCap; +} + static short colorPairs; static void colorInit(void) { @@ -238,18 +243,27 @@ void uiInit(void) { keypad(input, true); nodelay(input, true); + scrollBar = newwin(1, COLS, LINES - 2, 0); + short fg = 8 + COLOR_BLACK; + wbkgd(scrollBar, '~' | colorAttr(fg) | COLOR_PAIR(colorPair(fg, -1))); + windows.active = windowFor(Network); uiShow(); } void uiDraw(void) { wnoutrefresh(status); + int scrolled = windowScrolled(windows.active); pnoutrefresh( windows.active->pad, - windows.active->scroll - WINDOW_LINES, 0, + windows.active->scroll - WINDOW_LINES + scrolled, 0, 1, 0, - BOTTOM - 1, RIGHT + BOTTOM - 1 - scrolled, RIGHT ); + if (scrolled) { + touchwin(scrollBar); + wnoutrefresh(scrollBar); + } int y, x; getyx(input, y, x); pnoutrefresh( @@ -368,10 +382,11 @@ static void statusUpdate(void) { } static void unmark(struct Window *window) { - if (window->scroll < BufferCap) return; - window->heat = Cold; - window->unread = 0; - window->mark = false; + if (!windowScrolled(window)) { + window->heat = Cold; + window->unread = 0; + window->mark = false; + } statusUpdate(); } @@ -462,7 +477,7 @@ void uiWrite(size_t id, enum Heat heat, const time_t *src, const char *str) { statusUpdate(); } lines += wordWrap(window->pad, str); - if (window->scroll < BufferCap) { + if (windowScrolled(window)) { windowScroll(window, -lines); } if (heat > Warm) beep(); -- cgit 1.4.1