BSB Developer Docs
Loading...
Searching...
No Matches
menu.h File Reference

Rich menu widget with item icons and sub-labels. More...

#include <gui/widget.h>

Go to the source code of this file.

Typedefs

typedef struct Menu Menu
 Menu opaque structure.
 
typedef void(* MenuItemCallback) (uint32_t index, void *context)
 Menu item callback function type.
 

Functions

Menu * menu_alloc (Widget *parent)
 Create a new Menu instance.
 
void menu_free (Menu *instance)
 Delete a Menu instance.
 
Widget * menu_get_base (Menu *instance)
 Get a pointer to the base class instance.
 
void menu_add_item (Menu *instance, const char *label, const char *sub_label, const char *icon_source, uint32_t index, MenuItemCallback callback, void *context)
 Add an item to a Menu instance.
 
void menu_reset (Menu *instance)
 Remove all items from a Menu instance.
 
uint32_t menu_get_selected_item_index (const Menu *instance)
 Get the index of the selected item in a Menu instance.
 
void menu_set_selected_item_index (Menu *instance, uint32_t index)
 Select the item in a Menu instance with a matching index.
 

Detailed Description

Rich menu widget with item icons and sub-labels.

Typedef Documentation

◆ MenuItemCallback

typedef void(* MenuItemCallback) (uint32_t index, void *context)

Menu item callback function type.

Parameters
[in]indexindex value that the item was created with
[in,out]contextpointer to a user-specific object

Function Documentation

◆ menu_add_item()

void menu_add_item ( Menu * instance,
const char * label,
const char * sub_label,
const char * icon_source,
uint32_t index,
MenuItemCallback callback,
void * context )

Add an item to a Menu instance.

Parameters
[in,out]instancepointer to the Menu instance to be modified
[in]labelzero-terminated string containing the item text
[in]sub_labelzero-terminated string containing the auxiliary item text (may be NULL)
[in]icon_sourcezero-terminated string containing a full path to the icon file
[in]indexitem identifier, doesn't have to be unique
[in]callbackpointer to the function to be called when the item is clicked
[in,out]contextpointer to a user-specific object, will be passed to callback

◆ menu_alloc()

Menu * menu_alloc ( Widget * parent)

Create a new Menu instance.

Parameters
[in,out]parentpointer to the parent Widget instance
Returns
pointer to the newly created Menu instance

◆ menu_free()

void menu_free ( Menu * instance)

Delete a Menu instance.

Parameters
[in,out]instancepointer to the Menu instance to be deleted

◆ menu_get_base()

Widget * menu_get_base ( Menu * instance)

Get a pointer to the base class instance.

The return value can be used in all Widget methods.

Parameters
[in,out]instancepointer to the Menu instance to be queried
Returns
pointer to the base class instance

◆ menu_get_selected_item_index()

uint32_t menu_get_selected_item_index ( const Menu * instance)

Get the index of the selected item in a Menu instance.

Parameters
[in]instancepointer to the Menu instance to be queried
Returns
index of the selected item that was provided when adding it

◆ menu_reset()

void menu_reset ( Menu * instance)

Remove all items from a Menu instance.

Parameters
[in,out]instancepointer to the Menu instance to be modified

◆ menu_set_selected_item_index()

void menu_set_selected_item_index ( Menu * instance,
uint32_t index )

Select the item in a Menu instance with a matching index.

Note
If two or more items share the same index, only the first of them will be selected.
Parameters
[in,out]instancepointer to the Menu instance to be modified
[in]indexthe index of the item to be selected