Layer that displays a standard list menu. Data is provided using callbacks.
For short, static list menus, consider using SimpleMenuLayer.
void menu_cell_basic_draw | ( | GContext * | ctx, |
const Layer * | cell_layer, | ||
const char * | title, | ||
const char * | subtitle, | ||
GBitmap * | icon | ||
) |
Cell drawing function to draw a basic menu cell layout with title, subtitle and icon on the left of the cell. Call this function inside the .draw_row
callback implementation, see MenuLayerCallbacks.
ctx | The destination graphics context |
cell_layer | The layer of the cell to draw |
title | If non-null, draws a title in larger text (24 points, bold Raster Gothic system font). |
subtitle | If non-null, draws a subtitle in smaller text (18 points, Raster Gothic system font). If NULL , the title will be centered vertically inside the menu cell. |
icon | If non-null, draws an icon to the left of the text. If NULL , the icon will be omitted and the leftover space is used for the title and subtitle. |
void menu_cell_basic_header_draw | ( | GContext * | ctx, |
const Layer * | cell_layer, | ||
const char * | title | ||
) |
Section header drawing function to draw a basic section header cell layout with the title of the section. Call this function inside the .draw_header
callback implementation, see MenuLayerCallbacks.
ctx | The destination graphics context |
cell_layer | The layer of the cell to draw |
title | If non-null, draws the title in small text (14 points, bold Raster Gothic system font). |
void menu_cell_title_draw | ( | GContext * | ctx, |
const Layer * | cell_layer, | ||
const char * | title | ||
) |
Cell drawing function to draw a menu cell layout with only one big title. Call this function inside the .draw_row
callback implementation, see MenuLayerCallbacks.
ctx | The destination graphics context |
cell_layer | The layer of the cell to draw |
title | If non-null, draws a title in larger text (28 points, bold Raster Gothic system font). |
Comparator function to determine the order of two MenuIndex values.
a | Pointer to the menu index of the first item |
b | Pointer to the menu index of the second item |
MenuLayer* menu_layer_create | ( | GRect | frame | ) |
Creates a new MenuLayer on the heap and initalizes it with the default values.
true
false
frame.size
NULL
for each one)NULL
NULL
if the MenuLayer could not be created void menu_layer_destroy | ( | MenuLayer * | menu_layer | ) |
Destroys a MenuLayer previously created by menu_layer_create.
Layer* menu_layer_get_layer | ( | const MenuLayer * | menu_layer | ) |
Gets the "root" Layer of the menu layer, which is the parent for the sub- layers used for its implementation.
menu_layer | Pointer to the MenuLayer for which to get the "root" Layer |
ScrollLayer* menu_layer_get_scroll_layer | ( | const MenuLayer * | menu_layer | ) |
Gets the ScrollLayer of the menu layer, which is the layer responsible for the scrolling of the menu layer.
menu_layer | Pointer to the MenuLayer for which to get the ScrollLayer |
MenuIndex menu_layer_get_selected_index | ( | const MenuLayer * | menu_layer | ) |
Gets the MenuIndex of the currently selection menu item.
menu_layer | The MenuLayer for which to get the current selected index. |
void menu_layer_reload_data | ( | MenuLayer * | menu_layer | ) |
Reloads the data of the menu. This causes the menu to re-request the menu item data, by calling the relevant callbacks. The current selection and scroll position will not be changed. See the note with menu_layer_set_selected_index() for the behavior if the old selection is no longer valid.
menu_layer | The MenuLayer for which to reload the data. |
void menu_layer_set_callbacks | ( | MenuLayer * | menu_layer, |
void * | callback_context, | ||
MenuLayerCallbacks | callbacks | ||
) |
Sets the callbacks for the MenuLayer.
menu_layer | Pointer to the MenuLayer for which to set the callbacks and callback context. |
callback_context | The new callback context. This is passed into each of the callbacks and can be set to point to application provided data. |
callbacks | The new callbacks for the MenuLayer. The storage for this data structure must be long lived. Therefore, it cannot be stack-allocated. |
void menu_layer_set_click_config_onto_window | ( | MenuLayer * | menu_layer, |
struct Window * | window | ||
) |
Convenience function to set the ClickConfigProvider callback on the given window to menu layer's internal click config provider. This internal click configuration provider, will set up the default UP & DOWN scrolling / menu item selection behavior. This function calls scroll_layer_set_click_config_onto_window to accomplish this.
Click and long click events for the SELECT button can be handled by installing the appropriate callbacks using menu_layer_set_callbacks(). This is a deviation from the usual click configuration provider pattern.
menu_layer | The MenuLayer that needs to receive click events. |
window | The window for which to set the click configuration. |
void menu_layer_set_selected_index | ( | MenuLayer * | menu_layer, |
MenuIndex | index, | ||
MenuRowAlign | scroll_align, | ||
bool | animated | ||
) |
Selects the item with given MenuIndex.
menu_layer | The MenuLayer for which to change the selection |
index | The index of the item to select |
scroll_align | The alignment of the new selection |
animated | Supply true to animate changing the selection, or false to change the selection instantly. |
void menu_layer_set_selected_next | ( | MenuLayer * | menu_layer, |
bool | up, | ||
MenuRowAlign | scroll_align, | ||
bool | animated | ||
) |
Selects the next or previous item, relative to the current selection.
menu_layer | The MenuLayer for which to select the next item |
up | Supply false to select the next item in the list (downwards), or true to select the previous item in the list (upwards). |
scroll_align | The alignment of the new selection |
animated | Supply true to animate changing the selection, or false to change the selection instantly. |
struct MenuIndex |
struct MenuLayerCallbacks |
Data structure containing all the callbacks of a MenuLayer.
Data Fields | ||
---|---|---|
MenuLayerDrawHeaderCallback | draw_header |
Callback that gets called to render a section header. This gets called for each section header, every time it needs to be re-rendered.
|
MenuLayerDrawRowCallback | draw_row |
Callback that gets called to render a menu item. This gets called for each menu item, every time it needs to be re-rendered.
|
MenuLayerGetCellHeightCallback | get_cell_height |
Callback that gets called to get the height of a cell. This can get called at various moments throughout the life of a menu.
|
MenuLayerGetHeaderHeightCallback | get_header_height |
Callback that gets called to get the height of a section header. This can get called at various moments throughout the life of a menu.
|
MenuLayerGetNumberOfRowsInSectionsCallback | get_num_rows |
Callback that gets called to get the number of rows in a section. This can get called at various moments throughout the life of a menu.
|
MenuLayerGetNumberOfSectionsCallback | get_num_sections |
Callback that gets called to get the number of sections in the menu. This can get called at various moments throughout the life of a menu.
|
MenuLayerSelectCallback | select_click |
Callback that gets called when the user triggers a click with the SELECT button.
|
MenuLayerSelectCallback | select_long_click |
Callback that gets called when the user triggers a long click with the SELECT button.
|
MenuLayerSelectionChangedCallback | selection_changed |
Callback that gets called whenever the selection changes.
|
typedef void(* MenuLayerDrawHeaderCallback)(GContext *ctx, const Layer *cell_layer, uint16_t section_index, void *callback_context) |
Function signature for the callback to render the section header at a given section index.
ctx | The destination graphics context to draw into |
cell_layer | The header cell's layer, containing the geometry of the header cell |
section_index | The section index of the section header that needs to be drawn |
callback_context | The callback context |
cell_layer
argument is provided to make it easy to re-use an .update_proc
implementation in this callback. Only the bounds and frame of the cell_layer
are actually valid and other properties should be ignored. typedef void(* MenuLayerDrawRowCallback)(GContext *ctx, const Layer *cell_layer, MenuIndex *cell_index, void *callback_context) |
Function signature for the callback to render the menu cell at a given MenuIndex.
ctx | The destination graphics context to draw into |
cell_layer | The cell's layer, containing the geometry of the cell |
cell_index | The MenuIndex of the cell that needs to be drawn |
callback_context | The callback context |
cell_layer
argument is provided to make it easy to re-use an .update_proc
implementation in this callback. Only the bounds and frame of the cell_layer
are actually valid and other properties should be ignored. typedef int16_t(* MenuLayerGetCellHeightCallback)(struct MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context) |
Function signature for the callback to get the height of the menu cell at a given index.
menu_layer | The menu layer for which the data is requested |
cell_index | The MenuIndex for which the cell height is requested |
callback_context | The callback context |
typedef int16_t(* MenuLayerGetHeaderHeightCallback)(struct MenuLayer *menu_layer, uint16_t section_index, void *callback_context) |
Function signature for the callback to get the height of the section header at a given section index.
menu_layer | The menu layer for which the data is requested |
section_index | The index of the section for which the header height is requested |
callback_context | The callback context |
typedef uint16_t(* MenuLayerGetNumberOfRowsInSectionsCallback)(struct MenuLayer *menu_layer, uint16_t section_index, void *callback_context) |
Function signature for the callback to get the number of rows in a given section in a menu.
menu_layer | The menu layer for which the data is requested |
section_index | The index of the section of the menu for which the number of items it contains is requested |
callback_context | The callback context |
typedef uint16_t(* MenuLayerGetNumberOfSectionsCallback)(struct MenuLayer *menu_layer, void *callback_context) |
Function signature for the callback to get the number of sections in a menu.
menu_layer | The menu layer for which the data is requested |
callback_context | The callback context |
typedef void(* MenuLayerSelectCallback)(struct MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context) |
Function signature for the callback to handle the event that a user hits the SELECT button.
menu_layer | The menu layer for which the selection event occured |
cell_index | The MenuIndex of the cell that is selected |
callback_context | The callback context |
typedef void(* MenuLayerSelectionChangedCallback)(struct MenuLayer *menu_layer, MenuIndex new_index, MenuIndex old_index, void *callback_context) |
Function signature for the callback to handle a change in the current selected item in the menu.
enum MenuRowAlign |
Values to specify how a (selected) row should be aligned relative to the visible area of the MenuLayer.
#define MENU_CELL_BASIC_HEADER_HEIGHT ((const int16_t) 16) |
Default section header height in pixels.