dialogs.h 4.3 KB

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