Krolyxon
Commit c6726ed

Branches

Refs →

nsxivc6726ed

Nicer tns_move_selection

Author
Bert
Date
2011-02-18 15:33 +0100
Parent
62f4ab0
Commit
c6726ed331ed1fbe72fd28f48ebe41c4ccd721e0

+17 −20

2 files changed

  1. M thumbs.c +17 −19
  2. M thumbs.h +0 −1
M thumbs.c View
@@ -32,8 +32,9 @@ void tns_init(tns_t *tns, int cnt) {
3232 if (!tns)
3333 return;
3434
35− tns->cnt = tns->first = tns->sel = tns->vis = 0;
35+ tns->cnt = tns->first = tns->sel = 0;
3636 tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t));
37+ memset(tns->thumbs, 0, cnt * sizeof(thumb_t));
3738 }
3839
3940 void tns_free(tns_t *tns, win_t *win) {
@@ -115,7 +116,6 @@ void tns_render(tns_t *tns, win_t *win) {
115116 x += thumb_dim;
116117 }
117118 }
118− tns->vis = i - tns->first;
119119
120120 tns_highlight(tns, win, -1);
121121 }
@@ -139,7 +139,7 @@ void tns_highlight(tns_t *tns, win_t *win, int old) {
139139 }
140140
141141 void tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
142− int sel;
142+ int sel, old;
143143
144144 if (!tns || !win)
145145 return;
@@ -148,30 +148,28 @@ void tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
148148
149149 switch (dir) {
150150 case MOVE_LEFT:
151− if (sel % tns->cols > 0) {
152− --tns->sel;
153− tns_highlight(tns, win, sel);
154− }
151+ if (sel % tns->cols > 0)
152+ --sel;
155153 break;
156154 case MOVE_RIGHT:
157− if (sel % tns->cols < tns->cols - 1 && sel < tns->cnt - 1) {
158− ++tns->sel;
159− tns_highlight(tns, win, sel);
160− }
155+ if (sel % tns->cols < tns->cols - 1 && sel < tns->cnt - 1)
156+ ++sel;
161157 break;
162158 case MOVE_UP:
163− if (sel / tns->cols > 0) {
164− tns->sel -= tns->cols;
165− tns_highlight(tns, win, sel);
166− }
159+ if (sel / tns->cols > 0)
160+ sel -= tns->cols;
167161 break;
168162 case MOVE_DOWN:
169− if (sel / tns->cols < tns->rows - 1 && sel + tns->cols < tns->vis) {
170− tns->sel += tns->cols;
171− tns_highlight(tns, win, sel);
172− }
163+ if (sel / tns->cols < tns->rows - 1 && sel + tns->cols < tns->cnt)
164+ sel += tns->cols;
173165 break;
174166 }
167+
168+ if (sel != tns->sel && tns->thumbs[sel].x != 0) {
169+ old = tns->sel;
170+ tns->sel = sel;
171+ tns_highlight(tns, win, old);
172+ }
175173 }
176174
177175 int tns_translate(tns_t *tns, int x, int y) {
M thumbs.h View
@@ -45,7 +45,6 @@ typedef struct tns_s {
4545 int rows;
4646 int first;
4747 int sel;
48− int vis;
4948 } tns_t;
5049
5150 void tns_init(tns_t*, int);