Split into horizontal and vertical centering
Also remove forcibly redisplaing. Not sure it's necessary, so let's wait and see if things break.
This commit is contained in:
parent
d8551328f0
commit
1db2c7bff6
@ -37,28 +37,30 @@
|
|||||||
(line-height (default-line-height)))
|
(line-height (default-line-height)))
|
||||||
(/ (max 0 (- window-height content-height)) (* 2 line-height))))
|
(/ (max 0 (- window-height content-height)) (* 2 line-height))))
|
||||||
|
|
||||||
(defun center-content--enable ()
|
(defun center-content--horizontal (content-width)
|
||||||
"Enable horizontal and vertical centering of content."
|
"Add overlay for horizontal centering relative to CONTENT-WIDTH."
|
||||||
(let* ((content-size (center-content--content-pixel-size))
|
(let* ((left-margin (center-content--calculate-left-margin content-width))
|
||||||
(left-margin (center-content--calculate-left-margin (car content-size)))
|
(overlay (make-overlay (point-min) (point-max)))
|
||||||
(top-margin (center-content--calculate-top-margin (cdr content-size))))
|
(space (propertize " " 'display `(space :width ,left-margin))))
|
||||||
;; Apply horizontal centering using overlay
|
(overlay-put overlay 'line-prefix space)
|
||||||
(let ((overlay (make-overlay (point-min) (point-max)))
|
(setq center-content--horizontal-overlay overlay)))
|
||||||
(space (propertize " " 'display `(space :width ,left-margin))))
|
|
||||||
(overlay-put overlay 'line-prefix space)
|
(defun center-content--vertical (content-height)
|
||||||
(setq center-content--horizontal-overlay overlay))
|
"Add overlay for vertical centering relative to CONTENT-HEIGHT."
|
||||||
;; Apply vertical centering using header-line-format
|
(let* ((top-margin (center-content--calculate-top-margin content-height)))
|
||||||
;; Save and remap the header-line face to match the default face
|
;; Save and remap the header-line face to match the default face
|
||||||
(setq center-content--original-header-line-format header-line-format)
|
(setq center-content--original-header-line-format header-line-format)
|
||||||
(setq center-content--header-line-face-remap-cookie
|
(setq center-content--header-line-face-remap-cookie
|
||||||
(face-remap-add-relative 'header-line 'default))
|
(face-remap-add-relative 'header-line 'default))
|
||||||
(setq header-line-format (propertize " " 'display `(height ,top-margin)))
|
(setq header-line-format (propertize " " 'display `(height ,top-margin)))))
|
||||||
;; Save and hide the mode line
|
|
||||||
|
(defun center-content--enable ()
|
||||||
|
"Enable horizontal and vertical centering of content."
|
||||||
|
(let* ((content-size (center-content--content-pixel-size)))
|
||||||
|
(center-content--horizontal (car content-size))
|
||||||
|
(center-content--vertical (cdr content-size))
|
||||||
(setq center-content--original-mode-line-format mode-line-format)
|
(setq center-content--original-mode-line-format mode-line-format)
|
||||||
(setq mode-line-format nil)
|
(setq mode-line-format nil)))
|
||||||
;; Force redisplay
|
|
||||||
(force-mode-line-update)
|
|
||||||
(redisplay)))
|
|
||||||
|
|
||||||
(defun center-content--disable ()
|
(defun center-content--disable ()
|
||||||
"Disable centering of content."
|
"Disable centering of content."
|
||||||
|
Loading…
Reference in New Issue
Block a user