Add The Scroll Bar

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

23
ui.c
View File

@ -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;
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();