BsGUITabbedTitleBar.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUIElementContainer.h"
  4. #include "BsRect2I.h"
  5. #include "BsEvent.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Tabbed title bar to be used in editor windows. Displays tabs that can
  10. * be activated, reordered by dragging, or dragged off and on to/on other title bars.
  11. */
  12. class GUITabbedTitleBar : public GUIElementContainer
  13. {
  14. public:
  15. /**
  16. * Returns type name of the GUI element used for finding GUI element styles.
  17. */
  18. static const String& getGUITypeName();
  19. /**
  20. * @brief Creates a new GUI foldout element.
  21. *
  22. * @param backgroundStyle GUI style to display the background in. Keep as blank for default.
  23. * @param backgroundStyle GUI style to display the tab buttons in. Keep as blank for default.
  24. * @param maxBtnStyle GUI style to display the maximize button in. Keep as blank for default.
  25. * @param closeBtnStyle GUI style to display the close button in. Keep as blank for default.
  26. */
  27. static GUITabbedTitleBar* create(const String& backgroundStyle = StringUtil::BLANK, const String& tabBtnStyle = StringUtil::BLANK,
  28. const String& maxBtnStyle = StringUtil::BLANK, const String& closeBtnStyle = StringUtil::BLANK);
  29. /**
  30. * @brief Creates a new GUI foldout element.
  31. *
  32. *
  33. * @param options Options that allow you to control how is the element positioned and sized.
  34. * This will override any similar options set by style.
  35. * @param backgroundStyle GUI style to display the background in. Keep as blank for default.
  36. * @param backgroundStyle GUI style to display the tab buttons in. Keep as blank for default.
  37. * @param maxBtnStyle GUI style to display the maximize button in. Keep as blank for default.
  38. * @param closeBtnStyle GUI style to display the close button in. Keep as blank for default.
  39. */
  40. static GUITabbedTitleBar* create(const GUIOptions& options,
  41. const String& backgroundStyle = StringUtil::BLANK, const String& tabBtnStyle = StringUtil::BLANK,
  42. const String& maxBtnStyle = StringUtil::BLANK, const String& closeBtnStyle = StringUtil::BLANK);
  43. /**
  44. * @brief Adds a new tab to the end of the tab list.
  45. *
  46. * @param name Title to display on the tab button.
  47. *
  48. * @returns A unique index (not sequential) that you may use for later identifying the tab.
  49. */
  50. UINT32 addTab(const HString& name);
  51. /**
  52. * @brief Inserts a new tab button at the specified position.
  53. *
  54. * @param position Sequential index to insert the tab button in. This will be clamped
  55. * to a valid range.
  56. * @param name Title to display on the tab button.
  57. *
  58. * @returns A unique index (not sequential) that you may use for later identifying the tab.
  59. */
  60. UINT32 insertTab(UINT32 position, const HString& name);
  61. /**
  62. * @brief Removes the tab button with the specified unique index.
  63. */
  64. void removeTab(UINT32 uniqueIdx);
  65. /**
  66. * @brief Activates the tab button with the specified unique index.
  67. */
  68. void setActive(UINT32 uniqueIdx);
  69. /**
  70. * @brief Finds the unique tab index from the provided sequential tab position.
  71. */
  72. UINT32 getTabIdx(UINT32 position) const;
  73. /**
  74. * @brief Returns the total number of display tab buttons.
  75. */
  76. UINT32 getNumTabs() const { return (UINT32)mTabButtons.size(); }
  77. /**
  78. * @brief Changes the displayed title for a tab with the specified index.
  79. */
  80. void updateTabName(UINT32 uniqueIdx, const HString& name);
  81. /**
  82. * @brief Calculates areas between the tab buttons and other GUI elements on the title bar.
  83. * These areas are normally used for setting up valid areas the user can click on and drag
  84. * the window the title bar belongs to.
  85. */
  86. Vector<Rect2I> calcDraggableAreas(INT32 x, INT32 y, UINT32 width, UINT32 height) const;
  87. /**
  88. * @brief Triggered when the active tab changes. Provided parameter is the
  89. * unique index of the activated tab.
  90. */
  91. Event<void(UINT32)> onTabActivated;
  92. /**
  93. * @brief Triggered when a tab is closed. Provided parameter is the
  94. * unique index of the closed tab.
  95. */
  96. Event<void(UINT32)> onTabClosed;
  97. /**
  98. * @brief Triggered when a tab maximize button is clicked. Provided parameter is the
  99. * unique index of the maximized/restored tab.
  100. */
  101. Event<void(UINT32)> onTabMaximized;
  102. /**
  103. * @brief Triggered when a tab gets dragged off the title bar. Provided
  104. * parameter is the unique index of the activated tab.
  105. */
  106. Event<void(UINT32)> onTabDraggedOff;
  107. /**
  108. * @brief Triggered when a new tab gets dragged on the title bar. Provided
  109. * parameter is the sequential index of the activated tab.
  110. */
  111. Event<void(UINT32)> onTabDraggedOn;
  112. protected:
  113. GUITabbedTitleBar(const String& backgroundStyle, const String& tabBtnStyle,
  114. const String& minBtnStyle, const String& closeBtnStyle, const GUIDimensions& dimensions);
  115. virtual ~GUITabbedTitleBar();
  116. /**
  117. * @copydoc GUIElementContainer::updateClippedBounds
  118. */
  119. void updateClippedBounds() override;
  120. /**
  121. * @copydoc GUIElementContainer::_getOptimalSize
  122. */
  123. Vector2I _getOptimalSize() const override;
  124. /**
  125. * @copydoc GUIElementContainer::_updateLayoutInternal
  126. */
  127. void _updateLayoutInternal(const GUILayoutData& data) override;
  128. /**
  129. * @copydoc GUIElementContainer::_mouseEvent
  130. */
  131. virtual bool _mouseEvent(const GUIMouseEvent& ev) override;
  132. /**
  133. * @brief Starts the internal drag and drop operation.
  134. *
  135. * @param seqIdx Sequential index of the dragged tab.
  136. * @param startDragPos Pointer position of where the drag originated, relative
  137. * to parent widget.
  138. */
  139. void startDrag(UINT32 seqIdx, const Vector2I& startDragPos);
  140. /**
  141. * @brief Ends the internal drag and drop operation started with ::startDrag.
  142. */
  143. void endDrag();
  144. /**
  145. * @brief Triggered when a tab button is toggled on or off.
  146. *
  147. * @param tabIdx Unique index of the tab.
  148. * @param toggledOn Whether the tab was activated or deactivated.
  149. */
  150. void tabToggled(UINT32 tabIdx, bool toggledOn);
  151. /**
  152. * @brief Triggered when the close button is pressed.
  153. */
  154. void tabClosed();
  155. /**
  156. * @brief Triggered when the maximize button is pressed.
  157. */
  158. void tabMaximize();
  159. /**
  160. * @brief Triggered every frame while a tab button is being dragged.
  161. *
  162. * @param tabIdx Unique index of the dragged tab.
  163. * @param dragPos Position of the pointer, relative to parent widget.
  164. */
  165. void tabDragged(UINT32 tabIdx, const Vector2I& dragPos);
  166. /**
  167. * @brief Triggered when a drag operation on a tab button ends.
  168. *
  169. * @param tabIdx Unique index of the dragged tab.
  170. * @param dragPos Position of the pointer, relative to parent widget.
  171. */
  172. void tabDragEnd(UINT32 tabIdx, const Vector2I& dragPos);
  173. /**
  174. * @brief Converts unique tab index to a sequential index corresponding to the
  175. * tab's position in the title bar.
  176. */
  177. INT32 uniqueIdxToSeqIdx(UINT32 uniqueIdx) const;
  178. static const INT32 TAB_SPACING;
  179. static const INT32 FIRST_TAB_OFFSET;
  180. static const INT32 OPTION_BTN_SPACING;
  181. static const INT32 OPTION_BTN_RIGHT_OFFSET;
  182. Vector<GUITabButton*> mTabButtons;
  183. UINT32 mUniqueTabIdx;
  184. UINT32 mActiveTabIdx;
  185. GUITexture* mBackgroundImage;
  186. GUIButton* mMaxBtn;
  187. GUIButton* mCloseBtn;
  188. GUIToggleGroupPtr mTabToggleGroup;
  189. EditorWidgetBase* mTempDraggedWidget;
  190. UINT32 mTempDraggedTabIdx;
  191. bool mDragInProgress;
  192. GUITabButton* mDraggedBtn;
  193. INT32 mDragBtnOffset;
  194. INT32 mInitialDragOffset;
  195. String mBackgroundStyle;
  196. String mCloseBtnStyle;
  197. String mMaximizeBtnStyle;
  198. String mTabBtnStyle;
  199. };
  200. }