#rockbox-lua-menu
A (very) simple menu implementation for Rockbox Lua interpreter. It will draw a menu similar to the Rockbox's menus. Doesn't support (yet) icons and scroll bar. Untested on touch devices.
First, require the menu.lua
file on your code, and you're ready to go:
require "menu"
require "buttons"
local exiting = false
local CYCLETIME = rb.HZ / 50
local mainMenu = Menu:new(10,10,30,50)
:addItem("first item") -- supports method chaining
:addItem("second item")
:addItem("third item")
:addItem("exit", function () exiting = true end) -- supports callback
while not exiting do
rb.lcd_clear_display()
local endtick = rb.current_tick() + CYCLETIME
local but = rb.button_get(false)
if but == rb.buttons.BUTTON_SELECT then
activeMenu:choose()
elseif but == rb.buttons.BUTTON_SCROLL_FWD then
activeMenu:move(1)
elseif but == rb.buttons.BUTTON_SCROLL_BACK then
activeMenu:move(-1)
end
mainMenu:draw()
rb.lcd_update()
while rb.current_tick() < endtick do
rb.yield()
end
end
Or take a look at test.lua
.
Except for Menu:choose and Menu:draw, every method is chainable.
Creates a new menu object.
- x: the top-left x menu position
- y: the top-left y menu position
- w: the menu total width
- h: the menu total height
Add a menu entry with an optional callback. The callback will be called when you call Menu:choose().
- str: The menu entry text that will be shown on menu
- callback: The callback that will be called when the option is selected using Menu:choose
Removes a menu entry
- pos: position of the entry that will be removed
Changes the selected entry of menu
- qty: delta of the selection movement (a value of 2 will advance the selected option twice downwards)
Call the callback associated with the selected option, if any.
Draws the menu on screen.