button_panel.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #pragma once
  2. #include <gui/view.h>
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /** Button panel module descriptor */
  7. typedef struct ButtonPanel ButtonPanel;
  8. /** Callback type to call for handling selecting button_panel items */
  9. typedef void (*ButtonItemCallback)(void* context, uint32_t index);
  10. /** Callback type for additional drawings above main button_panel screen */
  11. typedef void (*ButtonPanelDrawCallback)(Canvas* canvas, void* _model);
  12. /** Callback type to intercept input events of button_panel */
  13. typedef bool (*ButtonPanelInputCallback)(InputEvent* event, void* context);
  14. /** Allocate new button_panel module.
  15. *
  16. * @return just-created module
  17. */
  18. ButtonPanel* button_panel_alloc(void);
  19. /** Free button_panel module.
  20. *
  21. * @param button_panel - module to free
  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 - module to clean
  27. */
  28. void button_panel_clean(ButtonPanel* button_panel);
  29. /** Reserve space for adding items.
  30. *
  31. * One does not simply use button_panel_add_item() without this function.
  32. * It should be allocated space for it first.
  33. *
  34. * @param button_panel - module to modify
  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 - module
  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 naviagation
  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 selected
  55. * (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 - module to get view from
  72. * @return acquired view
  73. */
  74. View* button_panel_get_view(ButtonPanel* button_panel);
  75. /** Add label to button_panel module.
  76. *
  77. * @param x - x-coordinate to place label
  78. * @param y - y-coordinate to place label
  79. * @param font - font to write label with
  80. * @param label_str - string label to write
  81. */
  82. void button_panel_add_label(
  83. ButtonPanel* button_panel,
  84. uint16_t x,
  85. uint16_t y,
  86. Font font,
  87. const char* label_str);
  88. // TODO: [FL-1445] Have to replace callbacks above with additional popup-layer
  89. /** Set popup draw callback for button_panel module.
  90. *
  91. * Used to add popup drawings after main draw callback is done.
  92. *
  93. * @param button_panel - module to modify
  94. * @param callback - callback function to set for draw event
  95. * @param context - context to pass to callback
  96. */
  97. void button_panel_set_popup_draw_callback(
  98. ButtonPanel* button_panel,
  99. ButtonPanelDrawCallback callback,
  100. void* context);
  101. /** Set popup input callback for button_panel module.
  102. *
  103. * Used to add popup input callback. It will intercept all input
  104. * events for current view.
  105. *
  106. * @param button_panel - module to modify
  107. * @param callback - function to overwrite main input callbacks
  108. * @param context - context to pass to callback
  109. */
  110. void button_panel_set_popup_input_callback(
  111. ButtonPanel* button_panel,
  112. ButtonPanelInputCallback callback,
  113. void* context);
  114. #ifdef __cplusplus
  115. }
  116. #endif