BsEditorWidgetManager.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsModule.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Handles opening and closing of EditorWidgets. Its primary purpose
  8. * is to keep track of all types of widgets so they can be saved and restored
  9. * upon program shutdown/startup, as well as being able to change widget layout on
  10. * the fly.
  11. */
  12. class BS_ED_EXPORT EditorWidgetManager : public Module<EditorWidgetManager>
  13. {
  14. public:
  15. EditorWidgetManager();
  16. ~EditorWidgetManager();
  17. /**
  18. * @brief Registers a widget that can then be opened by calling "open". When loading
  19. * a widget layout this name and callback will be used to attempt creating the widget.
  20. *
  21. * @param name Unique name for the widget.
  22. * @param createCallback Callback that returns a new instance of the widget.
  23. */
  24. void registerWidget(const String& name, std::function<EditorWidgetBase*(EditorWidgetContainer&)> createCallback);
  25. /**
  26. * @brief Creates a widget with the given name. If widget is already created it returns the existing instance.
  27. * Widget is opened in a new window.
  28. *
  29. * @param name The name of the widget.
  30. *
  31. * @return Always returns the created widget, and throws an exception if it fails.
  32. */
  33. EditorWidgetBase* open(const String& name);
  34. /**
  35. * @brief Creates a new widget an inserts it into the specified container.
  36. */
  37. EditorWidgetBase* create(const String& name, EditorWidgetContainer& parentContainer);
  38. /**
  39. * @brief Closes the given widget.
  40. */
  41. void close(EditorWidgetBase* widget);
  42. /**
  43. * @brief Retrieves the layout of all currently active widgets. You may later
  44. * use this layout to restore exact position of the widgets.
  45. */
  46. EditorWidgetLayoutPtr getLayout() const;
  47. /**
  48. * @brief Positions all widgets according to the provided layout. It will open
  49. * new widgets or close current ones if needed.
  50. */
  51. void setLayout(const EditorWidgetLayoutPtr& layout);
  52. /**
  53. * @brief Allows you to queue up widgets that will be registered as soon as an instance of EditorWidgetManager is
  54. * created.
  55. *
  56. * @note Useful primarily when widgets are being registered from static methods, because then there is no
  57. * EditorWidgetManager instance yet.
  58. */
  59. static void preRegisterWidget(const String& name, std::function<EditorWidgetBase*(EditorWidgetContainer&)> createCallback);
  60. private:
  61. Map<String, EditorWidgetBase*> mActiveWidgets;
  62. Map<String, std::function<EditorWidgetBase*(EditorWidgetContainer&)>> mCreateCallbacks;
  63. static Stack<std::pair<String, std::function<EditorWidgetBase*(EditorWidgetContainer&)>>> QueuedCreateCallbacks;
  64. };
  65. }