mch2022-template-app/main/include/menu.h

66 lines
1.8 KiB
C
Raw Normal View History

2022-04-08 21:15:57 +00:00
#pragma once
#ifdef __cplusplus
extern "C" {
#endif //__cplusplus
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "pax_gfx.h"
typedef bool (*menu_callback_t)();
typedef struct _menu_item {
char* label;
menu_callback_t callback;
void* callbackArgs;
2022-06-03 02:23:00 +00:00
pax_buf_t* icon;
2022-04-08 21:15:57 +00:00
// Linked list
struct _menu_item* previousItem;
struct _menu_item* nextItem;
} menu_item_t;
typedef struct menu {
char* title;
menu_item_t* firstItem;
size_t length;
size_t position;
2022-06-03 02:23:00 +00:00
float entry_height;
float text_height;
pax_buf_t* icon;
pax_col_t fgColor;
pax_col_t bgColor;
pax_col_t selectedItemColor;
pax_col_t bgTextColor;
pax_col_t borderColor;
pax_col_t titleColor;
pax_col_t titleBgColor;
pax_col_t scrollbarBgColor;
pax_col_t scrollbarFgColor;
2022-04-08 21:15:57 +00:00
} menu_t;
2022-06-03 02:23:00 +00:00
menu_t* menu_alloc(const char* aTitle, float arg_entry_height, float arg_text_height);
2022-04-08 21:15:57 +00:00
void menu_free(menu_t* aMenu);
2022-06-03 02:23:00 +00:00
void menu_set_icon(menu_t* aMenu, pax_buf_t* icon);
2022-04-08 21:15:57 +00:00
bool menu_insert_item(menu_t* aMenu, const char* aLabel, menu_callback_t aCallback, void* aCallbackArgs, size_t aPosition);
2022-06-03 02:23:00 +00:00
bool menu_insert_item_icon(menu_t* aMenu, const char* aLabel, menu_callback_t aCallback, void* aCallbackArgs, size_t aPosition, pax_buf_t* icon);
2022-04-08 21:15:57 +00:00
bool menu_remove_item(menu_t* aMenu, size_t aPosition);
bool menu_navigate_to(menu_t* aMenu, size_t aPosition);
void menu_navigate_previous(menu_t* aMenu);
void menu_navigate_next(menu_t* aMenu);
size_t menu_get_position(menu_t* aMenu);
2022-04-15 23:16:36 +00:00
size_t menu_get_length(menu_t* aMenu);
2022-04-08 21:15:57 +00:00
void* menu_get_callback_args(menu_t* aMenu, size_t aPosition);
void menu_debug(menu_t* aMenu);
2022-05-30 21:56:23 +00:00
void menu_render(pax_buf_t *aBuffer, menu_t *aMenu, float aPosX, float aPosY, float aWidth, float aHeight, pax_col_t aColor);
2022-04-08 21:15:57 +00:00
#ifdef __cplusplus
}
#endif //__cplusplus