BsGUIComponentFoldout.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUIElementContainer.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief GUI element that serves as a title for a Component object. The foldout
  8. * displays a certain label (e.g. component name) and can be expanded or collapsed.
  9. *
  10. * @note It's up to the caller to actually hook up what expanding or collapsing the foldout means,
  11. * internally it just toggles a button.
  12. */
  13. class BS_ED_EXPORT GUIComponentFoldout : public GUIElementContainer
  14. {
  15. struct PrivatelyConstruct {};
  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. * Returns the style type name of the internal toggle button that triggers expand/collapse.
  23. */
  24. static const String& getFoldoutButtonStyleType();
  25. /**
  26. * Returns the style type name of the internal toggle button that triggers component removal.
  27. */
  28. static const String& getFoldoutRemoveButtonStyleType();
  29. /**
  30. * @brief Creates a new GUI component foldout element.
  31. *
  32. * @param label Label to display in the foldout title.
  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 styleName Optional style to use for the element. Style will be retrieved
  36. * from GUISkin of the GUIWidget the element is used on. If not specified
  37. * default style is used.
  38. */
  39. static GUIComponentFoldout* create(const HString& label, const GUIOptions& options, const String& style = StringUtil::BLANK);
  40. /**
  41. * @brief Creates a new GUI component foldout element.
  42. *
  43. * @param label Label to display in the foldout title.
  44. * @param styleName Optional style to use for the element. Style will be retrieved
  45. * from GUISkin of the GUIWidget the element is used on. If not specified
  46. * default style is used.
  47. */
  48. static GUIComponentFoldout* create(const HString& label, const String& style = StringUtil::BLANK);
  49. GUIComponentFoldout(const PrivatelyConstruct& dummy, const HString& label, const String& style, const GUIDimensions& dimensions);
  50. /**
  51. * @brief Returns whether the foldout is currently expanded or collapsed.
  52. */
  53. bool isExpanded() const { return mIsExpanded; }
  54. /**
  55. * @brief Expands or collapses the foldout.
  56. */
  57. void setExpanded(bool expanded);
  58. /**
  59. * Changes the label displayed on the foldout.
  60. */
  61. void setContent(const GUIContent& content);
  62. /**
  63. * @copydoc GUIElement::setTint
  64. */
  65. virtual void setTint(const Color& color) override;
  66. /**
  67. * @copydoc GUIElement::_updateLayoutInternal
  68. */
  69. void _updateLayoutInternal(const GUILayoutData& data) override;
  70. /**
  71. * @copydoc GUIElement::_getOptimalSize
  72. */
  73. Vector2I _getOptimalSize() const override;
  74. Event<void(bool)> onStateChanged;
  75. Event<void()> onRemoveClicked;
  76. protected:
  77. virtual ~GUIComponentFoldout();
  78. /**
  79. * @brief Triggered when the foldout is expanded or collapsed.
  80. * True means expanded, false collapsed.
  81. */
  82. void toggleTriggered(bool value);
  83. /**
  84. * @brief Triggered when the remove button is clicked.
  85. */
  86. void removeTriggered();
  87. /**
  88. * @copydoc GUIElement::styleUpdated
  89. */
  90. void styleUpdated() override;
  91. GUIToggle* mToggle;
  92. GUIButton* mRemove;
  93. bool mIsExpanded;
  94. };
  95. }