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)))
 | 
			
		||||
    (/ (max 0 (- window-height content-height)) (* 2 line-height))))
 | 
			
		||||
 | 
			
		||||
(defun center-content--enable ()
 | 
			
		||||
  "Enable horizontal and vertical centering of content."
 | 
			
		||||
  (let* ((content-size (center-content--content-pixel-size))
 | 
			
		||||
         (left-margin (center-content--calculate-left-margin (car content-size)))
 | 
			
		||||
         (top-margin (center-content--calculate-top-margin (cdr content-size))))
 | 
			
		||||
    ;; Apply horizontal centering using overlay
 | 
			
		||||
    (let ((overlay (make-overlay (point-min) (point-max)))
 | 
			
		||||
          (space (propertize " " 'display `(space :width ,left-margin))))
 | 
			
		||||
      (overlay-put overlay 'line-prefix space)
 | 
			
		||||
      (setq center-content--horizontal-overlay overlay))
 | 
			
		||||
    ;; Apply vertical centering using header-line-format
 | 
			
		||||
(defun center-content--horizontal (content-width)
 | 
			
		||||
  "Add overlay for horizontal centering relative to CONTENT-WIDTH."
 | 
			
		||||
  (let* ((left-margin (center-content--calculate-left-margin content-width))
 | 
			
		||||
         (overlay (make-overlay (point-min) (point-max)))
 | 
			
		||||
         (space (propertize " " 'display `(space :width ,left-margin))))
 | 
			
		||||
    (overlay-put overlay 'line-prefix space)
 | 
			
		||||
    (setq center-content--horizontal-overlay overlay)))
 | 
			
		||||
 | 
			
		||||
(defun center-content--vertical (content-height)
 | 
			
		||||
  "Add overlay for vertical centering relative to CONTENT-HEIGHT."
 | 
			
		||||
  (let* ((top-margin (center-content--calculate-top-margin content-height)))
 | 
			
		||||
    ;; 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--header-line-face-remap-cookie
 | 
			
		||||
          (face-remap-add-relative 'header-line 'default))
 | 
			
		||||
    (setq header-line-format (propertize " " 'display `(height ,top-margin)))
 | 
			
		||||
    ;; Save and hide the mode line
 | 
			
		||||
    (setq header-line-format (propertize " " 'display `(height ,top-margin)))))
 | 
			
		||||
 | 
			
		||||
(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 mode-line-format nil)
 | 
			
		||||
    ;; Force redisplay
 | 
			
		||||
    (force-mode-line-update)
 | 
			
		||||
    (redisplay)))
 | 
			
		||||
    (setq mode-line-format nil)))
 | 
			
		||||
 | 
			
		||||
(defun center-content--disable ()
 | 
			
		||||
  "Disable centering of content."
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user