Widget.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <anki/ui/UiObject.h>
  7. #include <anki/util/Hierarchy.h>
  8. #include <anki/util/Bitset.h>
  9. namespace anki
  10. {
  11. /// @addtogroup ui
  12. /// @{
  13. /// Widget state.
  14. enum class WidgetState : U8
  15. {
  16. DEFAULT,
  17. HOVER,
  18. ACTIVATED,
  19. VISIBLE,
  20. ENABLED
  21. };
  22. /// UI widget.
  23. class Widget : public UiObject, private Hierarchy<Widget>
  24. {
  25. ANKI_WIDGET
  26. friend Hierarchy<Widget>;
  27. public:
  28. Widget(Canvas* canvas);
  29. ~Widget();
  30. void markForDeletion();
  31. Bool isMarkedForDeletion() const
  32. {
  33. return m_flags.bitsEnabled(MARKED_FOR_DELETION);
  34. }
  35. virtual void paint()
  36. {
  37. }
  38. /// Set position relatively to the parent.
  39. void setRelativePosition(const UVec2& pos);
  40. const UVec2& getRelativePosition() const
  41. {
  42. return m_posLocal;
  43. }
  44. const UVec2& getCanvasPosition() const
  45. {
  46. return m_posCanvas;
  47. }
  48. /// Set prefered size.
  49. void setSize(const UVec2& size);
  50. const UVec2& getSize() const
  51. {
  52. return m_size;
  53. }
  54. /// Set the limts of size. The widget cannot exceede those.
  55. void setSizeLimits(const UVec2& min, const UVec2& max);
  56. void addWidget(Widget* widget)
  57. {
  58. addChild(getAllocator(), widget);
  59. }
  60. void addWidgetGridLayout(Widget* widget, U colum, U row);
  61. Widget* getParentWidget()
  62. {
  63. return getParent();
  64. }
  65. const Widget* getParentWidget() const
  66. {
  67. return getParent();
  68. }
  69. #ifdef ANKI_BUILD
  70. void markForRepaint()
  71. {
  72. m_flags.enableBits(NEEDS_REPAINT, true);
  73. }
  74. Bool isMarkedForRepaint() const
  75. {
  76. return m_flags.bitsEnabled(NEEDS_REPAINT);
  77. }
  78. #endif
  79. private:
  80. enum
  81. {
  82. MARKED_FOR_DELETION = 1 << 0,
  83. NEEDS_REPAINT = 1 << 1
  84. };
  85. UVec2 m_minSize = UVec2(0u);
  86. UVec2 m_maxSize = UVec2(MAX_U32);
  87. UVec2 m_size = UVec2(0u);
  88. UVec2 m_posLocal = UVec2(0u); ///< Local space.
  89. UVec2 m_posCanvas = UVec2(0u); ///< World space.
  90. Bitset<U8> m_flags;
  91. };
  92. /// @}
  93. } // end namespace anki