widget.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <input/input.h>
  3. #include "canvas.h"
  4. typedef struct Widget Widget;
  5. /*
  6. * Widget Draw callback
  7. * @warning called from GUI thread
  8. */
  9. typedef void (*WidgetDrawCallback)(Canvas* api, void* context);
  10. /*
  11. * Widget Input callback
  12. * @warning called from GUI thread
  13. */
  14. typedef void (*WidgetInputCallback)(InputEvent* event, void* context);
  15. /*
  16. * Widget allocator
  17. * always returns widget or stops system if not enough memory.
  18. */
  19. Widget* widget_alloc();
  20. /*
  21. * Widget deallocator
  22. * Ensure that widget was unregistered in GUI system before use.
  23. */
  24. void widget_free(Widget* widget);
  25. /*
  26. * Set widget width.
  27. * Will be used to limit canvas drawing area and autolayout feature.
  28. * @param width - wanted width, 0 - auto.
  29. */
  30. void widget_set_width(Widget* widget, uint8_t width);
  31. uint8_t widget_get_width(Widget* widget);
  32. /*
  33. * Set widget height.
  34. * Will be used to limit canvas drawing area and autolayout feature.
  35. * @param height - wanted height, 0 - auto.
  36. */
  37. void widget_set_height(Widget* widget, uint8_t height);
  38. uint8_t widget_get_height(Widget* widget);
  39. /*
  40. * Enable or disable widget rendering.
  41. * @param enabled.
  42. */
  43. void widget_enabled_set(Widget* widget, bool enabled);
  44. bool widget_is_enabled(Widget* widget);
  45. /*
  46. * Widget event callbacks
  47. * @param callback - appropriate callback function
  48. * @param context - context to pass to callback
  49. */
  50. void widget_draw_callback_set(Widget* widget, WidgetDrawCallback callback, void* context);
  51. void widget_input_callback_set(Widget* widget, WidgetInputCallback callback, void* context);
  52. /*
  53. * Emit update signal to GUI system.
  54. * Rendering will happen later after GUI system process signal.
  55. */
  56. void widget_update(Widget* widget);