Scroll the input pad

master
Curtis McEnroe 2018-08-04 16:02:43 -04:00
parent f8e5648a9a
commit ea23dcec3b
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
1 changed files with 15 additions and 7 deletions

22
ui.c
View File

@ -33,6 +33,8 @@
#define A_ITALIC A_NORMAL #define A_ITALIC A_NORMAL
#endif #endif
#define MAX(a, b) ((a) > (b) ? (a) : (b))
static const int TOPIC_COLS = 512; static const int TOPIC_COLS = 512;
static const int CHAT_LINES = 100; static const int CHAT_LINES = 100;
static const int INPUT_COLS = 512; static const int INPUT_COLS = 512;
@ -41,6 +43,7 @@ static struct {
WINDOW *topic; WINDOW *topic;
WINDOW *chat; WINDOW *chat;
WINDOW *input; WINDOW *input;
size_t cursor;
} ui; } ui;
void uiInit(void) { void uiInit(void) {
@ -70,7 +73,7 @@ void uiInit(void) {
ui.input = newpad(2, INPUT_COLS); ui.input = newpad(2, INPUT_COLS);
mvwhline(ui.input, 0, 0, ACS_HLINE, INPUT_COLS); mvwhline(ui.input, 0, 0, ACS_HLINE, INPUT_COLS);
wmove(ui.input, 1, 0); wmove(ui.input, 1, ui.cursor);
nodelay(ui.input, true); nodelay(ui.input, true);
} }
@ -84,17 +87,20 @@ void uiHide(void) {
} }
void uiDraw(void) { void uiDraw(void) {
pnoutrefresh(ui.topic, 0, 0, 0, 0, 1, COLS - 1); int lastCol = COLS - 1;
int lastLine = LINES - 1;
pnoutrefresh(ui.topic, 0, 0, 0, 0, 1, lastCol);
pnoutrefresh( pnoutrefresh(
ui.chat, ui.chat,
CHAT_LINES - (LINES - 4), 0, CHAT_LINES - (lastLine - 4), 0,
2, 0, LINES - 1, COLS - 1 2, 0, lastLine, lastCol
); );
pnoutrefresh( pnoutrefresh(
ui.input, ui.input,
0, 0, 0, MAX(0, ui.cursor - lastCol),
LINES - 2, 0, lastLine - 1, 0,
LINES - 1, COLS - 1 lastLine, lastCol
); );
doupdate(); doupdate();
} }
@ -213,6 +219,7 @@ void uiRead(void) {
len = 0; len = 0;
} }
break; default: { break; default: {
// TODO: Check overflow
if (iswprint(ch)) buf[len++] = ch; if (iswprint(ch)) buf[len++] = ch;
} }
} }
@ -220,4 +227,5 @@ void uiRead(void) {
wmove(ui.input, 1, 0); wmove(ui.input, 1, 0);
waddnwstr(ui.input, buf, len); waddnwstr(ui.input, buf, len);
wclrtoeol(ui.input); wclrtoeol(ui.input);
ui.cursor = len;
} }