From bb3bb8ead97abe58c40f564a5058bad25d3f2f72 Mon Sep 17 00:00:00 2001 From: Eric Lewis Date: Tue, 11 Aug 2026 04:05:32 -0400 Subject: [PATCH 1/2] Fix gridview error when removing the last Noble.Menu item. Noble.Menu:removeItem() called setNumberOfRows() unconditionally, passing 0 when the menu was emptied, which caused "ERROR: playdate.ui.gridview sections must contain at least one row." on the console. The row count is now only updated when at least one item remains; emptying the menu instead resets the selection state (currentItemName is cleared and currentItemNumber returns to 1, matching a freshly created menu), and draw() early-returns for an empty menu so the retained one-row gridview never draws a phantom cell. Repopulating an emptied menu via addItem() resizes the gridview as usual. Fixes upstream issue #89. Co-Authored-By: Claude Fable 5 --- modules/Noble.Menu.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/Noble.Menu.lua b/modules/Noble.Menu.lua index 61faa1c..8d6815a 100644 --- a/modules/Noble.Menu.lua +++ b/modules/Noble.Menu.lua @@ -277,7 +277,14 @@ function Noble.Menu.new(__activate, __alignment, __localized, __color, __padding end end - self:setNumberOfRows(#self.itemNames) + if (#self.itemNames == 0) then + -- The menu is now empty. A gridview section must contain at least one row, + -- so we leave the row count alone and clear the current selection instead. + self.currentItemNumber = 1 + self.currentItemName = nil + else + self:setNumberOfRows(#self.itemNames) + end -- Update width local width = 0 @@ -474,6 +481,7 @@ function Noble.Menu.new(__activate, __alignment, __localized, __color, __padding -- menu:draw(50, 100) -- end function menu:draw(__x, __y) + if (#self.itemNames == 0) then return end local xAdjustment = 0 if (self.alignment == Noble.Text.ALIGN_CENTER) then xAdjustment = self.width/2 From 5941c9ab257e82c574cf399320dd2429b2d00ee0 Mon Sep 17 00:00:00 2001 From: Eric Lewis Date: Tue, 11 Aug 2026 04:43:08 -0400 Subject: [PATCH 2/2] Make an item added to an empty Noble.Menu the current item. Commit 58ee1e9 fixed the gridview crash when removing the last menu item by clearing currentItemName. However, addItem() never repaired the selection: an item added to an emptied menu drew as selected (the gridview still had a selected row), but click() silently did nothing because clickHandlers[currentItemName] looked up a nil key, until the player first pressed up or down. After setting the row count, addItem() now assigns the first item as the current item whenever there is none, and re-selects row 1 if the menu is active. Co-Authored-By: Claude Fable 5 --- modules/Noble.Menu.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/Noble.Menu.lua b/modules/Noble.Menu.lua index 8d6815a..da78a7c 100644 --- a/modules/Noble.Menu.lua +++ b/modules/Noble.Menu.lua @@ -215,6 +215,16 @@ function Noble.Menu.new(__activate, __alignment, __localized, __color, __padding self:setNumberOfRows(#self.itemNames) + -- If there is no current item (i.e. this item was added to an empty menu), + -- this item becomes the current one, so that click() works on it. + if (self.currentItemName == nil) then + self.currentItemNumber = 1 + self.currentItemName = self.itemNames[1] + if (self:isActive()) then + self:setSelectedRow(1) + end + end + end -- Internal method.