BsGUITabButton.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. * @brief Changes the button state to dragged or not dragged, resulting primarily
  79. * in a visual change.
  80. *
  81. * @note Internal method.
  82. */
  83. void _setDraggedState(bool active);
  84. /**
  85. * @brief Triggered when the user starts dragging the tab button. Reported parameters
  86. * are the unique index of the tab and pointer position relative to parent GUIWidget.
  87. */
  88. Event<void(UINT32, const Vector2I&)> onDragged;
  89. /**
  90. * @brief Triggered when the user ends dragging the tab button. Reported parameters
  91. * are the unique index of the tab and pointer position relative to parent GUIWidget.
  92. */
  93. Event<void(UINT32, const Vector2I&)> onDragEnd;
  94. protected:
  95. GUITabButton(const String& styleName, const GUIToggleGroupPtr& toggleGroup, UINT32 index, const GUIContent& content, const GUIDimensions& dimensions);
  96. /**
  97. * @copydoc GUIElement::_mouseEvent
  98. */
  99. virtual bool _mouseEvent(const GUIMouseEvent& ev) override;
  100. UINT32 mIndex;
  101. Vector2I mDragStartPosition;
  102. bool mDraggedState;
  103. GUIButtonState mInactiveState;
  104. static const UINT32 DRAG_MIN_DISTANCE;
  105. };
  106. }