From: Stefan Kangas Date: Wed, 27 Oct 2021 00:36:57 +0000 (+0200) Subject: image-dired: Use an evenly spaced grid for thumbnails X-Git-Tag: emacs-29.0.90~3671^2~401 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d22cd6d4c6a88894facbad9130200e86de22dd8a;p=emacs.git image-dired: Use an evenly spaced grid for thumbnails * lisp/image-dired.el (image-dired-line-up): Use an evenly spaced grid for thumbnails, even if image sizes differ. --- diff --git a/lisp/image-dired.el b/lisp/image-dired.el index b7650ba7725..b54404b0903 100644 --- a/lisp/image-dired.el +++ b/lisp/image-dired.el @@ -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 ()