mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-16 02:53:03 +01:00
allow friendlist to scroll up and down if friends overflow the window
This commit is contained in:
parent
81c48f7b2b
commit
7a89229375
@ -335,7 +335,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
#endif
|
||||
{ /* prevents buffer overflows and strange behaviour when cursor goes past the window */
|
||||
if ( (ctx->len < MAX_STR_SIZE-1) && (ctx->len < (x2 * (CHATBOX_HEIGHT - 1)-1)) ) {
|
||||
add_char_to_buf(key, ctx->line, &ctx->pos, &ctx->len);
|
||||
add_char_to_buf(ctx->line, &ctx->pos, &ctx->len, key);
|
||||
|
||||
if (x == x2-1)
|
||||
wmove(self->window, y+1, 0);
|
||||
|
@ -256,14 +256,16 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
}
|
||||
}
|
||||
|
||||
#define FLIST_OFST 3 /* Accounts for the three lines of text at top */
|
||||
|
||||
static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
{
|
||||
curs_set(0);
|
||||
werase(self->window);
|
||||
int x, y;
|
||||
getmaxyx(self->window, y, x);
|
||||
int x2, y2;
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
bool fix_statuses = x != self->x; /* true if window x axis has changed */
|
||||
bool fix_statuses = x2 != self->x; /* true if window x axis has changed */
|
||||
|
||||
if (num_friends == 0) {
|
||||
wprintw(self->window, "Empty. Add some friends! :-)\n");
|
||||
@ -274,9 +276,14 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
wattroff(self->window, COLOR_PAIR(CYAN) | A_BOLD);
|
||||
}
|
||||
|
||||
/* Determine which portion of friendlist to draw based on current position */
|
||||
int page = num_selected / (y2 - FLIST_OFST);
|
||||
int start = (y2 - FLIST_OFST) * page;
|
||||
int end = y2 - FLIST_OFST + start;
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_friends && i < y-3; ++i) {
|
||||
for (i = start; i < num_friends && i < end; ++i) {
|
||||
int f = friendlist_index[i];
|
||||
bool f_selected = false;
|
||||
|
||||
@ -329,7 +336,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
}
|
||||
|
||||
/* Truncate note if it doesn't fit on one line */
|
||||
uint16_t maxlen = x - getcurx(self->window) - 4;
|
||||
uint16_t maxlen = x2 - getcurx(self->window) - 4;
|
||||
if (friends[f].statusmsg_len > maxlen) {
|
||||
friends[f].statusmsg[maxlen-3] = '\0';
|
||||
strcat(friends[f].statusmsg, "...");
|
||||
@ -352,7 +359,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
}
|
||||
}
|
||||
|
||||
self->x = x;
|
||||
self->x = x2;
|
||||
wrefresh(self->window);
|
||||
}
|
||||
|
||||
|
@ -275,7 +275,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
#endif
|
||||
{ /* prevents buffer overflows and strange behaviour when cursor goes past the window */
|
||||
if ( (ctx->len < MAX_STR_SIZE-1) && (ctx->len < (x2 * (CHATBOX_HEIGHT - 1)-1)) ) {
|
||||
add_char_to_buf(key, ctx->line, &ctx->pos, &ctx->len);
|
||||
add_char_to_buf(ctx->line, &ctx->pos, &ctx->len, key);
|
||||
|
||||
if (x == x2-1)
|
||||
wmove(self->window, y+1, 0);
|
||||
|
@ -166,7 +166,7 @@ bool valid_nick(uint8_t *nick)
|
||||
*/
|
||||
|
||||
/* Adds char to buffer at pos */
|
||||
void add_char_to_buf(wint_t ch, wchar_t *buf, size_t *pos, size_t *len)
|
||||
void add_char_to_buf(wchar_t *buf, size_t *pos, size_t *len, wint_t ch)
|
||||
{
|
||||
if (*pos < 0 || *len >= MAX_STR_SIZE)
|
||||
return;
|
||||
@ -197,7 +197,7 @@ void del_char_buf_bck(wchar_t *buf, size_t *pos, size_t *len)
|
||||
--(*len);
|
||||
}
|
||||
|
||||
/* Deletes the character at pos */
|
||||
/* Deletes the character after pos */
|
||||
void del_char_buf_frnt(wchar_t *buf, size_t *pos, size_t *len)
|
||||
{
|
||||
if (*pos < 0 || *pos >= *len)
|
||||
|
@ -42,12 +42,12 @@ bool valid_nick(uint8_t *nick);
|
||||
*/
|
||||
|
||||
/* Adds char to buffer at pos */
|
||||
void add_char_to_buf(wint_t ch, wchar_t *buf, size_t *pos, size_t *len);
|
||||
void add_char_to_buf(wchar_t *buf, size_t *pos, size_t *len, wint_t ch);
|
||||
|
||||
/* Deletes the character before pos */
|
||||
void del_char_buf_bck(wchar_t *buf, size_t *pos, size_t *len);
|
||||
|
||||
/* Deletes the character at pos */
|
||||
/* Deletes the character after pos */
|
||||
void del_char_buf_frnt(wchar_t *buf, size_t *pos, size_t *len);
|
||||
|
||||
/* nulls buf and sets pos and len to 0 */
|
||||
|
Loading…
Reference in New Issue
Block a user