widget.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 Button Element
  97. *
  98. * @param widget Widget instance
  99. * @param button_type GuiButtonType instance
  100. * @param text text on allocated button
  101. * @param callback ButtonCallback instance
  102. * @param context pointer to context
  103. */
  104. void widget_add_button_element(
  105. Widget* widget,
  106. GuiButtonType button_type,
  107. const char* text,
  108. ButtonCallback callback,
  109. void* context);
  110. /** Add Icon Element
  111. *
  112. * @param widget Widget instance
  113. * @param x top left x coordinate
  114. * @param y top left y coordinate
  115. * @param icon Icon instance
  116. */
  117. void widget_add_icon_element(Widget* widget, uint8_t x, uint8_t y, const Icon* icon);
  118. /** Add Frame Element
  119. *
  120. * @param widget Widget instance
  121. * @param x top left x coordinate
  122. * @param y top left y coordinate
  123. * @param width frame width
  124. * @param height frame height
  125. * @param radius frame radius
  126. */
  127. void widget_add_frame_element(
  128. Widget* widget,
  129. uint8_t x,
  130. uint8_t y,
  131. uint8_t width,
  132. uint8_t height,
  133. uint8_t radius);
  134. #ifdef __cplusplus
  135. }
  136. #endif