|
|
|
How To Use the Menu APIHeadlineThis document describes how to use the menu API in rockbox. This is for the core and for plugins (plugins remember to use rb-> ). The API makes extensive use of the JdGordon-is-lazy-and-likes-macros macro system (TM)! apps/menu.h has all the macros needed to make a menu.MacrosThese are the important macros.
MENUITEM_SETTINGUsageUse this macro when you want to add the setting screen for a setting. The setting MUST be configured in apps/settings_list.c.Parameters
MENUITEM_SETTING_W_TEXTUsageSame as above, except the text to display either is not set in settings_list.c or you want to show different text.Parameters
MENUITEM_STRINGLIST (Important for plugins)UsageThis will create a menu which is a list of strings. do_menu() will return the index of the string which was selected (0 is the first one). Most do_menu() calls in plugins would use this macro to set up the menu.Parameters
MENUITEM_RETURNVALUEUsageSimilar to MENUITEM_STRINGLIST, except this creats a single menu item which when selected causes do_menu to return some value.Parameters
MENUITEM_RETURNVALUE_DYNTEXTUsageAs above, except the string to display is dynamic.Parameters
MENUITEM_FUNCTIONUsageCreates a menu item which when called will cause the function to be called.Parameters
MENUITEM_FUNCTION_DYNTEXTUsageAs above, except the string to display is dynamic.Parameters
MAKE_MENU (Most important macro)UsageThis is used to create a menu with item of the above macros.Parameters
Important Functionsint do_menu(const struct menu_item_ex *menu, int *start_selected); is the only function required to use the menu API.
ExamplesBasic usage, typical plugin menu
MENUITEM_STRINGLIST(menu, "Edit What?", NULL, "Extension", "Color",);
switch (rb->do_menu(&menu, NULL))
{
case 0: /* "Extension" */
/* do something.... */
break;
case 1: /* "Color" */
/* do something.... */
break;
default: /* user didnt select either item */
}
The above creates a small menu with 2 options, gives it the title "Edit What?" and runs the menu
Advanced usage (from lib/playback_control.c)
MENUITEM_FUNCTION(prevtrack_item, 0, "Previous Track",
prevtrack, NULL, NULL, Icon_NOICON);
MENUITEM_FUNCTION(playpause_item, 0, "Pause / Play",
play, NULL, NULL, Icon_NOICON);
MENUITEM_FUNCTION(stop_item, 0, "Stop Playback",
stop, NULL, NULL, Icon_NOICON);
MENUITEM_FUNCTION(nexttrack_item, 0, "Next Track",
nexttrack, NULL, NULL, Icon_NOICON);
MENUITEM_FUNCTION(volume_item, 0, "Change Volume",
volume, NULL, NULL, Icon_NOICON);
MENUITEM_FUNCTION(shuffle_item, 0, "Enable/Disable Shuffle",
shuffle, NULL, NULL, Icon_NOICON);
MENUITEM_FUNCTION(repeat_mode_item, 0, "Change Repeat Mode",
repeat_mode, NULL, NULL, Icon_NOICON);
MAKE_MENU(playback_control_menu, "Playback Control", NULL, Icon_NOICON,
&prevtrack_item, &playpause_item, &stop_item, &nexttrack_item,
&volume_item, &shuffle_item, &repeat_mode_item);
bool playback_control(struct plugin_api* newapi)
{
api = newapi;
return api->do_menu(&playback_control_menu, NULL) == MENU_ATTACHED_USB;
}
r1 - 15 Jul 2007 - 06:32:51 - JonathanGordon
Copyright © by the contributing authors.
|