elements.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 <m-string.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 scrollbar on canvas at specific position.
  29. *
  30. * @param canvas Canvas instance
  31. * @param x scrollbar position on X axis
  32. * @param y scrollbar position on Y axis
  33. * @param height scrollbar height
  34. * @param pos current element
  35. * @param total total elements
  36. */
  37. void elements_scrollbar_pos(
  38. Canvas* canvas,
  39. uint8_t x,
  40. uint8_t y,
  41. uint8_t height,
  42. uint16_t pos,
  43. uint16_t total);
  44. /** Draw scrollbar on canvas.
  45. * @note width 3px, height equal to canvas height
  46. *
  47. * @param canvas Canvas instance
  48. * @param pos current element of total elements
  49. * @param total total elements
  50. */
  51. void elements_scrollbar(Canvas* canvas, uint16_t pos, uint16_t total);
  52. /** Draw rounded frame
  53. *
  54. * @param canvas Canvas instance
  55. * @param x, y top left corner coordinates
  56. * @param width, height frame width and height
  57. */
  58. void elements_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  59. /** Draw button in left corner
  60. *
  61. * @param canvas Canvas instance
  62. * @param str button text
  63. */
  64. void elements_button_left(Canvas* canvas, const char* str);
  65. /** Draw button in right corner
  66. *
  67. * @param canvas Canvas instance
  68. * @param str button text
  69. */
  70. void elements_button_right(Canvas* canvas, const char* str);
  71. /** Draw button in center
  72. *
  73. * @param canvas Canvas instance
  74. * @param str button text
  75. */
  76. void elements_button_center(Canvas* canvas, const char* str);
  77. /** Draw aligned multiline text
  78. *
  79. * @param canvas Canvas instance
  80. * @param x, y coordinates based on align param
  81. * @param horizontal, vertical aligment of multiline text
  82. * @param text string (possible multiline)
  83. */
  84. void elements_multiline_text_aligned(
  85. Canvas* canvas,
  86. uint8_t x,
  87. uint8_t y,
  88. Align horizontal,
  89. Align vertical,
  90. const char* text);
  91. /** Draw multiline text
  92. *
  93. * @param canvas Canvas instance
  94. * @param x, y top left corner coordinates
  95. * @param text string (possible multiline)
  96. */
  97. void elements_multiline_text(Canvas* canvas, uint8_t x, uint8_t y, const char* text);
  98. /** Draw framed multiline text
  99. *
  100. * @param canvas Canvas instance
  101. * @param x, y top left corner coordinates
  102. * @param text string (possible multiline)
  103. */
  104. void elements_multiline_text_framed(Canvas* canvas, uint8_t x, uint8_t y, const char* text);
  105. /** Draw slightly rounded frame
  106. *
  107. * @param canvas Canvas instance
  108. * @param x, y top left corner coordinates
  109. * @param width, height size of frame
  110. */
  111. void elements_slightly_rounded_frame(
  112. Canvas* canvas,
  113. uint8_t x,
  114. uint8_t y,
  115. uint8_t width,
  116. uint8_t height);
  117. /** Draw slightly rounded box
  118. *
  119. * @param canvas Canvas instance
  120. * @param x, y top left corner coordinates
  121. * @param width, height size of box
  122. */
  123. void elements_slightly_rounded_box(
  124. Canvas* canvas,
  125. uint8_t x,
  126. uint8_t y,
  127. uint8_t width,
  128. uint8_t height);
  129. /** Draw bold rounded frame
  130. *
  131. * @param canvas Canvas instance
  132. * @param x, y top left corner coordinates
  133. * @param width, height size of frame
  134. */
  135. void elements_bold_rounded_frame(
  136. Canvas* canvas,
  137. uint8_t x,
  138. uint8_t y,
  139. uint8_t width,
  140. uint8_t height);
  141. /** Draw bubble frame for text
  142. *
  143. * @param canvas Canvas instance
  144. * @param x left x coordinates
  145. * @param y top y coordinate
  146. * @param width bubble width
  147. * @param height bubble height
  148. */
  149. void elements_bubble(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  150. /** Draw bubble frame for text with corner
  151. *
  152. * @param canvas Canvas instance
  153. * @param x left x coordinates
  154. * @param y top y coordinate
  155. * @param width bubble width
  156. * @param height bubble height
  157. * @param horizontal horizontal aligning
  158. * @param vertical aligning
  159. */
  160. void elements_bubble_str(
  161. Canvas* canvas,
  162. uint8_t x,
  163. uint8_t y,
  164. const char* text,
  165. Align horizontal,
  166. Align vertical);
  167. /** Trim string buffer to fit width in pixels
  168. *
  169. * @param canvas Canvas instance
  170. * @param string string to trim
  171. * @param width max width
  172. */
  173. void elements_string_fit_width(Canvas* canvas, string_t string, uint8_t width);
  174. /** Draw text box element
  175. *
  176. * @param canvas Canvas instance
  177. * @param x x coordinate
  178. * @param y y coordinate
  179. * @param width width to fit text
  180. * @param height height to fit text
  181. * @param horizontal Align instance
  182. * @param vertical Align instance
  183. * @param[in] text Formatted text. The following formats are available:
  184. * "\e#Bold text\e#" - bold font is used
  185. * "\e*Monospaced text\e*" - monospaced font is used
  186. * "\e#Inversed text\e#" - white text on black background
  187. */
  188. void elements_text_box(
  189. Canvas* canvas,
  190. uint8_t x,
  191. uint8_t y,
  192. uint8_t width,
  193. uint8_t height,
  194. Align horizontal,
  195. Align vertical,
  196. const char* text);
  197. #ifdef __cplusplus
  198. }
  199. #endif