From bfef45f7659e602d74fbca372010949b4701a5e8 Mon Sep 17 00:00:00 2001 From: Kinneyzhang Date: Wed, 5 Aug 2026 20:42:58 +0800 Subject: [PATCH] fix: size grid auto rows after item width resolution Render auto-width grid children at their resolved track widths before resolving row heights. This keeps wrapped content visible and prevents stale intrinsic heights from clipping the final line. Verification: make grid-tests EMACS=/Applications/Emacs.app/Contents/MacOS/Emacs; make compile EMACS=/Applications/Emacs.app/Contents/MacOS/Emacs; make check EMACS=/Applications/Emacs.app/Contents/MacOS/Emacs. --- ebox-grid.el | 23 +++++++++++++++++++---- tests/ebox-grid-tests.el | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/ebox-grid.el b/ebox-grid.el index 47dbd8c..a43e28f 100644 --- a/ebox-grid.el +++ b/ebox-grid.el @@ -494,6 +494,17 @@ size for start/center/end alignment unless it would overflow its track." (align (or (plist-get props :align-items) 'stretch))) (ebox-grid--align source width height justify align))) +(defun ebox-grid--sized-rendered-entries (entries rendered widths gap props) + "Render ENTRIES at their resolved column widths for later row sizing." + (let ((sized (make-hash-table :test 'eq))) + (dolist (entry entries) + (let* ((node (plist-get entry :node)) + (width (ebox-grid--entry-size entry widths gap))) + (puthash node + (ebox-grid--entry-source entry rendered width props) + sized))) + sized)) + (defun ebox-grid--entry-at (matrix row column) "Return entry occupying ROW and COLUMN in MATRIX." (and (< row (length matrix)) @@ -631,19 +642,23 @@ size for start/center/end alignment unless it would overflow its track." (let* ((widths (ebox-grid--resolve-sizes columns column-count 'columns entries rendered (cdr gaps) available auto-columns)) - (heights (ebox-grid--resolve-sizes rows row-count 'rows - entries rendered (car gaps) - height auto-rows)) (column-layout (ebox-grid--content-layout widths (cdr gaps) available (or (plist-get props :justify-content) 'start))) + (sized-rendered + (ebox-grid--sized-rendered-entries + entries rendered (plist-get column-layout :sizes) + (plist-get column-layout :between) props)) + (heights (ebox-grid--resolve-sizes rows row-count 'rows + entries sized-rendered (car gaps) + height auto-rows)) (row-layout (ebox-grid--content-layout heights (car gaps) height (or (plist-get props :align-content) 'start))) (body (ebox-grid--render entries matrix column-layout row-layout - props rendered))) + props sized-rendered))) (ebox--render-grid-box node body)))) ;;;###autoload diff --git a/tests/ebox-grid-tests.el b/tests/ebox-grid-tests.el index 59ee857..0913d16 100644 --- a/tests/ebox-grid-tests.el +++ b/tests/ebox-grid-tests.el @@ -51,6 +51,20 @@ (widths (mapcar #'ebox--string-pixel-width lines))) (should (equal widths (make-list (length widths) 120))))) +(ert-deftest ebox-grid-sizes-auto-row-after-assigned-width-wrap () + "Auto rows should use the height of width-constrained child content." + (let* ((node (ebox-grid + :width '(40) + :grid-template-columns '((38)) + :border "#334155" + (ebox-create + :content "WIDE CONTENT WIDE CONTENT WIDE CONTENT WIDE CONTENT" + :wrap-mode 'word))) + (lines (ebox-string-lines (ebox-render node))) + (widths (mapcar #'ebox--string-pixel-width lines))) + (should (= (length lines) 2)) + (should (equal widths (make-list (length widths) 40))))) + (ert-deftest ebox-grid-aligns-every-line-before-border-render () "Grid wrapper borders should stay on one right edge across child lines." (let* ((node (ebox-grid