Layout.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef LAYOUT_H_
  2. #define LAYOUT_H_
  3. #include "Ref.h"
  4. #include "Touch.h"
  5. namespace gameplay
  6. {
  7. class Container;
  8. class Control;
  9. /**
  10. * The layout interface for UI containers.
  11. *
  12. * Implementations of this interface are responsible for positioning, resizing
  13. * and then calling update on all the controls within a container.
  14. */
  15. class Layout : public Ref
  16. {
  17. friend class Container;
  18. friend class Form;
  19. public:
  20. /**
  21. * Layout types available to containers.
  22. */
  23. enum Type
  24. {
  25. /**
  26. * Flow layout: Controls are placed next to one another horizontally
  27. * until the right-most edge of the container is reached, at which point
  28. * a new row is started.
  29. */
  30. LAYOUT_FLOW,
  31. /**
  32. * Vertical layout: Controls are placed next to one another vertically until
  33. * the bottom-most edge of the container is reached.
  34. */
  35. LAYOUT_VERTICAL,
  36. /**
  37. * Absolute layout: Controls are not modified at all by this layout.
  38. * They must be positioned and sized manually.
  39. */
  40. LAYOUT_ABSOLUTE,
  41. /**
  42. * Scroll layout: Controls may be placed outside the bounds of the container.
  43. * The user can then touch and drag to scroll. By default controls are placed
  44. * based on absolute positions in the .form file, but vertical or horizontal
  45. * automatic positioning is an available option.
  46. */
  47. LAYOUT_SCROLL
  48. };
  49. /**
  50. * Get the type of this layout.
  51. *
  52. * @return The type of this layout.
  53. */
  54. virtual Type getType() = 0;
  55. protected:
  56. /**
  57. * Position, resize, and update the controls within a container.
  58. *
  59. * @param container The container to update.
  60. */
  61. virtual void update(const Container* container) = 0;
  62. /**
  63. * Align a control within a container.
  64. *
  65. * @param control The control to align.
  66. * @param container The container to align the control within.
  67. */
  68. virtual void align(Control* control, const Container* container);
  69. /**
  70. * Touch callback on touch events. Coordinates are given relative to the container's
  71. * content area.
  72. *
  73. * @param evt The touch event that occurred.
  74. * @param x The x position of the touch in pixels. Left edge is zero.
  75. * @param y The y position of the touch in pixels. Top edge is zero.
  76. * @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
  77. *
  78. * @see Touch::TouchEvent
  79. */
  80. virtual bool touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex);
  81. };
  82. }
  83. #endif