BsGUIFoldout.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUIElementContainer.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Composite GUI element that contains a toggle button and a label.
  8. * Used for handling expand/collapse operations, although it's up to
  9. * the caller to actually handle the #onStateChanged event.
  10. */
  11. class BS_ED_EXPORT GUIFoldout : public GUIElementContainer
  12. {
  13. struct PrivatelyConstruct {};
  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. * Returns GUI style type name for the internal toggle button.
  21. */
  22. static const String& getFoldoutButtonStyleType();
  23. /**
  24. * Returns GUI style type name for the internal label.
  25. */
  26. static const String& getLabelStyleType();
  27. /**
  28. * @brief Creates a new GUI foldout element.
  29. *
  30. * @param label Label to display in the foldout title.
  31. * @param options Options that allow you to control how is the element positioned and sized.
  32. * This will override any similar options set by style.
  33. * @param styleName Optional style to use for the element. Style will be retrieved
  34. * from GUISkin of the GUIWidget the element is used on. If not specified
  35. * default style is used.
  36. */
  37. static GUIFoldout* create(const HString& label, const GUIOptions& options, const String& style = StringUtil::BLANK);
  38. /**
  39. * @brief Creates a new GUI foldout element.
  40. *
  41. * @param label Label to display in the foldout title.
  42. * @param styleName Optional style to use for the element. Style will be retrieved
  43. * from GUISkin of the GUIWidget the element is used on. If not specified
  44. * default style is used.
  45. */
  46. static GUIFoldout* create(const HString& label, const String& style = StringUtil::BLANK);
  47. GUIFoldout(const PrivatelyConstruct& dummy, const HString& label, const String& style, const GUIDimensions& dimensions);
  48. /**
  49. * @brief Checks is the foldout expanded (i.e. the toggle button is active)
  50. */
  51. bool isExpanded() const { return mIsExpanded; }
  52. /**
  53. * @brief Expands or collapses the foldout (i.e. changes the toggle button state)
  54. */
  55. void setExpanded(bool expanded);
  56. /**
  57. * Changes the label of the foldout.
  58. */
  59. void setContent(const GUIContent& content);
  60. /**
  61. * @copydoc GUIElement::setTint
  62. */
  63. virtual void setTint(const Color& color) override;
  64. /**
  65. * @copydoc GUIElement::_updateLayoutInternal
  66. */
  67. void _updateLayoutInternal(const GUILayoutData& data) override;
  68. /**
  69. * @copydoc GUIElement::_getOptimalSize
  70. */
  71. Vector2I _getOptimalSize() const override;
  72. Event<void(bool)> onStateChanged; /**< Triggered when the foldout is expanded or collapsed. True means expanded, false otherwise. */
  73. protected:
  74. virtual ~GUIFoldout();
  75. /**
  76. * @brief Callback triggered when the internal toggle button is toggled.
  77. */
  78. void toggleTriggered(bool value);
  79. /**
  80. * @copydoc GUIElement::_getOptimalSize
  81. */
  82. void styleUpdated() override;
  83. GUILabel* mLabel;
  84. GUIToggle* mToggle;
  85. bool mIsExpanded;
  86. };
  87. }