From 94d326883232c52b6e7376d16c6597015443dc5d Mon Sep 17 00:00:00 2001 From: Kelsi Date: Thu, 14 May 2026 17:08:39 -0700 Subject: [PATCH] fix(inventory): size backpack window to actual keyring contents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit renderBagWindow reserved height for ALL 32 keyring slots at 40px in 6 columns, but the keyring renders at 24px in 8 columns and only draws rows that contain occupied slots. Result: a huge empty grey area below the items in the Backpack window. Mirror the render-side calculation (lastOccupied → visibleKeySlots → keyringRows at 24px) in the height math; skip the keyring height entirely when nothing is keyed. --- src/ui/inventory_screen.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ui/inventory_screen.cpp b/src/ui/inventory_screen.cpp index b5cda18e..b3d22701 100644 --- a/src/ui/inventory_screen.cpp +++ b/src/ui/inventory_screen.cpp @@ -1094,9 +1094,24 @@ void InventoryScreen::renderBagWindow(const char* title, bool& isOpen, int rows = (numSlots + columns - 1) / columns; float contentH = rows * (slotSize + 4.0f) + 10.0f; if (bagIndex < 0) { - int keyringRows = (inventory.getKeyringSize() + columns - 1) / columns; + // Keyring renders at 24px in 8 columns and ONLY shows rows that have + // occupied slots (rounded up to a full row of 8) — must match the + // render logic below or we reserve huge empty space. + constexpr float keySlotSize = 24.0f; + constexpr int keyCols = 8; + int lastOccupied = -1; + if (showKeyring_) { + for (int i = inventory.getKeyringSize() - 1; i >= 0; --i) { + if (!inventory.getKeyringSlot(i).empty()) { lastOccupied = i; break; } + } + } + int visibleKeySlots = (lastOccupied < 0) ? 0 + : ((lastOccupied / keyCols) + 1) * keyCols; + int keyringRows = (visibleKeySlots + keyCols - 1) / keyCols; contentH += 36.0f; // separator + sort button + money display - contentH += 30.0f + keyringRows * (slotSize + 4.0f); // keyring header + slots + if (visibleKeySlots > 0) { + contentH += 30.0f + keyringRows * (keySlotSize + 4.0f); // header + slots + } } float gridW = columns * (slotSize + 4.0f) + 30.0f; // Ensure window is wide enough for the title + close button