| @@ -88,21 +88,27 @@ void tns_load(tns_t *tns, win_t *win, const char *filename) { |
| 88 | 88 | | } |
| 89 | 89 | | |
| 90 | 90 | | void tns_check_view(tns_t *tns, Bool scrolled) { |
| 91 | + | int r; |
| 92 | + | |
| 91 | 93 | | if (!tns) |
| 92 | 94 | | return; |
| 93 | 95 | | |
| 94 | 96 | | tns->first -= tns->first % tns->cols; |
| 97 | + | r = fileidx % tns->cols; |
| 95 | 98 | | |
| 96 | 99 | | if (scrolled) { |
| 97 | 100 | | /* move selection into visible area */ |
| 101 | + | if (fileidx >= tns->first + tns->cols * tns->rows) |
| 102 | + | fileidx = tns->first + r + tns->cols * (tns->rows - 1); |
| 103 | + | else if (fileidx < tns->first) |
| 104 | + | fileidx = tns->first + r; |
| 98 | 105 | | } else { |
| 99 | 106 | | /* scroll to selection */ |
| 100 | 107 | | if (tns->first + tns->cols * tns->rows <= fileidx) { |
| 101 | | − | tns->first = fileidx - fileidx % tns->cols - |
| 102 | | − | tns->cols * (tns->rows - 1); |
| 108 | + | tns->first = fileidx - r - tns->cols * (tns->rows - 1); |
| 103 | 109 | | tns->dirty = 1; |
| 104 | 110 | | } else if (tns->first > fileidx) { |
| 105 | | − | tns->first = fileidx - fileidx % tns->cols; |
| 111 | + | tns->first = fileidx - r; |
| 106 | 112 | | tns->dirty = 1; |
| 107 | 113 | | } |
| 108 | 114 | | } |
| @@ -167,7 +173,7 @@ void tns_highlight(tns_t *tns, win_t *win, int n, Bool hl) { |
| 167 | 173 | | win_draw(win); |
| 168 | 174 | | } |
| 169 | 175 | | |
| 170 | | − | int tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) { |
| 176 | + | int tns_move_selection(tns_t *tns, win_t *win, tnsdir_t dir) { |
| 171 | 177 | | int old; |
| 172 | 178 | | |
| 173 | 179 | | if (!tns || !win) |
| @@ -176,19 +182,19 @@ int tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) { |
| 176 | 182 | | old = fileidx; |
| 177 | 183 | | |
| 178 | 184 | | switch (dir) { |
| 179 | | − | case MOVE_LEFT: |
| 185 | + | case TNS_LEFT: |
| 180 | 186 | | if (fileidx > 0) |
| 181 | 187 | | --fileidx; |
| 182 | 188 | | break; |
| 183 | | − | case MOVE_RIGHT: |
| 189 | + | case TNS_RIGHT: |
| 184 | 190 | | if (fileidx < tns->cnt - 1) |
| 185 | 191 | | ++fileidx; |
| 186 | 192 | | break; |
| 187 | | − | case MOVE_UP: |
| 193 | + | case TNS_UP: |
| 188 | 194 | | if (fileidx >= tns->cols) |
| 189 | 195 | | fileidx -= tns->cols; |
| 190 | 196 | | break; |
| 191 | | − | case MOVE_DOWN: |
| 197 | + | case TNS_DOWN: |
| 192 | 198 | | if (fileidx + tns->cols < tns->cnt) |
| 193 | 199 | | fileidx += tns->cols; |
| 194 | 200 | | break; |
| @@ -204,6 +210,28 @@ int tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) { |
| 204 | 210 | | return fileidx != old; |
| 205 | 211 | | } |
| 206 | 212 | | |
| 213 | + | int tns_scroll(tns_t *tns, tnsdir_t dir) { |
| 214 | + | int old; |
| 215 | + | |
| 216 | + | if (!tns) |
| 217 | + | return 0; |
| 218 | + | |
| 219 | + | old = tns->first; |
| 220 | + | |
| 221 | + | if (dir == TNS_DOWN && tns->first + tns->cols * tns->rows < tns->cnt) |
| 222 | + | tns->first += tns->cols; |
| 223 | + | else if (dir == TNS_UP && tns->first >= tns->cols) |
| 224 | + | tns->first -= tns->cols; |
| 225 | + | |
| 226 | + | if (tns->first != old) { |
| 227 | + | tns_check_view(tns, True); |
| 228 | + | tns->dirty = 1; |
| 229 | + | return 1; |
| 230 | + | } else { |
| 231 | + | return 0; |
| 232 | + | } |
| 233 | + | } |
| 234 | + | |
| 207 | 235 | | int tns_translate(tns_t *tns, int x, int y) { |
| 208 | 236 | | int n; |
| 209 | 237 | | thumb_t *t; |