dialogs.h 4.5 KB

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