widget.h 1.7 KB

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