Pebble Foundation Classes  0.2.0
C++ for Pebble
ActionMenu
Collaboration diagram for ActionMenu:

Classes

struct  ActionMenuConfig
 Configuration struct for the ActionMenu. More...
 

Typedefs

typedef struct ActionMenuItem ActionMenuItem
 
typedef struct ActionMenuLevel ActionMenuLevel
 
typedef struct ActionMenu ActionMenu
 
typedef void(* ActionMenuDidCloseCb) (ActionMenu *menu, const ActionMenuItem *performed_action, void *context)
 
typedef void(* ActionMenuPerformActionCb) (ActionMenu *action_menu, const ActionMenuItem *action, void *context)
 
typedef void(* ActionMenuEachItemCb) (const ActionMenuItem *item, void *context)
 

Enumerations

enum  ActionMenuAlign { ActionMenuAlignTop = 0, ActionMenuAlignCenter }
 
enum  ActionMenuLevelDisplayMode { ActionMenuLevelDisplayModeWide, ActionMenuLevelDisplayModeThin }
 

Functions

char * action_menu_item_get_label (const ActionMenuItem *item)
 
void * action_menu_item_get_action_data (const ActionMenuItem *item)
 
ActionMenuLevel * action_menu_level_create (uint16_t max_items)
 
void action_menu_level_set_display_mode (ActionMenuLevel *level, ActionMenuLevelDisplayMode display_mode)
 
ActionMenuItem * action_menu_level_add_action (ActionMenuLevel *level, const char *label, ActionMenuPerformActionCb cb, void *action_data)
 
ActionMenuItem * action_menu_level_add_child (ActionMenuLevel *level, ActionMenuLevel *child, const char *label)
 
void action_menu_hierarchy_destroy (const ActionMenuLevel *root, ActionMenuEachItemCb each_cb, void *context)
 
void * action_menu_get_context (ActionMenu *action_menu)
 
ActionMenuLevel * action_menu_get_root_level (ActionMenu *action_menu)
 
ActionMenu * action_menu_open (ActionMenuConfig *config)
 
void action_menu_freeze (ActionMenu *action_menu)
 
void action_menu_unfreeze (ActionMenu *action_menu)
 
void action_menu_set_result_window (ActionMenu *action_menu, Window *result_window)
 
void action_menu_close (ActionMenu *action_menu, bool animated)
 

Detailed Description

Typedef Documentation

◆ ActionMenuDidCloseCb

typedef void(* ActionMenuDidCloseCb) (ActionMenu *menu, const ActionMenuItem *performed_action, void *context)

Callback executed after the ActionMenu has closed, so memory may be freed.

Parameters
root_levelthe root level passed to the ActionMenu
performed_actionthe ActionMenuItem for the action that was performed, NULL if the ActionMenu is closing without an action being selected by the user
contextthe context passed to the ActionMenu

◆ ActionMenuEachItemCb

typedef void(* ActionMenuEachItemCb) (const ActionMenuItem *item, void *context)

Callback invoked for each item in an action menu hierarchy.

Parameters
itemthe current action menu item
acaller-provided context callback

◆ ActionMenuPerformActionCb

typedef void(* ActionMenuPerformActionCb) (ActionMenu *action_menu, const ActionMenuItem *action, void *context)

Callback executed when a given action is selected

Parameters
action_menuthe action menu currently on screen
actionthe action that was triggered
contextthe context passed to the action menu
Note
the action menu is closed immediately after an action is performed, unless it is frozen in the ActionMenuPerformActionCb

Enumeration Type Documentation

◆ ActionMenuLevelDisplayMode

enum value that controls whether menu items are displayed in a grid (similarly to the emoji replies) or in a single column (reminiscent of MenuLayer)

Enumerator
ActionMenuLevelDisplayModeWide 

Each item gets its own row.

ActionMenuLevelDisplayModeThin 

Grid view: multiple items per row.

Function Documentation

◆ action_menu_close()

void action_menu_close ( ActionMenu *  action_menu,
bool  animated 
)

Close the ActionMenu, whether it is frozen or not.

Note
this API can be used on a frozen ActionMenu once the data required to build the result window has been received and the result window has been set
Parameters
action_menuthe ActionMenu to close
animatedwhether or not show a close animation

◆ action_menu_freeze()

void action_menu_freeze ( ActionMenu *  action_menu)

Freeze the ActionMenu. The ActionMenu will no longer respond to user input.

