easy_flipper.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. #ifndef EASY_FLIPPER_H
  2. #define EASY_FLIPPER_H
  3. #include <malloc.h>
  4. #include <furi.h>
  5. #include <furi_hal.h>
  6. #include <gui/gui.h>
  7. #include <gui/view.h>
  8. #include <gui/modules/submenu.h>
  9. #include <gui/view_dispatcher.h>
  10. #include <gui/elements.h>
  11. #include <gui/modules/menu.h>
  12. #include <gui/modules/submenu.h>
  13. #include <gui/modules/widget.h>
  14. #include <gui/modules/text_input.h>
  15. #include <gui/modules/text_box.h>
  16. #include <gui/modules/variable_item_list.h>
  17. #include <gui/modules/dialog_ex.h>
  18. #include <notification/notification.h>
  19. #include <dialogs/dialogs.h>
  20. #include <gui/modules/popup.h>
  21. #include <gui/modules/loading.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <jsmn/jsmn.h>
  25. #define EASY_TAG "EasyFlipper"
  26. void easy_flipper_dialog(
  27. char *header,
  28. char *text);
  29. /**
  30. * @brief Navigation callback for exiting the application
  31. * @param context The context - unused
  32. * @return next view id (VIEW_NONE to exit the app)
  33. */
  34. uint32_t easy_flipper_callback_exit_app(void *context);
  35. /**
  36. * @brief Initialize a buffer
  37. * @param buffer The buffer to initialize
  38. * @param buffer_size The size of the buffer
  39. * @return true if successful, false otherwise
  40. */
  41. bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size);
  42. /**
  43. * @brief Initialize a View object
  44. * @param view The View object to initialize
  45. * @param view_id The ID/Index of the view
  46. * @param draw_callback The draw callback function (set to NULL if not needed)
  47. * @param input_callback The input callback function (set to NULL if not needed)
  48. * @param previous_callback The previous callback function (can be set to NULL)
  49. * @param view_dispatcher The ViewDispatcher object
  50. * @return true if successful, false otherwise
  51. */
  52. bool easy_flipper_set_view(
  53. View **view,
  54. int32_t view_id,
  55. void draw_callback(Canvas *, void *),
  56. bool input_callback(InputEvent *, void *),
  57. uint32_t (*previous_callback)(void *),
  58. ViewDispatcher **view_dispatcher,
  59. void *context);
  60. /**
  61. * @brief Initialize a ViewDispatcher object
  62. * @param view_dispatcher The ViewDispatcher object to initialize
  63. * @param gui The GUI object
  64. * @param context The context to pass to the event callback
  65. * @return true if successful, false otherwise
  66. */
  67. bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui, void *context);
  68. /**
  69. * @brief Initialize a Submenu object
  70. * @note This does not set the items in the submenu
  71. * @param submenu The Submenu object to initialize
  72. * @param view_id The ID/Index of the view
  73. * @param title The title/header of the submenu
  74. * @param previous_callback The previous callback function (can be set to NULL)
  75. * @param view_dispatcher The ViewDispatcher object
  76. * @return true if successful, false otherwise
  77. */
  78. bool easy_flipper_set_submenu(
  79. Submenu **submenu,
  80. int32_t view_id,
  81. char *title,
  82. uint32_t(previous_callback)(void *),
  83. ViewDispatcher **view_dispatcher);
  84. /**
  85. * @brief Initialize a Menu object
  86. * @note This does not set the items in the menu
  87. * @param menu The Menu object to initialize
  88. * @param view_id The ID/Index of the view
  89. * @param item_callback The item callback function
  90. * @param previous_callback The previous callback function (can be set to NULL)
  91. * @param view_dispatcher The ViewDispatcher object
  92. * @return true if successful, false otherwise
  93. */
  94. bool easy_flipper_set_menu(
  95. Menu **menu,
  96. int32_t view_id,
  97. uint32_t(previous_callback)(void *),
  98. ViewDispatcher **view_dispatcher);
  99. /**
  100. * @brief Initialize a Widget object
  101. * @param widget The Widget object to initialize
  102. * @param view_id The ID/Index of the view
  103. * @param text The text to display in the widget
  104. * @param previous_callback The previous callback function (can be set to NULL)
  105. * @param view_dispatcher The ViewDispatcher object
  106. * @return true if successful, false otherwise
  107. */
  108. bool easy_flipper_set_widget(
  109. Widget **widget,
  110. int32_t view_id,
  111. char *text,
  112. uint32_t(previous_callback)(void *),
  113. ViewDispatcher **view_dispatcher);
  114. /**
  115. * @brief Initialize a VariableItemList object
  116. * @note This does not set the items in the VariableItemList
  117. * @param variable_item_list The VariableItemList object to initialize
  118. * @param view_id The ID/Index of the view
  119. * @param enter_callback The enter callback function (can be set to NULL)
  120. * @param previous_callback The previous callback function (can be set to NULL)
  121. * @param view_dispatcher The ViewDispatcher object
  122. * @param context The context to pass to the enter callback (usually the app)
  123. * @return true if successful, false otherwise
  124. */
  125. bool easy_flipper_set_variable_item_list(
  126. VariableItemList **variable_item_list,
  127. int32_t view_id,
  128. void (*enter_callback)(void *, uint32_t),
  129. uint32_t(previous_callback)(void *),
  130. ViewDispatcher **view_dispatcher,
  131. void *context);
  132. /**
  133. * @brief Initialize a TextInput object
  134. * @param text_input The TextInput object to initialize
  135. * @param view_id The ID/Index of the view
  136. * @param previous_callback The previous callback function (can be set to NULL)
  137. * @param view_dispatcher The ViewDispatcher object
  138. * @return true if successful, false otherwise
  139. */
  140. bool easy_flipper_set_text_input(
  141. TextInput **text_input,
  142. int32_t view_id,
  143. char *header_text,
  144. char *text_input_temp_buffer,
  145. uint32_t text_input_buffer_size,
  146. void (*result_callback)(void *),
  147. uint32_t(previous_callback)(void *),
  148. ViewDispatcher **view_dispatcher,
  149. void *context);
  150. /**
  151. * @brief Initialize a TextInput object with extra symbols
  152. * @param uart_text_input The TextInput object to initialize
  153. * @param view_id The ID/Index of the view
  154. * @param previous_callback The previous callback function (can be set to NULL)
  155. * @param view_dispatcher The ViewDispatcher object
  156. * @return true if successful, false otherwise
  157. */
  158. bool easy_flipper_set_uart_text_input(
  159. TextInput **uart_text_input,
  160. int32_t view_id,
  161. char *header_text,
  162. char *uart_text_input_temp_buffer,
  163. uint32_t uart_text_input_buffer_size,
  164. void (*result_callback)(void *),
  165. uint32_t(previous_callback)(void *),
  166. ViewDispatcher **view_dispatcher,
  167. void *context);
  168. /**
  169. * @brief Initialize a DialogEx object
  170. * @param dialog_ex The DialogEx object to initialize
  171. * @param view_id The ID/Index of the view
  172. * @param header The header of the dialog
  173. * @param header_x The x coordinate of the header
  174. * @param header_y The y coordinate of the header
  175. * @param text The text of the dialog
  176. * @param text_x The x coordinate of the dialog
  177. * @param text_y The y coordinate of the dialog
  178. * @param left_button_text The text of the left button
  179. * @param right_button_text The text of the right button
  180. * @param center_button_text The text of the center button
  181. * @param result_callback The result callback function
  182. * @param previous_callback The previous callback function (can be set to NULL)
  183. * @param view_dispatcher The ViewDispatcher object
  184. * @param context The context to pass to the result callback
  185. * @return true if successful, false otherwise
  186. */
  187. bool easy_flipper_set_dialog_ex(
  188. DialogEx **dialog_ex,
  189. int32_t view_id,
  190. char *header,
  191. uint16_t header_x,
  192. uint16_t header_y,
  193. char *text,
  194. uint16_t text_x,
  195. uint16_t text_y,
  196. char *left_button_text,
  197. char *right_button_text,
  198. char *center_button_text,
  199. void (*result_callback)(DialogExResult, void *),
  200. uint32_t(previous_callback)(void *),
  201. ViewDispatcher **view_dispatcher,
  202. void *context);
  203. /**
  204. * @brief Initialize a Popup object
  205. * @param popup The Popup object to initialize
  206. * @param view_id The ID/Index of the view
  207. * @param header The header of the dialog
  208. * @param header_x The x coordinate of the header
  209. * @param header_y The y coordinate of the header
  210. * @param text The text of the dialog
  211. * @param text_x The x coordinate of the dialog
  212. * @param text_y The y coordinate of the dialog
  213. * @param result_callback The result callback function
  214. * @param previous_callback The previous callback function (can be set to NULL)
  215. * @param view_dispatcher The ViewDispatcher object
  216. * @param context The context to pass to the result callback
  217. * @return true if successful, false otherwise
  218. */
  219. bool easy_flipper_set_popup(
  220. Popup **popup,
  221. int32_t view_id,
  222. char *header,
  223. uint16_t header_x,
  224. uint16_t header_y,
  225. char *text,
  226. uint16_t text_x,
  227. uint16_t text_y,
  228. void (*result_callback)(void *),
  229. uint32_t(previous_callback)(void *),
  230. ViewDispatcher **view_dispatcher,
  231. void *context);
  232. /**
  233. * @brief Initialize a Loading object
  234. * @param loading The Loading object to initialize
  235. * @param view_id The ID/Index of the view
  236. * @param previous_callback The previous callback function (can be set to NULL)
  237. * @param view_dispatcher The ViewDispatcher object
  238. * @return true if successful, false otherwise
  239. */
  240. bool easy_flipper_set_loading(
  241. Loading **loading,
  242. int32_t view_id,
  243. uint32_t(previous_callback)(void *),
  244. ViewDispatcher **view_dispatcher);
  245. /**
  246. * @brief Set a char butter to a FuriString
  247. * @param furi_string The FuriString object
  248. * @param buffer The buffer to copy the string to
  249. * @return true if successful, false otherwise
  250. */
  251. bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer);
  252. #endif