menu.h 2.2 KB

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