Note
this API should be used when waiting for asynchronous operation.
Parameters
action_menuthe ActionMenu

◆ action_menu_get_context()

void* action_menu_get_context ( ActionMenu *  action_menu)

Get the context pointer this ActionMenu was created with

Parameters
action_menuA pointer to an ActionMenu
Returns
the context pointer initially provided in the ActionMenuConfig. NULL if none exists.

◆ action_menu_get_root_level()

ActionMenuLevel* action_menu_get_root_level ( ActionMenu *  action_menu)

Get the root level of an ActionMenu

Parameters
action_menuthe ActionMenu you want to know about
Returns
a pointer to the root ActionMenuLevel for the given ActionMenu, NULL if invalid

◆ action_menu_hierarchy_destroy()

void action_menu_hierarchy_destroy ( const ActionMenuLevel *  root,
ActionMenuEachItemCb  each_cb,
void *  context 
)

Destroy a hierarchy of ActionMenuLevels

Parameters
rootthe root level in the hierarchy
each_cba callback to call on every ActionMenuItem in every level
contexta context pointer to pass to each_cb on invocation
Note
Typical implementations will cleanup memory allocated for the item label/data associated with each item in the callback
Hierarchy is traversed in post-order. In other words, all children items are freed before their parent is freed.

◆ action_menu_item_get_action_data()

void* action_menu_item_get_action_data ( const ActionMenuItem *  item)

Getter for the action_data pointer of a given ActionMenuitem.

See also
action_menu_level_add_action
Parameters
itemthe ActionMenuItem of interest
Returns
a pointer to the data. NULL if invalid.

◆ action_menu_item_get_label()

char* action_menu_item_get_label ( const ActionMenuItem *  item)

Getter for the label of a given ActionMenuItem

Parameters
itemthe ActionMenuItem of interest
Returns
a pointer to the string label. NULL if invalid.

◆ action_menu_level_add_action()

ActionMenuItem* action_menu_level_add_action ( ActionMenuLevel *  level,
const char *  label,
ActionMenuPerformActionCb  cb,
void *  action_data 
)

Add an action to an ActionLevel

Parameters
levelthe level to add the action to
labelthe text to display for the action in the menu
cbthe callback that will be triggered when this action is actuated
action_datadata to pass to the callback for this action
Returns
a reference to the new ActionMenuItem on success, NULL if the level is full

◆ action_menu_level_add_child()

ActionMenuItem* action_menu_level_add_child ( ActionMenuLevel *  level,
ActionMenuLevel *  child,
const char *  label 
)

Add a child to this ActionMenuLevel

Parameters
levelthe parent level
childthe child level
labelthe text to display in the action menu for this level
Returns
a reference to the new ActionMenuItem on success, NULL if the level is full

◆ action_menu_level_create()

ActionMenuLevel* action_menu_level_create ( uint16_t  max_items)

Create a new action menu level with storage allocated for a given number of items

Parameters
max_itemsthe max number of items that will be displayed at that level
Note
levels are freed alongside the whole hierarchy so no destroy API is provided.
by default, levels are using ActionMenuLevelDisplayModeWide. Use action_menu_level_set_display_mode to change it.
See also
action_menu_hierarchy_destroy

◆ action_menu_level_set_display_mode()

void action_menu_level_set_display_mode ( ActionMenuLevel *  level,
ActionMenuLevelDisplayMode  display_mode 
)

Set the action menu display mode

Parameters
levelThe ActionMenuLevel whose display mode you want to change
display_modeThe display mode for the action menu (3 vs. 1 item per row)

◆ action_menu_open()

ActionMenu* action_menu_open ( ActionMenuConfig config)

Open a new ActionMenu. The ActionMenu acts much like a window. It fills the whole screen and handles clicks.

Parameters
configthe configuration info for this new ActionMenu
Returns
the new ActionMenu

◆ action_menu_set_result_window()

void action_menu_set_result_window ( ActionMenu *  action_menu,
Window *  result_window 
)

Set the result window for an ActionMenu. The result window will be shown when the ActionMenu closes

Parameters
action_menuthe ActionMenu
result_windowthe window to insert, pass NULL to remove the current result window
Note
repeated call will result in only the last call to be applied, i.e. only one result window is ever set

◆ action_menu_unfreeze()

void action_menu_unfreeze ( ActionMenu *  action_menu)

Unfreeze the ActionMenu previously frozen with action_menu_freeze

Parameters
action_menuthe ActionMenu to unfreeze