| @@ -98,7 +98,9 @@ void tns_render(tns_t *tns, win_t *win) { |
| 98 | 98 | | |
| 99 | 99 | | win_clear(win); |
| 100 | 100 | | |
| 101 | | − | x = y = 5; |
| 101 | + | i = cnt % tns->cols ? 1 : 0; |
| 102 | + | tns->x = x = (win->w - MIN(cnt, tns->cols) * thumb_dim) / 2 + 5; |
| 103 | + | tns->y = y = (win->h - (cnt / tns->cols + i) * thumb_dim) / 2 + 5; |
| 102 | 104 | | i = tns->first; |
| 103 | 105 | | |
| 104 | 106 | | while (i < cnt) { |
| @@ -107,13 +109,14 @@ void tns_render(tns_t *tns, win_t *win) { |
| 107 | 109 | | win_draw_pixmap(win, tns->thumbs[i].pm, tns->thumbs[i].x, |
| 108 | 110 | | tns->thumbs[i].y, tns->thumbs[i].w, tns->thumbs[i].h); |
| 109 | 111 | | if (++i % tns->cols == 0) { |
| 110 | | − | x = 5; |
| 112 | + | x = tns->x; |
| 111 | 113 | | y += thumb_dim; |
| 112 | 114 | | } else { |
| 113 | 115 | | x += thumb_dim; |
| 114 | 116 | | } |
| 115 | 117 | | } |
| 116 | 118 | | |
| 119 | + | printf("%d, %d\n", tns->sel, tns->cnt); |
| 117 | 120 | | tns_highlight(tns, win, -1); |
| 118 | 121 | | } |
| 119 | 122 | | |
| @@ -175,10 +178,10 @@ int tns_translate(tns_t *tns, int x, int y) { |
| 175 | 178 | | int n; |
| 176 | 179 | | thumb_t *t; |
| 177 | 180 | | |
| 178 | | − | if (!tns || x < 5 || y < 5) |
| 181 | + | if (!tns || x < tns->x || y < tns->y) |
| 179 | 182 | | return -1; |
| 180 | 183 | | |
| 181 | | − | if ((n = y / thumb_dim * tns-> cols + x / thumb_dim) < tns->cnt) { |
| 184 | + | if ((n = (y - tns->y) / thumb_dim * tns->cols + (x - tns->x) / thumb_dim) < tns->cnt) { |
| 182 | 185 | | t = &tns->thumbs[n]; |
| 183 | 186 | | if (x > t->x && x < t->x + t->w && y > t->y && y < t->y + t->h) |
| 184 | 187 | | return n; |