BsGUITabButton.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUIToggle.h"
  4. #include "BsGUIToggleGroup.h"
  5. #include "BsImageSprite.h"
  6. #include "BsEvent.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * @brief Specialization of a GUIToggle element used for displaying
  11. * tabs in a GUITabbedTitleBar. Aside from being toggleable these
  12. * buttons also track drag and drop operations.
  13. */
  14. class GUITabButton : public GUIToggle
  15. {
  16. public:
  17. /**
  18. * Returns type name of the GUI element used for finding GUI element styles.
  19. */
  20. static const String& getGUITypeName();
  21. /**
  22. * @brief Creates a new GUI tab button element.
  23. *
  24. * @param toggleGroup A toggle group that forms a link between related tab buttons.
  25. * @param index Unique index that can be used for identifying a tab.
  26. * @param text Label to display in the button.
  27. * @param styleName Optional style to use for the element. Style will be retrieved
  28. * from GUISkin of the GUIWidget the element is used on. If not specified
  29. * default style is used.
  30. */
  31. static GUITabButton* create(const GUIToggleGroupPtr& toggleGroup, UINT32 index, const HString& text,
  32. const String& styleName = StringUtil::BLANK);
  33. /**
  34. * @brief Creates a new GUI tab button element.
  35. *
  36. * @param toggleGroup A toggle group that forms a link between related tab buttons.
  37. * @param index Unique index that can be used for identifying a tab.
  38. * @param text Label to display in the button.
  39. * @param options Options that allow you to control how is the element positioned and sized.
  40. * This will override any similar options set by style.
  41. * @param styleName Optional style to use for the element. Style will be retrieved
  42. * from GUISkin of the GUIWidget the element is used on. If not specified
  43. * default style is used.
  44. */
  45. static GUITabButton* create(const GUIToggleGroupPtr& toggleGroup, UINT32 index, const HString& text,
  46. const GUIOptions& options, const String& styleName = StringUtil::BLANK);
  47. /**
  48. * @brief Creates a new GUI tab button element.
  49. *
  50. * @param toggleGroup A toggle group that forms a link between related tab buttons.
  51. * @param index Unique index that can be used for identifying a tab.
  52. * @param content Content to display in the button.
  53. * @param styleName Optional style to use for the element. Style will be retrieved
  54. * from GUISkin of the GUIWidget the element is used on. If not specified
  55. * default style is used.
  56. */
  57. static GUITabButton* create(const GUIToggleGroupPtr& toggleGroup, UINT32 index, const GUIContent& content,
  58. const String& styleName = StringUtil::BLANK);
  59. /**
  60. * @brief Creates a new GUI tab button element.
  61. *
  62. * @param toggleGroup A toggle group that forms a link between related tab buttons.
  63. * @param index Unique index that can be used for identifying a tab.
  64. * @param content Content to display in the button.
  65. * @param options Options that allow you to control how is the element positioned and sized.
  66. * This will override any similar options set by style.
  67. * @param styleName Optional style to use for the element. Style will be retrieved
  68. * from GUISkin of the GUIWidget the element is used on. If not specified
  69. * default style is used.
  70. */
  71. static GUITabButton* create(const GUIToggleGroupPtr& toggleGroup, UINT32 index, const GUIContent& content,
  72. const GUIOptions& options, const String& styleName = StringUtil::BLANK);
  73. /**
  74. * @brief Returns the unique index for this tab button.
  75. */
  76. UINT32 getIndex() const { return mIndex; }
  77. /**
  78. * @copydoc GUIToggle::toggleOn
  79. */
  80. void toggleOn() override;
  81. /**
  82. * @copydoc GUIToggle::toggleOff
  83. */
  84. void toggleOff() override;
  85. /**
  86. * @brief Changes the button state to dragged or not dragged, resulting primarily
  87. * in a visual change.
  88. *
  89. * @note Internal method.
  90. */
  91. void _setDraggedState(bool active);
  92. /**
  93. * @brief Triggered when the user starts dragging the tab button. Reported parameters
  94. * are the unique index of the tab and pointer position relative to parent GUIWidget.
  95. */
  96. Event<void(UINT32, const Vector2I&)> onDragged;
  97. /**
  98. * @brief Triggered when the user ends dragging the tab button. Reported parameters
  99. * are the unique index of the tab and pointer position relative to parent GUIWidget.
  100. */
  101. Event<void(UINT32, const Vector2I&)> onDragEnd;
  102. protected:
  103. GUITabButton(const String& styleName, const GUIToggleGroupPtr& toggleGroup, UINT32 index, const GUIContent& content, const GUIDimensions& dimensions);
  104. /**
  105. * @copydoc GUIElement::_mouseEvent
  106. */
  107. virtual bool _mouseEvent(const GUIMouseEvent& ev) override;
  108. UINT32 mIndex;
  109. Vector2I mDragStartPosition;
  110. bool mDraggedState;
  111. GUIButtonState mInactiveState;
  112. static const UINT32 DRAG_MIN_DISTANCE;
  113. };
  114. }