BsEditorWidgetContainer.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsEvent.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief A GUI object that contains one or multiple editor widgets.
  8. * Each widget is represented by a single tab and can be activated,
  9. * deactivated, moved or dragged off.
  10. *
  11. * @note Internal class.
  12. */
  13. class BS_ED_EXPORT EditorWidgetContainer
  14. {
  15. public:
  16. EditorWidgetContainer(GUIWidget* parent, EditorWindowBase* parentEditorWindow);
  17. virtual ~EditorWidgetContainer();
  18. /**
  19. * @brief Adds a new widget to the container, adding a new tab to
  20. * the end of the tab bar.
  21. */
  22. void add(EditorWidgetBase& widget);
  23. /**
  24. * @brief Removes a widget from the container.
  25. */
  26. void remove(EditorWidgetBase& widget);
  27. /**
  28. * @brief Inserts a widget at the specified index, adding a new
  29. * tab at that position.
  30. *
  31. * @param idx Sequential index where to insert the widget.
  32. * @param widget Widget to insert.
  33. */
  34. void insert(UINT32 idx, EditorWidgetBase& widget);
  35. /**
  36. * @brief Checks if the container already contains the provided widget.
  37. */
  38. bool contains(EditorWidgetBase& widget);
  39. /**
  40. * @brief Sets the size of the container in pixels. This also modifies
  41. * the size of all child widgets.
  42. */
  43. void setSize(UINT32 width, UINT32 height);
  44. /**
  45. * @brief Sets the position of the container, relative to the parent
  46. * GUI widget. This also modifies the position of all child widgets.
  47. */
  48. void setPosition(INT32 x, INT32 y);
  49. /**
  50. * @brief Returns the number of widgets currently docked in this container.
  51. */
  52. UINT32 getNumWidgets() const { return (UINT32)mWidgets.size(); }
  53. /**
  54. * @brief Returns a widget at the specified index.
  55. *
  56. * @param idx Sequential index of the widget to retrieve.
  57. */
  58. EditorWidgetBase* getWidget(UINT32 idx) const;
  59. /**
  60. * @brief Returns a widget that is currently visible (its tab is active).
  61. */
  62. EditorWidgetBase* getActiveWidget() const;
  63. /**
  64. * @brief Returns the parent GUI widget the container is using to render the GUI on.
  65. */
  66. GUIWidget& getParentWidget() const { return *mParent; }
  67. /**
  68. * @brief Returns the parent editor window the container is docked in.
  69. */
  70. EditorWindowBase* getParentWindow() const { return mParentWindow; }
  71. /**
  72. * @brief Returns bounds not including the tabbed title bar. These are the bounds
  73. * available to child widget GUI.
  74. */
  75. Rect2I getContentBounds() const;
  76. /**
  77. * @brief Returns a list of areas that can be dragged off. These are normally areas
  78. * represented by tab buttons.
  79. */
  80. Vector<Rect2I> getDraggableAreas() const;
  81. /**
  82. * @brief Called once per frame. Calls update on all docked widgets.
  83. */
  84. void update();
  85. /**
  86. * @brief Updates the tabbed title bar by refreshing the names of all docked widgets.
  87. */
  88. void refreshWidgetNames();
  89. /**
  90. * @brief Triggers when a widget is about to be destroyed.
  91. */
  92. void _notifyWidgetDestroyed(EditorWidgetBase* widget);
  93. Event<void()> onWidgetAdded; /**< Triggered whenever a new widget is added to this container. */
  94. Event<void()> onWidgetClosed; /**< Triggered whenever a widget docked in this container is closed. */
  95. private:
  96. EditorWindowBase* mParentWindow;
  97. GUITabbedTitleBar* mTitleBar;
  98. GUIPanel* mTitleBarPanel;
  99. GUIWidget* mParent;
  100. INT32 mX, mY;
  101. UINT32 mWidth, mHeight;
  102. UnorderedMap<UINT32, EditorWidgetBase*> mWidgets;
  103. INT32 mActiveWidget;
  104. static const UINT32 TitleBarHeight;
  105. /**
  106. * @brief Removes a widget without triggering a widget closed event.
  107. */
  108. void removeInternal(EditorWidgetBase& widget);
  109. /**
  110. * @brief Changes the currently active widget to the one at the specified index. Making
  111. * the widget active means it will be visible in the container.
  112. *
  113. * @param idx Unique widget index (not sequential).
  114. */
  115. void setActiveWidget(UINT32 idx);
  116. /**
  117. * @brief Triggered when a user clicks on a tab in the tabbed title bar.
  118. *
  119. * @param idx Unique widget index (not sequential) of the tab that was activated.
  120. */
  121. void tabActivated(UINT32 idx);
  122. /**
  123. * @brief Triggered when a user closes a tab in the tabbed title bar.
  124. *
  125. * @param idx Unique widget index (not sequential) of the tab that was closed.
  126. */
  127. void tabClosed(UINT32 idx);
  128. /**
  129. * @brief Triggered when a user drags a tab off the tabbed title bar.
  130. *
  131. * @param idx Unique widget index (not sequential) of the tab that was dragged off.
  132. */
  133. void tabDraggedOff(UINT32 idx);
  134. /**
  135. * @brief Triggered when a user drags a tab on the tabbed title bar.
  136. *
  137. * @param idx Sequential index at the position on which the tab has been dragged on.
  138. */
  139. void tabDraggedOn(UINT32 idx);
  140. /**
  141. * @brief Triggered when the widget drag and drop operation finishes.
  142. *
  143. * @param wasDragProcessed Signals whether any object handled the drop.
  144. */
  145. static void tabDroppedCallback(bool wasDragProcessed);
  146. };
  147. }