From b38436038b799d560ae5c9034c23fda48dff130a Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Tue, 12 May 2026 14:03:12 +0000 Subject: [PATCH] fix: scrollbar position offset, dialog size clamp to terminal dimensions --- src/components/dialog.lisp | 16 +++++++++------- src/components/scrollbox.lisp | 13 ++++++++----- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/components/dialog.lisp b/src/components/dialog.lisp index fc5a8b1..c375d5c 100644 --- a/src/components/dialog.lisp +++ b/src/components/dialog.lisp @@ -18,15 +18,17 @@ (content :initarg :content :initform nil :accessor dialog-content) (on-dismiss :initarg :on-dismiss :initform nil :accessor dialog-on-dismiss))) -(defun dialog-size-pixels (size) - (case size - (:small (values 40 8)) - (:medium (values 60 16)) - (:large (values 88 24)) - (t (values 60 16)))) +(defun dialog-size-pixels (size &optional (max-w 80) (max-h 24)) + (multiple-value-bind (dw dh) + (case size + (:small (values 40 8)) + (:medium (values 60 16)) + (:large (values 88 24)) + (t (values 60 16))) + (values (min dw max-w) (min dh max-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)) (y (floor (- h dh) 2))) ;; Backdrop — dim the full screen diff --git a/src/components/scrollbox.lisp b/src/components/scrollbox.lisp index 801ae6c..9f04810 100644 --- a/src/components/scrollbox.lisp +++ b/src/components/scrollbox.lisp @@ -74,17 +74,20 @@ Children outside the viewport are skipped." (defun draw-scrollbars (sb backend viewport-w viewport-h) (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) (let* ((thumb (scrollbar-thumb sy viewport-h content-h)) (thumb-pos (round (* thumb viewport-h)))) - (draw-rect backend (1- viewport-w) 0 1 viewport-h :bg :bright-black) - (draw-text backend (1- viewport-w) thumb-pos "█" nil nil))) + (draw-rect backend (+ ox (1- viewport-w)) oy 1 viewport-h :bg :bright-black) + (draw-text backend (+ ox (1- viewport-w)) (+ oy thumb-pos) "█" nil nil))) (when (> content-w viewport-w) (let* ((thumb (scrollbar-thumb sx viewport-w content-w)) (thumb-pos (round (* thumb viewport-w)))) - (draw-rect backend 0 (1- viewport-h) viewport-w 1 :bg :bright-black) - (draw-text backend thumb-pos (1- viewport-h) "█" nil nil))))) + (draw-rect backend ox (+ oy (1- viewport-h)) viewport-w 1 :bg :bright-black) + (draw-text backend (+ ox thumb-pos) (+ oy (1- viewport-h)) "█" nil nil))))) (defun update-sticky-scroll (sb) (when (sticky-scroll-p sb)