view_port.h 2.7 KB

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