widget.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * @file widget.h
  3. * GUI: Widget view module API
  4. */
  5. #pragma once
  6. #include <gui/view.h>
  7. #include "widget_elements/widget_element.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. typedef struct Widget Widget;
  12. typedef struct WidgetElement WidgetElement;
  13. /** Allocate Widget that holds Widget Elements
  14. *
  15. * @return Widget instance
  16. */
  17. Widget* widget_alloc();
  18. /** Free Widget
  19. * @note this function free allocated Widget Elements
  20. *
  21. * @param widget Widget instance
  22. */
  23. void widget_free(Widget* widget);
  24. /** Reset Widget
  25. *
  26. * @param widget Widget instance
  27. */
  28. void widget_reset(Widget* widget);
  29. /** Get Widget view
  30. *
  31. * @param widget Widget instance
  32. *
  33. * @return View instance
  34. */
  35. View* widget_get_view(Widget* widget);
  36. /** Add Multi String Element
  37. *
  38. * @param widget Widget instance
  39. * @param x x coordinate
  40. * @param y y coordinate
  41. * @param horizontal Align instance
  42. * @param vertical Align instance
  43. * @param font Font instance
  44. * @param[in] text The text
  45. */
  46. void widget_add_string_multiline_element(
  47. Widget* widget,
  48. uint8_t x,
  49. uint8_t y,
  50. Align horizontal,
  51. Align vertical,
  52. Font font,
  53. const char* text);
  54. /** Add String Element
  55. *
  56. * @param widget Widget instance
  57. * @param x x coordinate
  58. * @param y y coordinate
  59. * @param horizontal Align instance
  60. * @param vertical Align instance
  61. * @param font Font instance
  62. * @param[in] text The text
  63. */
  64. void widget_add_string_element(
  65. Widget* widget,
  66. uint8_t x,
  67. uint8_t y,
  68. Align horizontal,
  69. Align vertical,
  70. Font font,
  71. const char* text);
  72. /** Add Text Box Element
  73. *
  74. * @param widget Widget instance
  75. * @param x x coordinate
  76. * @param y y coordinate
  77. * @param width width to fit text
  78. * @param height height to fit text
  79. * @param horizontal Align instance
  80. * @param vertical Align instance
  81. * @param[in] text Formatted text. The following formats are available:
  82. * "\e#Bold text\e#" - bold font is used
  83. * "\e*Monospaced text\e*" - monospaced font is used
  84. * "\e#Inversed text\e#" - white text on black background
  85. * @param strip_to_dots Strip text to ... if does not fit to width
  86. */
  87. void widget_add_text_box_element(
  88. Widget* widget,
  89. uint8_t x,
  90. uint8_t y,
  91. uint8_t width,
  92. uint8_t height,
  93. Align horizontal,
  94. Align vertical,
  95. const char* text,
  96. bool strip_to_dots);
  97. /** Add Text Scroll Element
  98. *
  99. * @param widget Widget instance
  100. * @param x x coordinate
  101. * @param y y coordinate
  102. * @param width width to fit text
  103. * @param height height to fit text
  104. * @param[in] text Formatted text. Default format: align left, Secondary font.
  105. * The following formats are available:
  106. * "\e#Bold text" - sets bold font before until next '\n' symbol
  107. * "\ecCenter-aligned text" - sets center horizontal align until the next '\n' symbol
  108. * "\erRight-aligned text" - sets right horizontal align until the next '\n' symbol
  109. */
  110. void widget_add_text_scroll_element(
  111. Widget* widget,
  112. uint8_t x,
  113. uint8_t y,
  114. uint8_t width,
  115. uint8_t height,
  116. const char* text);
  117. /** Add Button Element
  118. *
  119. * @param widget Widget instance
  120. * @param button_type GuiButtonType instance
  121. * @param text text on allocated button
  122. * @param callback ButtonCallback instance
  123. * @param context pointer to context
  124. */
  125. void widget_add_button_element(
  126. Widget* widget,
  127. GuiButtonType button_type,
  128. const char* text,
  129. ButtonCallback callback,
  130. void* context);
  131. /** Add Icon Element
  132. *
  133. * @param widget Widget instance
  134. * @param x top left x coordinate
  135. * @param y top left y coordinate
  136. * @param icon Icon instance
  137. */
  138. void widget_add_icon_element(Widget* widget, uint8_t x, uint8_t y, const Icon* icon);
  139. /** Add Frame Element
  140. *
  141. * @param widget Widget instance
  142. * @param x top left x coordinate
  143. * @param y top left y coordinate
  144. * @param width frame width
  145. * @param height frame height
  146. * @param radius frame radius
  147. */
  148. void widget_add_frame_element(
  149. Widget* widget,
  150. uint8_t x,
  151. uint8_t y,
  152. uint8_t width,
  153. uint8_t height,
  154. uint8_t radius);
  155. #ifdef __cplusplus
  156. }
  157. #endif