widget.h 3.6 KB

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