1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-06-29 15:57:45 +02:00

allow groupchat sidebar to scroll

This commit is contained in:
Jfreegman 2013-12-03 03:44:02 -05:00
parent ba750753a5
commit 1a86327f9f
3 changed files with 31 additions and 13 deletions

View File

@ -256,7 +256,7 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
} }
} }
#define FLIST_OFST 3 /* Accounts for the three lines of text at top */ #define FLIST_OFST 3 /* Accounts for the three lines at top */
static void friendlist_onDraw(ToxWindow *self, Tox *m) static void friendlist_onDraw(ToxWindow *self, Tox *m)
{ {
@ -276,8 +276,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
wattroff(self->window, COLOR_PAIR(CYAN) | A_BOLD); wattroff(self->window, COLOR_PAIR(CYAN) | A_BOLD);
} }
if ((y2 - FLIST_OFST) <= 0) /* don't allow division by zero */
if ((y2 - FLIST_OFST) == 0) /* don't allow division by zero */
return; return;
/* Determine which portion of friendlist to draw based on current position */ /* Determine which portion of friendlist to draw based on current position */

View File

@ -85,6 +85,7 @@ static void print_groupchat_help(ChatContext *ctx)
wattron(ctx->history, A_BOLD); wattron(ctx->history, A_BOLD);
wprintw(ctx->history, "\n * Argument messages must be enclosed in quotation marks.\n"); wprintw(ctx->history, "\n * Argument messages must be enclosed in quotation marks.\n");
wprintw(ctx->history, " * Scroll peer list with the Page Up/Page Down keys.\n");
wattroff(ctx->history, A_BOLD); wattroff(ctx->history, A_BOLD);
wattroff(ctx->history, COLOR_PAIR(CYAN)); wattroff(ctx->history, COLOR_PAIR(CYAN));
@ -267,7 +268,22 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
else else
wmove(self->window, y, x+1); wmove(self->window, y, x+1);
} }
} else }
/* Scroll peerlist up and down one position if list overflows window */
else if (key == KEY_NPAGE) {
int L = y2 - CHATBOX_HEIGHT - SDBAR_OFST;
if (groupchats[self->num].side_pos < groupchats[self->num].num_peers - L)
++groupchats[self->num].side_pos;
}
else if (key == KEY_PPAGE) {
if (groupchats[self->num].side_pos > 0)
--groupchats[self->num].side_pos;
}
else
#if HAVE_WIDECHAR #if HAVE_WIDECHAR
if (iswprint(key)) if (iswprint(key))
#else #else
@ -336,18 +352,18 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
static void groupchat_onDraw(ToxWindow *self, Tox *m) static void groupchat_onDraw(ToxWindow *self, Tox *m)
{ {
curs_set(1); curs_set(1);
int x, y; int x2, y2;
getmaxyx(self->window, y, x); getmaxyx(self->window, y2, x2);
ChatContext *ctx = self->chatwin; ChatContext *ctx = self->chatwin;
wclear(ctx->linewin); wclear(ctx->linewin);
mvwprintw(ctx->linewin, 1, 0, "%s", wcs_to_char(ctx->line)); mvwprintw(ctx->linewin, 1, 0, "%s", wcs_to_char(ctx->line));
wclrtobot(ctx->sidebar); wclear(ctx->sidebar);
mvwhline(ctx->linewin, 0, 0, ACS_HLINE, x); mvwhline(ctx->linewin, 0, 0, ACS_HLINE, x2);
mvwvline(ctx->sidebar, 0, 0, ACS_VLINE, y-CHATBOX_HEIGHT); mvwvline(ctx->sidebar, 0, 0, ACS_VLINE, y2-CHATBOX_HEIGHT);
mvwaddch(ctx->sidebar, y-CHATBOX_HEIGHT, 0, ACS_BTEE); mvwaddch(ctx->sidebar, y2-CHATBOX_HEIGHT, 0, ACS_BTEE);
int num_peers = groupchats[self->num].num_peers; int num_peers = groupchats[self->num].num_peers;
@ -360,13 +376,14 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
mvwhline(ctx->sidebar, 1, 1, ACS_HLINE, SIDEBAR_WIDTH-1); mvwhline(ctx->sidebar, 1, 1, ACS_HLINE, SIDEBAR_WIDTH-1);
int N = TOX_MAX_NAME_LENGTH; int N = TOX_MAX_NAME_LENGTH;
int maxlines = y - CHATBOX_HEIGHT; int maxlines = y2 - SDBAR_OFST - CHATBOX_HEIGHT;
int i; int i;
for (i = 0; i < num_peers && i < maxlines; ++i) { for (i = 0; i < num_peers && i < maxlines; ++i) {
wmove(ctx->sidebar, i+2, 1); wmove(ctx->sidebar, i+2, 1);
groupchats[self->num].peer_names[i*N+SIDEBAR_WIDTH-2] = '\0'; int peer = i + groupchats[self->num].side_pos;
wprintw(ctx->sidebar, "%s\n", &groupchats[self->num].peer_names[i*N]); groupchats[self->num].peer_names[peer*N+SIDEBAR_WIDTH-2] = '\0';
wprintw(ctx->sidebar, "%s\n", &groupchats[self->num].peer_names[peer*N]);
} }
wrefresh(self->window); wrefresh(self->window);

View File

@ -3,11 +3,13 @@
*/ */
#define SIDEBAR_WIDTH 16 #define SIDEBAR_WIDTH 16
#define SDBAR_OFST 2 /* Offset for the peer number box at the top of the statusbar */
typedef struct { typedef struct {
int chatwin; int chatwin;
bool active; bool active;
int num_peers; int num_peers;
int side_pos; /* current position of the sidebar - used for scrolling up and down */
uint8_t *peer_names; uint8_t *peer_names;
uint8_t *oldpeer_names; uint8_t *oldpeer_names;
} GroupChat; } GroupChat;