dialogs.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #pragma once
  2. #include <furi.h>
  3. #include <gui/canvas.h>
  4. #include <gui/modules/file_browser.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /****************** COMMON ******************/
  9. #define RECORD_DIALOGS "dialogs"
  10. typedef struct DialogsApp DialogsApp;
  11. /****************** FILE BROWSER ******************/
  12. /**
  13. * File browser dialog extra options
  14. * @param extension file extension to be offered for selection
  15. * @param skip_assets true - do not show assets folders
  16. * @param icon file icon pointer, NULL for default icon
  17. * @param hide_ext true - hide extensions for files
  18. * @param item_loader_callback callback function for providing custom icon & entry name
  19. * @param hide_ext callback context
  20. */
  21. typedef struct {
  22. const char* extension;
  23. bool skip_assets;
  24. const Icon* icon;
  25. bool hide_ext;
  26. FileBrowserLoadItemCallback item_loader_callback;
  27. void* item_loader_context;
  28. } DialogsFileBrowserOptions;
  29. /**
  30. * Initialize file browser dialog options
  31. * and set default values
  32. * @param options pointer to options structure
  33. * @param extension file extension to filter
  34. * @param icon file icon pointer, NULL for default icon
  35. */
  36. void dialog_file_browser_set_basic_options(
  37. DialogsFileBrowserOptions* options,
  38. const char* extension,
  39. const Icon* icon);
  40. /**
  41. * Shows and processes the file browser dialog
  42. * @param context api pointer
  43. * @param result_path selected file path string pointer
  44. * @param path preselected file path string pointer
  45. * @param options file browser dialog extra options, may be null
  46. * @return bool whether a file was selected
  47. */
  48. bool dialog_file_browser_show(
  49. DialogsApp* context,
  50. FuriString* result_path,
  51. FuriString* path,
  52. const DialogsFileBrowserOptions* options);
  53. /****************** MESSAGE ******************/
  54. /**
  55. * Message result type
  56. */
  57. typedef enum {
  58. DialogMessageButtonBack,
  59. DialogMessageButtonLeft,
  60. DialogMessageButtonCenter,
  61. DialogMessageButtonRight,
  62. } DialogMessageButton;
  63. /**
  64. * Message struct
  65. */
  66. typedef struct DialogMessage DialogMessage;
  67. /**
  68. * Allocate and fill message
  69. * @return DialogMessage*
  70. */
  71. DialogMessage* dialog_message_alloc();
  72. /**
  73. * Free message struct
  74. * @param message message pointer
  75. */
  76. void dialog_message_free(DialogMessage* message);
  77. /**
  78. * Set message text
  79. * @param message message pointer
  80. * @param text text, can be NULL if you don't want to display the text
  81. * @param x x position
  82. * @param y y position
  83. * @param horizontal horizontal alignment
  84. * @param vertical vertical alignment
  85. */
  86. void dialog_message_set_text(
  87. DialogMessage* message,
  88. const char* text,
  89. uint8_t x,
  90. uint8_t y,
  91. Align horizontal,
  92. Align vertical);
  93. /**
  94. * Set message header
  95. * @param message message pointer
  96. * @param text text, can be NULL if you don't want to display the header
  97. * @param x x position
  98. * @param y y position
  99. * @param horizontal horizontal alignment
  100. * @param vertical vertical alignment
  101. */
  102. void dialog_message_set_header(
  103. DialogMessage* message,
  104. const char* text,
  105. uint8_t x,
  106. uint8_t y,
  107. Align horizontal,
  108. Align vertical);
  109. /**
  110. * Set message icon
  111. * @param message message pointer
  112. * @param icon icon pointer, can be NULL if you don't want to display the icon
  113. * @param x x position
  114. * @param y y position
  115. */
  116. void dialog_message_set_icon(DialogMessage* message, const Icon* icon, uint8_t x, uint8_t y);
  117. /**
  118. * Set message buttons text, button text can be NULL if you don't want to display and process some buttons
  119. * @param message message pointer
  120. * @param left left button text, can be NULL if you don't want to display the left button
  121. * @param center center button text, can be NULL if you don't want to display the center button
  122. * @param right right button text, can be NULL if you don't want to display the right button
  123. */
  124. void dialog_message_set_buttons(
  125. DialogMessage* message,
  126. const char* left,
  127. const char* center,
  128. const char* right);
  129. /**
  130. * Show message from filled struct
  131. * @param context api pointer
  132. * @param message message struct pointer to be shown
  133. * @return DialogMessageButton type
  134. */
  135. DialogMessageButton dialog_message_show(DialogsApp* context, const DialogMessage* message);
  136. /**
  137. * Show SD error message (with question sign)
  138. * @param context
  139. * @param error_text
  140. */
  141. void dialog_message_show_storage_error(DialogsApp* context, const char* error_text);
  142. #ifdef __cplusplus
  143. }
  144. #endif