popup.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * @file popup.h
  3. * GUI: Popup view module API
  4. */
  5. #pragma once
  6. #include <gui/view.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /** Popup anonymous structure */
  11. typedef struct Popup Popup;
  12. /** Popup result callback type
  13. * @warning comes from GUI thread
  14. */
  15. typedef void (*PopupCallback)(void* context);
  16. /** Allocate and initialize popup
  17. *
  18. * This popup used to ask simple questions like Yes/
  19. *
  20. * @return Popup instance
  21. */
  22. Popup* popup_alloc();
  23. /** Deinitialize and free popup
  24. *
  25. * @param popup Popup instance
  26. */
  27. void popup_free(Popup* popup);
  28. /** Get popup view
  29. *
  30. * @param popup Popup instance
  31. *
  32. * @return View instance that can be used for embedding
  33. */
  34. View* popup_get_view(Popup* popup);
  35. /** Set popup header text
  36. *
  37. * @param popup Popup instance
  38. * @param callback PopupCallback
  39. */
  40. void popup_set_callback(Popup* popup, PopupCallback callback);
  41. /** Set popup context
  42. *
  43. * @param popup Popup instance
  44. * @param context context pointer, will be passed to result callback
  45. */
  46. void popup_set_context(Popup* popup, void* context);
  47. /** Set popup header text
  48. *
  49. * If text is null, popup header will not be rendered
  50. *
  51. * @param popup Popup instance
  52. * @param text text to be shown, can be multiline
  53. * @param x x position
  54. * @param y y position
  55. * @param horizontal horizontal alignment
  56. * @param vertical vertical aligment
  57. */
  58. void popup_set_header(
  59. Popup* popup,
  60. const char* text,
  61. uint8_t x,
  62. uint8_t y,
  63. Align horizontal,
  64. Align vertical);
  65. /** Set popup text
  66. *
  67. * If text is null, popup text will not be rendered
  68. *
  69. * @param popup Popup instance
  70. * @param text text to be shown, can be multiline
  71. * @param x x position
  72. * @param y y position
  73. * @param horizontal horizontal alignment
  74. * @param vertical vertical aligment
  75. */
  76. void popup_set_text(
  77. Popup* popup,
  78. const char* text,
  79. uint8_t x,
  80. uint8_t y,
  81. Align horizontal,
  82. Align vertical);
  83. /** Set popup icon
  84. *
  85. * If icon position is negative, popup icon will not be rendered
  86. *
  87. * @param popup Popup instance
  88. * @param x x position
  89. * @param y y position
  90. * @param icon pointer to Icon data
  91. */
  92. void popup_set_icon(Popup* popup, uint8_t x, uint8_t y, const Icon* icon);
  93. /** Set popup timeout
  94. *
  95. * @param popup Popup instance
  96. * @param timeout_in_ms popup timeout value in milliseconds
  97. */
  98. void popup_set_timeout(Popup* popup, uint32_t timeout_in_ms);
  99. /** Enable popup timeout
  100. *
  101. * @param popup Popup instance
  102. */
  103. void popup_enable_timeout(Popup* popup);
  104. /** Disable popup timeout
  105. *
  106. * @param popup Popup instance
  107. */
  108. void popup_disable_timeout(Popup* popup);
  109. /** Reset popup instance state
  110. *
  111. * @param popup Popup instance
  112. */
  113. void popup_reset(Popup* popup);
  114. #ifdef __cplusplus
  115. }
  116. #endif