menu.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include <furi.h>
  3. #include <gui/gui.h>
  4. typedef struct {
  5. const char *name; //Name of the menu
  6. bool enabled; //Is the menu item enabled (it will not render, you cannot select it)
  7. void (*callback)(void *state); //Callback for when the activate_menu is called while this menu is selected
  8. } MenuItem;
  9. typedef struct {
  10. MenuItem *items; //list of menu items
  11. uint8_t menu_count; //count of menu items (do not change)
  12. uint8_t current_menu; //currently selected menu item
  13. uint8_t menu_width; //width of the menu
  14. bool enabled; //is the menu enabled (it will not render and accept events when disabled)
  15. } Menu;
  16. /**
  17. * Cleans up the pointers used by the menu
  18. *
  19. * @param menu Pointer of the menu to clean up
  20. */
  21. void free_menu(Menu *menu);
  22. /**
  23. * Add a new menu item
  24. *
  25. * @param menu Pointer of the menu
  26. * @param name Name of the menu item
  27. * @param callback Callback called on activation
  28. */
  29. void add_menu(Menu *menu, const char *name, void (*callback)(void *));
  30. /**
  31. * Setting menu item to be enabled/disabled
  32. *
  33. * @param menu Pointer of the menu
  34. * @param index Menu index to set
  35. * @param state Enabled (true), Disabled(false)
  36. */
  37. void set_menu_state(Menu *menu, uint8_t index, bool state);
  38. /**
  39. * Moves selection up or down
  40. *
  41. * @param menu Pointer of the menu
  42. * @param direction Direction to move -1 down, 1 up
  43. */
  44. void move_menu(Menu *menu, int8_t direction);
  45. /**
  46. * Triggers the current menu callback
  47. *
  48. * @param menu Pointer of the menu
  49. * @param state Usually your application state
  50. */
  51. void activate_menu(Menu *menu, void *state);
  52. /**
  53. * Renders the menu at a coordinate (call it in your render function).
  54. *
  55. * Keep in mind that Flipper has a 128x64 pixel screen resolution and the coordinate
  56. * you give is the menu's rectangle top-left corner (arrows not included).
  57. * The rectangle height is 10 px, the arrows have a 4 pixel height. Space needed is 18px.
  58. * The width of the menu can be configured in the menu object.
  59. *
  60. *
  61. * @param menu Pointer of the menu
  62. * @param canvas Flippers Canvas pointer
  63. * @param pos_x X position to draw
  64. * @param pos_y Y position to draw
  65. */
  66. void render_menu(Menu *menu, Canvas *canvas, uint8_t pos_x, uint8_t pos_y);