elements.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /**
  2. * @file elements.h
  3. * GUI: Elements API
  4. *
  5. * Canvas helpers and UI building blocks.
  6. *
  7. */
  8. #pragma once
  9. #include <stdint.h>
  10. #include <furi.h>
  11. #include "canvas.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #define ELEMENTS_MAX_LINES_NUM (7)
  16. #define ELEMENTS_BOLD_MARKER '#'
  17. #define ELEMENTS_MONO_MARKER '*'
  18. #define ELEMENTS_INVERSED_MARKER '!'
  19. /** Draw progress bar.
  20. *
  21. * @param canvas Canvas instance
  22. * @param x progress bar position on X axis
  23. * @param y progress bar position on Y axis
  24. * @param width progress bar width
  25. * @param progress progress (0.0 - 1.0)
  26. */
  27. void elements_progress_bar(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, float progress);
  28. /** Draw progress bar with text.
  29. *
  30. * @param canvas Canvas instance
  31. * @param x progress bar position on X axis
  32. * @param y progress bar position on Y axis
  33. * @param width progress bar width
  34. * @param progress progress (0.0 - 1.0)
  35. * @param text text to draw
  36. */
  37. void elements_progress_bar_with_text(
  38. Canvas* canvas,
  39. uint8_t x,
  40. uint8_t y,
  41. uint8_t width,
  42. float progress,
  43. const char* text);
  44. /** Draw scrollbar on canvas at specific position.
  45. *
  46. * @param canvas Canvas instance
  47. * @param x scrollbar position on X axis
  48. * @param y scrollbar position on Y axis
  49. * @param height scrollbar height
  50. * @param pos current element
  51. * @param total total elements
  52. */
  53. void elements_scrollbar_pos(
  54. Canvas* canvas,
  55. uint8_t x,
  56. uint8_t y,
  57. uint8_t height,
  58. uint16_t pos,
  59. uint16_t total);
  60. /** Draw scrollbar on canvas.
  61. * @note width 3px, height equal to canvas height
  62. *
  63. * @param canvas Canvas instance
  64. * @param pos current element of total elements
  65. * @param total total elements
  66. */
  67. void elements_scrollbar(Canvas* canvas, uint16_t pos, uint16_t total);
  68. /** Draw rounded frame
  69. *
  70. * @param canvas Canvas instance
  71. * @param x, y top left corner coordinates
  72. * @param width, height frame width and height
  73. */
  74. void elements_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  75. /** Draw button in left corner
  76. *
  77. * @param canvas Canvas instance
  78. * @param str button text
  79. */
  80. void elements_button_left(Canvas* canvas, const char* str);
  81. /** Draw button in right corner
  82. *
  83. * @param canvas Canvas instance
  84. * @param str button text
  85. */
  86. void elements_button_right(Canvas* canvas, const char* str);
  87. /** Draw button in center
  88. *
  89. * @param canvas Canvas instance
  90. * @param str button text
  91. */
  92. void elements_button_center(Canvas* canvas, const char* str);
  93. /** Draw aligned multiline text
  94. *
  95. * @param canvas Canvas instance
  96. * @param x, y coordinates based on align param
  97. * @param horizontal, vertical alignment of multiline text
  98. * @param text string (possible multiline)
  99. */
  100. void elements_multiline_text_aligned(
  101. Canvas* canvas,
  102. uint8_t x,
  103. uint8_t y,
  104. Align horizontal,
  105. Align vertical,
  106. const char* text);
  107. /** Draw multiline text
  108. *
  109. * @param canvas Canvas instance
  110. * @param x, y top left corner coordinates
  111. * @param text string (possible multiline)
  112. */
  113. void elements_multiline_text(Canvas* canvas, uint8_t x, uint8_t y, const char* text);
  114. /** Draw framed multiline text
  115. *
  116. * @param canvas Canvas instance
  117. * @param x, y top left corner coordinates
  118. * @param text string (possible multiline)
  119. */
  120. void elements_multiline_text_framed(Canvas* canvas, uint8_t x, uint8_t y, const char* text);
  121. /** Draw slightly rounded frame
  122. *
  123. * @param canvas Canvas instance
  124. * @param x, y top left corner coordinates
  125. * @param width, height size of frame
  126. */
  127. void elements_slightly_rounded_frame(
  128. Canvas* canvas,
  129. uint8_t x,
  130. uint8_t y,
  131. uint8_t width,
  132. uint8_t height);
  133. /** Draw slightly rounded box
  134. *
  135. * @param canvas Canvas instance
  136. * @param x, y top left corner coordinates
  137. * @param width, height size of box
  138. */
  139. void elements_slightly_rounded_box(
  140. Canvas* canvas,
  141. uint8_t x,
  142. uint8_t y,
  143. uint8_t width,
  144. uint8_t height);
  145. /** Draw bold rounded frame
  146. *
  147. * @param canvas Canvas instance
  148. * @param x, y top left corner coordinates
  149. * @param width, height size of frame
  150. */
  151. void elements_bold_rounded_frame(
  152. Canvas* canvas,
  153. uint8_t x,
  154. uint8_t y,
  155. uint8_t width,
  156. uint8_t height);
  157. /** Draw bubble frame for text
  158. *
  159. * @param canvas Canvas instance
  160. * @param x left x coordinates
  161. * @param y top y coordinate
  162. * @param width bubble width
  163. * @param height bubble height
  164. */
  165. void elements_bubble(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  166. /** Draw bubble frame for text with corner
  167. *
  168. * @param canvas Canvas instance
  169. * @param x left x coordinates
  170. * @param y top y coordinate
  171. * @param width bubble width
  172. * @param height bubble height
  173. * @param horizontal horizontal aligning
  174. * @param vertical aligning
  175. */
  176. void elements_bubble_str(
  177. Canvas* canvas,
  178. uint8_t x,
  179. uint8_t y,
  180. const char* text,
  181. Align horizontal,
  182. Align vertical);
  183. /** Trim string buffer to fit width in pixels
  184. *
  185. * @param canvas Canvas instance
  186. * @param string string to trim
  187. * @param width max width
  188. */
  189. void elements_string_fit_width(Canvas* canvas, FuriString* string, uint8_t width);
  190. /** Draw scrollable text line
  191. *
  192. * @param canvas The canvas
  193. * @param[in] x X coordinate
  194. * @param[in] y Y coordinate
  195. * @param[in] width The width
  196. * @param string The string
  197. * @param[in] scroll The scroll counter: 0 - no scroll, any other number - scroll. Just count up, everything else will be calculated on the inside.
  198. * @param[in] ellipsis The ellipsis flag: true to add ellipse
  199. */
  200. void elements_scrollable_text_line(
  201. Canvas* canvas,
  202. uint8_t x,
  203. uint8_t y,
  204. uint8_t width,
  205. FuriString* string,
  206. size_t scroll,
  207. bool ellipsis);
  208. /** Draw text box element
  209. *
  210. * @param canvas Canvas instance
  211. * @param x x coordinate
  212. * @param y y coordinate
  213. * @param width width to fit text
  214. * @param height height to fit text
  215. * @param horizontal Align instance
  216. * @param vertical Align instance
  217. * @param[in] text Formatted text. The following formats are available:
  218. * "\e#Bold text\e#" - bold font is used
  219. * "\e*Monospaced text\e*" - monospaced font is used
  220. * "\e!Inversed text\e!" - white text on black background
  221. * @param strip_to_dots Strip text to ... if does not fit to width
  222. */
  223. void elements_text_box(
  224. Canvas* canvas,
  225. uint8_t x,
  226. uint8_t y,
  227. uint8_t width,
  228. uint8_t height,
  229. Align horizontal,
  230. Align vertical,
  231. const char* text,
  232. bool strip_to_dots);
  233. #ifdef __cplusplus
  234. }
  235. #endif