menu.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef _MENU_H
  2. #define _MENU_H
  3. #include "u8g2.h"
  4. #define MENU_SMALL_FONT u8g2_font_baby_tr
  5. #define MENU_NORMAL_FONT u8g2_font_ncenR08_tf
  6. #define MENU_BIG_NUM u8g2_font_ncenR18_tf
  7. typedef struct _menu_struct menu_t;
  8. typedef struct _me_struct me_t;
  9. typedef int (*me_cb)(menu_t *menu, const me_t *me, uint8_t msg);
  10. struct _me_struct
  11. {
  12. me_cb cb;
  13. void *val;
  14. void *arg;
  15. u8g2_uint_t x;
  16. u8g2_uint_t y;
  17. };
  18. /* return 1, if this element can have focus */
  19. #define ME_MSG_IS_FOCUS 1
  20. /* draw focus graphics for the element */
  21. #define ME_MSG_DRAW_FOCUS 2
  22. /* user has pressed the select key */
  23. #define ME_MSG_SELECT 3
  24. /* advice for drawing */
  25. #define ME_MSG_DRAW 4
  26. struct _menu_struct
  27. {
  28. u8g2_t *u8g2;
  29. volatile uint16_t current_index; /* element which is processed right now */
  30. uint16_t focus_index; /* element which has the focus at the moment */
  31. uint16_t radio_index; /* if elements for a radio selection, then this is set by the cb */
  32. uint16_t me_count; /* total number of elements in the list */
  33. /* pointer to the list of menu elements */
  34. const me_t *me_list;
  35. };
  36. void menu_SetEdgePixel(menu_t *menu, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h) U8G2_NOINLINE;
  37. void menu_ClearEdgePixel(menu_t *menu, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h) U8G2_NOINLINE;
  38. void menu_DrawBoxFocus(menu_t *menu, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h) U8G2_NOINLINE;
  39. void menu_DrawFrameFocus(menu_t *menu, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h) U8G2_NOINLINE;
  40. void menu_Init(menu_t *menu, u8g2_t *u8g2);
  41. void menu_SetMEList(menu_t *menu, const me_t *me_list, uint16_t initial_focus);
  42. void menu_Draw(menu_t *menu);
  43. void menu_NextFocus(menu_t *menu);
  44. void menu_Select(menu_t *menu);
  45. int me_cb_null(menu_t *menu, const me_t *me, uint8_t msg);
  46. int me_cb_big_toggle(menu_t *menu, const me_t *me, uint8_t msg);
  47. int me_cb_wd_toggle(menu_t *menu, const me_t *me, uint8_t msg);
  48. int me_cb_0_5(menu_t *menu, const me_t *me, uint8_t msg);
  49. int me_cb_0_9(menu_t *menu, const me_t *me, uint8_t msg);
  50. int me_cb_0_9_ro(menu_t *menu, const me_t *me, uint8_t msg);
  51. int me_cb_0_23(menu_t *menu, const me_t *me, uint8_t msg);
  52. int me_cb_0_23_ro(menu_t *menu, const me_t *me, uint8_t msg);
  53. int me_cb_0_55(menu_t *menu, const me_t *me, uint8_t msg);
  54. int me_cb_1_12(menu_t *menu, const me_t *me, uint8_t msg);
  55. int me_cb_1_31(menu_t *menu, const me_t *me, uint8_t msg);
  56. int me_cb_num_label(menu_t *menu, const me_t *me, uint8_t msg);
  57. int me_cb_button_full_line(menu_t *menu, const me_t *me, uint8_t msg);
  58. int me_cb_button_half_line(menu_t *menu, const me_t *me, uint8_t msg);
  59. int me_cb_button_empty(menu_t *menu, const me_t *me, uint8_t msg);
  60. int me_cb_label(menu_t *menu, const me_t *me, uint8_t msg);
  61. int me_cb_16x16_bitmap_button(menu_t *menu, const me_t *me, uint8_t msg);
  62. #endif