Add The Scroll Bar

weechat-hashes
C. McEnroe 2020-02-09 09:18:26 -05:00
parent 8451543b98
commit 11f2de1a29
1 changed files with 22 additions and 7 deletions

29
ui.c
View File

@ -48,6 +48,7 @@
static WINDOW *status; static WINDOW *status;
static WINDOW *input; static WINDOW *input;
static WINDOW *scrollBar;
enum { BufferCap = 512 }; enum { BufferCap = 512 };
struct Buffer { struct Buffer {
@ -119,6 +120,10 @@ static struct Window *windowFor(size_t id) {
return window; return window;
} }
static bool windowScrolled(struct Window *window) {
return window->scroll < BufferCap;
}
static short colorPairs; static short colorPairs;
static void colorInit(void) { static void colorInit(void) {
@ -238,18 +243,27 @@ void uiInit(void) {
keypad(input, true); keypad(input, true);
nodelay(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); windows.active = windowFor(Network);
uiShow(); uiShow();
} }
void uiDraw(void) { void uiDraw(void) {
wnoutrefresh(status); wnoutrefresh(status);
int scrolled = windowScrolled(windows.active);
pnoutrefresh( pnoutrefresh(
windows.active->pad, windows.active->pad,
windows.active->scroll - WINDOW_LINES, 0, windows.active->scroll - WINDOW_LINES + scrolled, 0,
1, 0, 1, 0,
BOTTOM - 1, RIGHT BOTTOM - 1 - scrolled, RIGHT
); );
if (scrolled) {
touchwin(scrollBar);
wnoutrefresh(scrollBar);
}
int y, x; int y, x;
getyx(input, y, x); getyx(input, y, x);
pnoutrefresh( pnoutrefresh(
@ -368,10 +382,11 @@ static void statusUpdate(void) {
} }
static void unmark(struct Window *window) { static void unmark(struct Window *window) {
if (window->scroll < BufferCap) return; if (!windowScrolled(window)) {
window->heat = Cold; window->heat = Cold;
window->unread = 0; window->unread = 0;
window->mark = false; window->mark = false;
}
statusUpdate(); statusUpdate();
} }
@ -462,7 +477,7 @@ void uiWrite(size_t id, enum Heat heat, const time_t *src, const char *str) {
statusUpdate(); statusUpdate();
} }
lines += wordWrap(window->pad, str); lines += wordWrap(window->pad, str);
if (window->scroll < BufferCap) { if (windowScrolled(window)) {
windowScroll(window, -lines); windowScroll(window, -lines);
} }
if (heat > Warm) beep(); if (heat > Warm) beep();