view_port.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. typedef enum {
  9. ViewPortOrientationHorizontal,
  10. ViewPortOrientationVertical,
  11. } ViewPortOrientation;
  12. /*
  13. * ViewPort Draw callback
  14. * @warning called from GUI thread
  15. */
  16. typedef void (*ViewPortDrawCallback)(Canvas* canvas, void* context);
  17. /*
  18. * ViewPort Input callback
  19. * @warning called from GUI thread
  20. */
  21. typedef void (*ViewPortInputCallback)(InputEvent* event, void* context);
  22. /*
  23. * ViewPort allocator
  24. * always returns view_port or stops system if not enough memory.
  25. */
  26. ViewPort* view_port_alloc();
  27. /*
  28. * ViewPort deallocator
  29. * Ensure that view_port was unregistered in GUI system before use.
  30. */
  31. void view_port_free(ViewPort* view_port);
  32. /*
  33. * Set view_port width.
  34. * Will be used to limit canvas drawing area and autolayout feature.
  35. * @param width - wanted width, 0 - auto.
  36. */
  37. void view_port_set_width(ViewPort* view_port, uint8_t width);
  38. uint8_t view_port_get_width(ViewPort* view_port);
  39. /*
  40. * Set view_port height.
  41. * Will be used to limit canvas drawing area and autolayout feature.
  42. * @param height - wanted height, 0 - auto.
  43. */
  44. void view_port_set_height(ViewPort* view_port, uint8_t height);
  45. uint8_t view_port_get_height(ViewPort* view_port);
  46. /*
  47. * Enable or disable view_port rendering.
  48. * @param view_port - ViewPort instance
  49. * @param enabled
  50. * @warning automatically dispatches update event
  51. */
  52. void view_port_enabled_set(ViewPort* view_port, bool enabled);
  53. bool view_port_is_enabled(ViewPort* view_port);
  54. /*
  55. * ViewPort event callbacks
  56. * @param callback - appropriate callback function
  57. * @param context - context to pass to callback
  58. */
  59. void view_port_draw_callback_set(ViewPort* view_port, ViewPortDrawCallback callback, void* context);
  60. void view_port_input_callback_set(
  61. ViewPort* view_port,
  62. ViewPortInputCallback callback,
  63. void* context);
  64. /*
  65. * Emit update signal to GUI system.
  66. * Rendering will happen later after GUI system process signal.
  67. */
  68. void view_port_update(ViewPort* view_port);
  69. /*
  70. * Set ViewPort orientation.
  71. * @param orientation, display orientation, horizontal or vertical.
  72. */
  73. void view_port_set_orientation(ViewPort* view_port, ViewPortOrientation orientation);
  74. ViewPortOrientation view_port_get_orientation(const ViewPort* view_port);
  75. #ifdef __cplusplus
  76. }
  77. #endif