dialogs.h 4.4 KB

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