dialog_ex.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #pragma once
  2. #include <gui/view.h>
  3. /* Dialog anonymous structure */
  4. typedef struct DialogEx DialogEx;
  5. /* DialogEx result */
  6. typedef enum {
  7. DialogExResultLeft,
  8. DialogExResultCenter,
  9. DialogExResultRight,
  10. } DialogExResult;
  11. /* DialogEx result callback type
  12. * @warning comes from GUI thread
  13. */
  14. typedef void (*DialogExResultCallback)(DialogExResult result, void* context);
  15. /* Allocate and initialize dialog
  16. * This dialog used to ask simple questions like Yes/
  17. */
  18. DialogEx* dialog_ex_alloc();
  19. /* Deinitialize and free dialog
  20. * @param dialog - DialogEx instance
  21. */
  22. void dialog_ex_free(DialogEx* dialog_ex);
  23. /* Get dialog view
  24. * @param dialog - DialogEx instance
  25. * @return View instance that can be used for embedding
  26. */
  27. View* dialog_ex_get_view(DialogEx* dialog_ex);
  28. /* Set dialog result callback
  29. * @param dialog_ex - DialogEx instance
  30. * @param callback - result callback function
  31. */
  32. void dialog_ex_set_result_callback(DialogEx* dialog_ex, DialogExResultCallback callback);
  33. /* Set dialog context
  34. * @param dialog_ex - DialogEx instance
  35. * @param context - context pointer, will be passed to result callback
  36. */
  37. void dialog_ex_set_context(DialogEx* dialog_ex, void* context);
  38. /* Set dialog header text
  39. * If text is null, dialog header will not be rendered
  40. * @param dialog - DialogEx instance
  41. * @param text - text to be shown, can be multiline
  42. * @param x, y - text position
  43. * @param horizontal, vertical - text aligment
  44. */
  45. void dialog_ex_set_header(
  46. DialogEx* dialog_ex,
  47. const char* text,
  48. uint8_t x,
  49. uint8_t y,
  50. Align horizontal,
  51. Align vertical);
  52. /* Set dialog text
  53. * If text is null, dialog text will not be rendered
  54. * @param dialog - DialogEx instance
  55. * @param text - text to be shown, can be multiline
  56. * @param x, y - text position
  57. * @param horizontal, vertical - text aligment
  58. */
  59. void dialog_ex_set_text(
  60. DialogEx* dialog_ex,
  61. const char* text,
  62. uint8_t x,
  63. uint8_t y,
  64. Align horizontal,
  65. Align vertical);
  66. /* Set dialog icon
  67. * If x or y is negative, dialog icon will not be rendered
  68. * @param dialog - DialogEx instance
  69. * @param x, y - icon position
  70. * @param name - icon to be shown
  71. */
  72. void dialog_ex_set_icon(DialogEx* dialog_ex, int8_t x, int8_t y, IconName name);
  73. /* Set left button text
  74. * If text is null, left button will not be rendered and processed
  75. * @param dialog - DialogEx instance
  76. * @param text - text to be shown
  77. */
  78. void dialog_ex_set_left_button_text(DialogEx* dialog_ex, const char* text);
  79. /* Set center button text
  80. * If text is null, center button will not be rendered and processed
  81. * @param dialog - DialogEx instance
  82. * @param text - text to be shown
  83. */
  84. void dialog_ex_set_center_button_text(DialogEx* dialog_ex, const char* text);
  85. /* Set right button text
  86. * If text is null, right button will not be rendered and processed
  87. * @param dialog - DialogEx instance
  88. * @param text - text to be shown
  89. */
  90. void dialog_ex_set_right_button_text(DialogEx* dialog_ex, const char* text);