view_port.h 1.9 KB

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