Nicer tns_move_selection

This commit is contained in:
Bert 2011-02-18 15:33:52 +01:00
parent 62f4ab037a
commit c6726ed331
2 changed files with 17 additions and 20 deletions

View File

@ -32,8 +32,9 @@ void tns_init(tns_t *tns, int cnt) {
if (!tns) if (!tns)
return; return;
tns->cnt = tns->first = tns->sel = tns->vis = 0; tns->cnt = tns->first = tns->sel = 0;
tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t)); tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t));
memset(tns->thumbs, 0, cnt * sizeof(thumb_t));
} }
void tns_free(tns_t *tns, win_t *win) { void tns_free(tns_t *tns, win_t *win) {
@ -115,7 +116,6 @@ void tns_render(tns_t *tns, win_t *win) {
x += thumb_dim; x += thumb_dim;
} }
} }
tns->vis = i - tns->first;
tns_highlight(tns, win, -1); tns_highlight(tns, win, -1);
} }
@ -139,7 +139,7 @@ void tns_highlight(tns_t *tns, win_t *win, int old) {
} }
void tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) { void tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
int sel; int sel, old;
if (!tns || !win) if (!tns || !win)
return; return;
@ -148,30 +148,28 @@ void tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
switch (dir) { switch (dir) {
case MOVE_LEFT: case MOVE_LEFT:
if (sel % tns->cols > 0) { if (sel % tns->cols > 0)
--tns->sel; --sel;
tns_highlight(tns, win, sel);
}
break; break;
case MOVE_RIGHT: case MOVE_RIGHT:
if (sel % tns->cols < tns->cols - 1 && sel < tns->cnt - 1) { if (sel % tns->cols < tns->cols - 1 && sel < tns->cnt - 1)
++tns->sel; ++sel;
tns_highlight(tns, win, sel);
}
break; break;
case MOVE_UP: case MOVE_UP:
if (sel / tns->cols > 0) { if (sel / tns->cols > 0)
tns->sel -= tns->cols; sel -= tns->cols;
tns_highlight(tns, win, sel);
}
break; break;
case MOVE_DOWN: case MOVE_DOWN:
if (sel / tns->cols < tns->rows - 1 && sel + tns->cols < tns->vis) { if (sel / tns->cols < tns->rows - 1 && sel + tns->cols < tns->cnt)
tns->sel += tns->cols; sel += tns->cols;
tns_highlight(tns, win, sel);
}
break; break;
} }
if (sel != tns->sel && tns->thumbs[sel].x != 0) {
old = tns->sel;
tns->sel = sel;
tns_highlight(tns, win, old);
}
} }
int tns_translate(tns_t *tns, int x, int y) { int tns_translate(tns_t *tns, int x, int y) {

View File

@ -45,7 +45,6 @@ typedef struct tns_s {
int rows; int rows;
int first; int first;
int sel; int sel;
int vis;
} tns_t; } tns_t;
void tns_init(tns_t*, int); void tns_init(tns_t*, int);