Refactor notibox--get-position and add stack positions

This commit is contained in:
MitchMarq42 2023-08-11 19:37:10 -08:00
parent 06221a2462
commit 878eb11346

View File

@ -48,21 +48,32 @@
(defvar notibox-padding 30) (defvar notibox-padding 30)
(defvar alert-fade-time 5); seconds, also provided by `alert' package (defvar alert-fade-time 5); seconds, also provided by `alert' package
(defvar notibox--refresh-delay 0.1) ; seconds. Probably don't change this one. (defvar notibox--refresh-delay 0.1) ; seconds. Probably don't change this one.
(defun notibox--get-position () (defun notibox--get-position (&optional stackdepth)
"Return the starting coordinate at which to place the notibox, as cons." "Return the starting coordinate at which to place the next notibox, as cons.
(let* ((parent-width (frame-pixel-width))
If STACKDEPTH is non-nil and nonzero, return a position that far down."
(let* (
(stackdepth (or stackdepth 0))
(parent-width (frame-pixel-width))
(child-width (* notibox-width (shr-string-pixel-width " "))) (child-width (* notibox-width (shr-string-pixel-width " ")))
(parent-height (frame-pixel-height)) (parent-height (frame-pixel-height))
(child-height (* notibox-height (line-pixel-height)))) (child-height (* notibox-height (line-pixel-height)))
(pcase notibox-corner (padded-height (+ child-height notibox-padding))
('topleft (cons notibox-padding notibox-padding)) (x-justify (pcase notibox-corner
('topright (cons (- parent-width (+ child-width notibox-padding)) ((or 'topleft 'bottomleft) notibox-padding)
notibox-padding)) ((or 'topright 'bottomright)
('bottomleft (cons notibox-padding (- parent-width (+ child-width notibox-padding)))))
(- parent-height (+ child-height notibox-padding)))) (y-justify (pcase notibox-corner
('bottomright (cons ((or 'topleft 'topright) notibox-padding)
(- parent-width (+ child-width notibox-padding)) ((or 'bottomleft 'bottomright)
(- parent-height (+ child-height notibox-padding))))))) (- parent-height (+ child-height notibox-padding)))))
(y-direction (pcase notibox-corner
((or 'topleft 'topright) #'+)
((or 'bottomleft 'bottomright) #'-)))
(y-coord (funcall y-direction y-justify (* stackdepth child-height)))
)
(cons x-justify y-coord)
))
;; (notibox--get-position) ;; (notibox--get-position)
(defun notibox--prepare-buffer (title body) (defun notibox--prepare-buffer (title body)