popup.h 2.3 KB

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