widget.h 4.6 KB

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