From c757d4dc28c5baedaab44a59545760d905d87b20 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 21 Oct 2025 15:47:06 +0200 Subject: [PATCH] fix(layout): allow width/height to be a function. Closes #2184 --- lua/snacks/layout.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lua/snacks/layout.lua b/lua/snacks/layout.lua index 8bc3a38c..3437e04e 100644 --- a/lua/snacks/layout.lua +++ b/lua/snacks/layout.lua @@ -324,8 +324,14 @@ function M:update_box(box, parent) end local free = vim.deepcopy(dim) + local box_win = self.box_wins[box.id] + local function size(child) - return child[size_main] or 0 + local ret = child[size_main] or 0 + if type(ret) == "function" then + ret = ret(box_win) + end + return ret end local dims = {} ---@type table @@ -371,7 +377,6 @@ function M:update_box(box, parent) end -- update box win - local box_win = self.box_wins[box.id] if box_win then if not is_root then box_win.opts.win = self.root.win