fix: scrollbar position offset, dialog size clamp to terminal dimensions
This commit is contained in:
@@ -18,15 +18,17 @@
|
|||||||
(content :initarg :content :initform nil :accessor dialog-content)
|
(content :initarg :content :initform nil :accessor dialog-content)
|
||||||
(on-dismiss :initarg :on-dismiss :initform nil :accessor dialog-on-dismiss)))
|
(on-dismiss :initarg :on-dismiss :initform nil :accessor dialog-on-dismiss)))
|
||||||
|
|
||||||
(defun dialog-size-pixels (size)
|
(defun dialog-size-pixels (size &optional (max-w 80) (max-h 24))
|
||||||
|
(multiple-value-bind (dw dh)
|
||||||
(case size
|
(case size
|
||||||
(:small (values 40 8))
|
(:small (values 40 8))
|
||||||
(:medium (values 60 16))
|
(:medium (values 60 16))
|
||||||
(:large (values 88 24))
|
(:large (values 88 24))
|
||||||
(t (values 60 16))))
|
(t (values 60 16)))
|
||||||
|
(values (min dw max-w) (min dh max-h))))
|
||||||
|
|
||||||
(defun render-dialog (dialog screen w h)
|
(defun render-dialog (dialog screen w h)
|
||||||
(multiple-value-bind (dw dh) (dialog-size-pixels (dialog-size dialog))
|
(multiple-value-bind (dw dh) (dialog-size-pixels (dialog-size dialog) w h)
|
||||||
(let ((x (floor (- w dw) 2))
|
(let ((x (floor (- w dw) 2))
|
||||||
(y (floor (- h dh) 2)))
|
(y (floor (- h dh) 2)))
|
||||||
;; Backdrop — dim the full screen
|
;; Backdrop — dim the full screen
|
||||||
|
|||||||
@@ -74,17 +74,20 @@ Children outside the viewport are skipped."
|
|||||||
|
|
||||||
(defun draw-scrollbars (sb backend viewport-w viewport-h)
|
(defun draw-scrollbars (sb backend viewport-w viewport-h)
|
||||||
(let* ((content-h (scroll-box-content-height sb)) (content-w (scroll-box-content-width sb))
|
(let* ((content-h (scroll-box-content-height sb)) (content-w (scroll-box-content-width sb))
|
||||||
(sy (scroll-box-scroll-y sb)) (sx (scroll-box-scroll-x sb)))
|
(sy (scroll-box-scroll-y sb)) (sx (scroll-box-scroll-x sb))
|
||||||
|
(ln (scroll-box-layout-node sb))
|
||||||
|
(ox (if ln (layout-node-x ln) 0))
|
||||||
|
(oy (if ln (layout-node-y ln) 0)))
|
||||||
(when (> content-h viewport-h)
|
(when (> content-h viewport-h)
|
||||||
(let* ((thumb (scrollbar-thumb sy viewport-h content-h))
|
(let* ((thumb (scrollbar-thumb sy viewport-h content-h))
|
||||||
(thumb-pos (round (* thumb viewport-h))))
|
(thumb-pos (round (* thumb viewport-h))))
|
||||||
(draw-rect backend (1- viewport-w) 0 1 viewport-h :bg :bright-black)
|
(draw-rect backend (+ ox (1- viewport-w)) oy 1 viewport-h :bg :bright-black)
|
||||||
(draw-text backend (1- viewport-w) thumb-pos "█" nil nil)))
|
(draw-text backend (+ ox (1- viewport-w)) (+ oy thumb-pos) "█" nil nil)))
|
||||||
(when (> content-w viewport-w)
|
(when (> content-w viewport-w)
|
||||||
(let* ((thumb (scrollbar-thumb sx viewport-w content-w))
|
(let* ((thumb (scrollbar-thumb sx viewport-w content-w))
|
||||||
(thumb-pos (round (* thumb viewport-w))))
|
(thumb-pos (round (* thumb viewport-w))))
|
||||||
(draw-rect backend 0 (1- viewport-h) viewport-w 1 :bg :bright-black)
|
(draw-rect backend ox (+ oy (1- viewport-h)) viewport-w 1 :bg :bright-black)
|
||||||
(draw-text backend thumb-pos (1- viewport-h) "█" nil nil)))))
|
(draw-text backend (+ ox thumb-pos) (+ oy (1- viewport-h)) "█" nil nil)))))
|
||||||
|
|
||||||
(defun update-sticky-scroll (sb)
|
(defun update-sticky-scroll (sb)
|
||||||
(when (sticky-scroll-p sb)
|
(when (sticky-scroll-p sb)
|
||||||
|
|||||||
Reference in New Issue
Block a user