elements.h 5.6 KB

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