widget.h 1.5 KB

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