elements.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. /** Trim string buffer to fit width in pixels
  146. *
  147. * @param canvas Canvas instance
  148. * @param string string to trim
  149. * @param width max width
  150. */
  151. void elements_string_fit_width(Canvas* canvas, string_t string, uint8_t width);
  152. /** Draw text box element
  153. *
  154. * @param canvas Canvas instance
  155. * @param x x coordinate
  156. * @param y y coordinate
  157. * @param width width to fit text
  158. * @param height height to fit text
  159. * @param horizontal Align instance
  160. * @param vertical Align instance
  161. * @param[in] text Formatted text. The following formats are available:
  162. * "\e#Bold text\e#" - bold font is used
  163. * "\e*Monospaced text\e*" - monospaced font is used
  164. * "\e#Inversed text\e#" - white text on black background
  165. */
  166. void elements_text_box(
  167. Canvas* canvas,
  168. uint8_t x,
  169. uint8_t y,
  170. uint8_t width,
  171. uint8_t height,
  172. Align horizontal,
  173. Align vertical,
  174. const char* text);
  175. #ifdef __cplusplus
  176. }
  177. #endif