elements.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. /** Draw progress bar.
  16. * @param x - progress bar position on X axis
  17. * @param y - progress bar position on Y axis
  18. * @param width - progress bar width
  19. * @param progress - progress in unnamed metric
  20. * @param total - total amount in unnamed metric
  21. */
  22. void elements_progress_bar(
  23. Canvas* canvas,
  24. uint8_t x,
  25. uint8_t y,
  26. uint8_t width,
  27. uint8_t progress,
  28. uint8_t total);
  29. /** Draw scrollbar on canvas at specific position.
  30. * @param x - scrollbar position on X axis
  31. * @param y - scrollbar position on Y axis
  32. * @param height - scrollbar height
  33. * @param pos - current element
  34. * @param total - total elements
  35. */
  36. void elements_scrollbar_pos(
  37. Canvas* canvas,
  38. uint8_t x,
  39. uint8_t y,
  40. uint8_t height,
  41. uint16_t pos,
  42. uint16_t total);
  43. /** Draw scrollbar on canvas.
  44. * width 3px, height equal to canvas height
  45. * @param pos - current element of total elements
  46. * @param total - total elements
  47. */
  48. void elements_scrollbar(Canvas* canvas, uint16_t pos, uint16_t total);
  49. /** Draw rounded frame
  50. * @param x, y - top left corner coordinates
  51. * @param width, height - frame width and height
  52. */
  53. void elements_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  54. /** Draw button in left corner
  55. * @param str - button text
  56. */
  57. void elements_button_left(Canvas* canvas, const char* str);
  58. /** Draw button in right corner
  59. * @param str - button text
  60. */
  61. void elements_button_right(Canvas* canvas, const char* str);
  62. /** Draw button in center
  63. * @param str - button text
  64. */
  65. void elements_button_center(Canvas* canvas, const char* str);
  66. /** Draw aligned multiline text
  67. * @param x, y - coordinates based on align param
  68. * @param horizontal, vertical - aligment of multiline text
  69. * @param text - string (possible multiline)
  70. */
  71. void elements_multiline_text_aligned(
  72. Canvas* canvas,
  73. uint8_t x,
  74. uint8_t y,
  75. Align horizontal,
  76. Align vertical,
  77. const char* text);
  78. /** Draw multiline text
  79. * @param x, y - top left corner coordinates
  80. * @param text - string (possible multiline)
  81. */
  82. void elements_multiline_text(Canvas* canvas, uint8_t x, uint8_t y, const char* text);
  83. /** Draw framed multiline text
  84. * @param x, y - top left corner coordinates
  85. * @param text - string (possible multiline)
  86. */
  87. void elements_multiline_text_framed(Canvas* canvas, uint8_t x, uint8_t y, const char* text);
  88. /** Draw slightly rounded frame
  89. * @param x, y - top left corner coordinates
  90. * @param width, height - size of frame
  91. */
  92. void elements_slightly_rounded_frame(
  93. Canvas* canvas,
  94. uint8_t x,
  95. uint8_t y,
  96. uint8_t width,
  97. uint8_t height);
  98. /** Draw slightly rounded box
  99. * @param x, y - top left corner coordinates
  100. * @param width, height - size of box
  101. */
  102. void elements_slightly_rounded_box(
  103. Canvas* canvas,
  104. uint8_t x,
  105. uint8_t y,
  106. uint8_t width,
  107. uint8_t height);
  108. /** Draw bubble frame for text
  109. * @param x - left x coordinates
  110. * @param y - top y coordinate
  111. * @param width - bubble width
  112. * @param height - bubble height
  113. */
  114. void elements_bubble(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
  115. /** Trim string buffer to fit width in pixels
  116. * @param string - string to trim
  117. * @param width - max width
  118. */
  119. void elements_string_fit_width(Canvas* canvas, string_t string, uint8_t width);
  120. #ifdef __cplusplus
  121. }
  122. #endif