button_panel.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * @file button_panel.h
  3. * GUI: ButtonPanel view module API
  4. */
  5. #pragma once
  6. #include <gui/view.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /** Button panel module descriptor */
  11. typedef struct ButtonPanel ButtonPanel;
  12. /** Callback type to call for handling selecting button_panel items */
  13. typedef void (*ButtonItemCallback)(void* context, uint32_t index);
  14. /** Allocate new button_panel module.
  15. *
  16. * @return ButtonPanel instance
  17. */
  18. ButtonPanel* button_panel_alloc(void);
  19. /** Free button_panel module.
  20. *
  21. * @param button_panel ButtonPanel instance
  22. */
  23. void button_panel_free(ButtonPanel* button_panel);
  24. /** Free items from button_panel module. Preallocated matrix stays unchanged.
  25. *
  26. * @param button_panel ButtonPanel instance
  27. */
  28. void button_panel_reset(ButtonPanel* button_panel);
  29. /** Reserve space for adding items.
  30. *
  31. * One does not simply use button_panel_add_item() without this function. It
  32. * should be allocated space for it first.
  33. *
  34. * @param button_panel ButtonPanel instance
  35. * @param reserve_x number of columns in button_panel
  36. * @param reserve_y number of rows in button_panel
  37. */
  38. void button_panel_reserve(ButtonPanel* button_panel, size_t reserve_x, size_t reserve_y);
  39. /** Add item to button_panel module.
  40. *
  41. * Have to set element in bounds of allocated size by X and by Y.
  42. *
  43. * @param button_panel ButtonPanel instance
  44. * @param index value to pass to callback
  45. * @param matrix_place_x coordinates by x-axis on virtual grid, it
  46. * is only used for navigation
  47. * @param matrix_place_y coordinates by y-axis on virtual grid, it
  48. * is only used for naviagation
  49. * @param x x-coordinate to draw icon on
  50. * @param y y-coordinate to draw icon on
  51. * @param icon_name name of the icon to draw
  52. * @param icon_name_selected name of the icon to draw when current
  53. * element is selected
  54. * @param callback function to call when specific element is
  55. * selected (pressed Ok on selected item)
  56. * @param callback_context context to pass to callback
  57. */
  58. void button_panel_add_item(
  59. ButtonPanel* button_panel,
  60. uint32_t index,
  61. uint16_t matrix_place_x,
  62. uint16_t matrix_place_y,
  63. uint16_t x,
  64. uint16_t y,
  65. const Icon* icon_name,
  66. const Icon* icon_name_selected,
  67. ButtonItemCallback callback,
  68. void* callback_context);
  69. /** Get button_panel view.
  70. *
  71. * @param button_panel ButtonPanel instance
  72. *
  73. * @return acquired view
  74. */
  75. View* button_panel_get_view(ButtonPanel* button_panel);
  76. /** Add label to button_panel module.
  77. *
  78. * @param button_panel ButtonPanel instance
  79. * @param x x-coordinate to place label
  80. * @param y y-coordinate to place label
  81. * @param font font to write label with
  82. * @param label_str string label to write
  83. */
  84. void button_panel_add_label(
  85. ButtonPanel* button_panel,
  86. uint16_t x,
  87. uint16_t y,
  88. Font font,
  89. const char* label_str);
  90. #ifdef __cplusplus
  91. }
  92. #endif