button_panel.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. /** Callback type for additional drawings above main button_panel screen */
  15. typedef void (*ButtonPanelDrawCallback)(Canvas* canvas, void* _model);
  16. /** Callback type to intercept input events of button_panel */
  17. typedef bool (*ButtonPanelInputCallback)(InputEvent* event, void* context);
  18. /** Allocate new button_panel module.
  19. *
  20. * @return ButtonPanel instance
  21. */
  22. ButtonPanel* button_panel_alloc(void);
  23. /** Free button_panel module.
  24. *
  25. * @param button_panel ButtonPanel instance
  26. */
  27. void button_panel_free(ButtonPanel* button_panel);
  28. /** Free items from button_panel module. Preallocated matrix stays unchanged.
  29. *
  30. * @param button_panel ButtonPanel instance
  31. */
  32. void button_panel_clean(ButtonPanel* button_panel);
  33. /** Reserve space for adding items.
  34. *
  35. * One does not simply use button_panel_add_item() without this function. It
  36. * should be allocated space for it first.
  37. *
  38. * @param button_panel ButtonPanel instance
  39. * @param reserve_x number of columns in button_panel
  40. * @param reserve_y number of rows in button_panel
  41. */
  42. void button_panel_reserve(ButtonPanel* button_panel, size_t reserve_x, size_t reserve_y);
  43. /** Add item to button_panel module.
  44. *
  45. * Have to set element in bounds of allocated size by X and by Y.
  46. *
  47. * @param button_panel ButtonPanel instance
  48. * @param index value to pass to callback
  49. * @param matrix_place_x coordinates by x-axis on virtual grid, it
  50. * is only used for naviagation
  51. * @param matrix_place_y coordinates by y-axis on virtual grid, it
  52. * is only used for naviagation
  53. * @param x x-coordinate to draw icon on
  54. * @param y y-coordinate to draw icon on
  55. * @param icon_name name of the icon to draw
  56. * @param icon_name_selected name of the icon to draw when current
  57. * element is selected
  58. * @param callback function to call when specific element is
  59. * selected (pressed Ok on selected item)
  60. * @param callback_context context to pass to callback
  61. */
  62. void button_panel_add_item(
  63. ButtonPanel* button_panel,
  64. uint32_t index,
  65. uint16_t matrix_place_x,
  66. uint16_t matrix_place_y,
  67. uint16_t x,
  68. uint16_t y,
  69. const Icon* icon_name,
  70. const Icon* icon_name_selected,
  71. ButtonItemCallback callback,
  72. void* callback_context);
  73. /** Get button_panel view.
  74. *
  75. * @param button_panel ButtonPanel instance
  76. *
  77. * @return acquired view
  78. */
  79. View* button_panel_get_view(ButtonPanel* button_panel);
  80. /** Add label to button_panel module.
  81. *
  82. * @param button_panel ButtonPanel instance
  83. * @param x x-coordinate to place label
  84. * @param y y-coordinate to place label
  85. * @param font font to write label with
  86. * @param label_str string label to write
  87. */
  88. void button_panel_add_label(
  89. ButtonPanel* button_panel,
  90. uint16_t x,
  91. uint16_t y,
  92. Font font,
  93. const char* label_str);
  94. // TODO: [FL-1445] Have to replace callbacks above with additional popup-layer
  95. /** Set popup draw callback for button_panel module.
  96. *
  97. * Used to add popup drawings after main draw callback is done.
  98. *
  99. * @param button_panel ButtonPanel instance
  100. * @param callback callback function to set for draw event
  101. * @param context context to pass to callback
  102. */
  103. void button_panel_set_popup_draw_callback(
  104. ButtonPanel* button_panel,
  105. ButtonPanelDrawCallback callback,
  106. void* context);
  107. /** Set popup input callback for button_panel module.
  108. *
  109. * Used to add popup input callback. It will intercept all input events for
  110. * current view.
  111. *
  112. * @param button_panel ButtonPanel instance
  113. * @param callback function to overwrite main input callbacks
  114. * @param context context to pass to callback
  115. */
  116. void button_panel_set_popup_input_callback(
  117. ButtonPanel* button_panel,
  118. ButtonPanelInputCallback callback,
  119. void* context);
  120. #ifdef __cplusplus
  121. }
  122. #endif