Krolyxon
Commit 73a9279

Branches

Refs →

nsxiv73a9279

Center humbnails in window

Author
Bert
Date
2011-02-18 14:57 +0100
Parent
76cca4e
Commit
73a92795982d1c0896217caabcd48335c3ed9d63

+10 −5

3 files changed

  1. M Makefile +1 −1
  2. M thumbs.c +7 −4
  3. M thumbs.h +2 −0
M Makefile View
@@ -1,6 +1,6 @@
11 all: sxiv
22
3−VERSION=git-20110217
3+VERSION=git-20110218
44
55 CC?=gcc
66 PREFIX?=/usr/local
M thumbs.c View
@@ -98,7 +98,9 @@ void tns_render(tns_t *tns, win_t *win) {
9898
9999 win_clear(win);
100100
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;
102104 i = tns->first;
103105
104106 while (i < cnt) {
@@ -107,13 +109,14 @@ void tns_render(tns_t *tns, win_t *win) {
107109 win_draw_pixmap(win, tns->thumbs[i].pm, tns->thumbs[i].x,
108110 tns->thumbs[i].y, tns->thumbs[i].w, tns->thumbs[i].h);
109111 if (++i % tns->cols == 0) {
110− x = 5;
112+ x = tns->x;
111113 y += thumb_dim;
112114 } else {
113115 x += thumb_dim;
114116 }
115117 }
116118
119+ printf("%d, %d\n", tns->sel, tns->cnt);
117120 tns_highlight(tns, win, -1);
118121 }
119122
@@ -175,10 +178,10 @@ int tns_translate(tns_t *tns, int x, int y) {
175178 int n;
176179 thumb_t *t;
177180
178− if (!tns || x < 5 || y < 5)
181+ if (!tns || x < tns->x || y < tns->y)
179182 return -1;
180183
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) {
182185 t = &tns->thumbs[n];
183186 if (x > t->x && x < t->x + t->w && y > t->y && y < t->y + t->h)
184187 return n;
M thumbs.h View
@@ -39,6 +39,8 @@ typedef struct thumb_s {
3939 typedef struct tns_s {
4040 thumb_t *thumbs;
4141 int cnt;
42+ int x;
43+ int y;
4244 int cols;
4345 int rows;
4446 int first;