]> git.eshelyaron.com Git - emacs.git/commitdiff
image-dired: Use an evenly spaced grid for thumbnails
authorStefan Kangas <stefan@marxist.se>
Wed, 27 Oct 2021 00:36:57 +0000 (02:36 +0200)
committerStefan Kangas <stefan@marxist.se>
Wed, 27 Oct 2021 00:57:51 +0000 (02:57 +0200)
* lisp/image-dired.el (image-dired-line-up): Use an evenly spaced
grid for thumbnails, even if image sizes differ.

lisp/image-dired.el

index b7650ba7725ee391762ed916f76018f9b06db986..b54404b09031cd733573b0d82af7ae9aea058c10 100644 (file)
@@ -1884,18 +1884,26 @@ See also `image-dired-line-up-dynamic'."
                   (not (eobp)))
         (delete-char 1)))
     (goto-char (point-min))
-    (let ((count 0))
+    (let ((seen 0)
+          (thumb-prev-pos 0)
+          (thumb-width-chars
+           (ceiling (/ (+ (* 2 image-dired-thumb-relief)
+                          (* 2 image-dired-thumb-margin)
+                          (image-dired-thumb-size 'width))
+                       (float (frame-char-width))))))
       (while (not (eobp))
         (forward-char)
         (if (= image-dired-thumbs-per-row 1)
             (insert "\n")
-          (insert " ")
-          (setq count (1+ count))
-          (when (and (= count (- image-dired-thumbs-per-row 1))
+          (cl-incf thumb-prev-pos thumb-width-chars)
+          (insert (propertize " " 'display `(space :align-to ,thumb-prev-pos)))
+          (cl-incf seen)
+          (when (and (= seen (- image-dired-thumbs-per-row 1))
                     (not (eobp)))
             (forward-char)
             (insert "\n")
-            (setq count 0)))))
+            (setq seen 0)
+            (setq thumb-prev-pos 0)))))
     (goto-char (point-min))))
 
 (defun image-dired-line-up-dynamic ()