Get immediate callback from optionsMenuItem to dynamically update menu image

, ,

My use case: I’m building a feature to allow the player to select the font for my game’s UI from an options menu item in the system menu (using playdate.menu:addOptionsMenuItem()). I’d like to give a small preview of the selected font as the user changes the value, and the menu image (playdate.setMenuImage()) seems like it would be a good place to do this, especially since I’m already displaying some text as part of that image.

Currently, the documentation states that the callback set in playdate.menu:addOptionsMenuItem() (or playdate.menu:addCheckmarkMenuItem()) isn’t called until the user closes the menu. To provide feedback to the user for the feature as I envision it (without having to write a custom menu):

  1. The menu items would need to call their callback immediately when the value is changed, while the menu remains open (not currently possible). To avoid breaking games that rely on the current behavior, addOptionsMenuItem and addCheckmarkMenuItem could take an extra boolean parameter to indicate that we want our callback to be called immediately, or something like that.
  2. The menu image would need to be able to be updated while the menu is open (I don’t know if this part is already possible).
2 Likes