123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
-
-
- #ifndef __MENU_H__
- #define __MENU_H__
-
- #include <stdbool.h>
-
- #define MENU_MAX_LINES 5
- #define MENU_MAX_LEN (MENU_MAX_LINES * 32)
-
- #define MENU_BOX_HEIGHT(lines, font, space) ((lines * font) + ((lines - 1) * space))
-
- struct menu_state {
- int off
- int selection
- int length
- char buff[MENU_MAX_LEN]
- int lines
- int y_off
- }
-
- void menu_init(void (*enter)(int),
- void (*up)(int),
- void (*down)(int),
- void (*exit)(void))
- void menu_deinit(void)
-
- void menu_run(void (*cb)(struct menu_state *), bool centered)
-
- extern bool menu_got_input
-
- #define ADD_STATIC_ELEMENT(format, ...) { \
- menu->length += 1
- if (((menu->length - 1) >= menu->off) \
- && ((menu->length - 1 - menu->off) < menu->lines)) { \
- if ((menu->length - 1) == menu->selection) { \
- pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "> ")
- } else { \
- pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, " ")
- } \
- pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, \
- format __VA_OPT__(,) __VA_ARGS__)
- pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "\n")
- } \
- }
-
- #endif
|