BsGUIToggleField.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUIFieldBase.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief A composite GUI object representing an editor field. Editor fields are a combination
  8. * of a label and an input field. Label is optional. This specific implementation
  9. * displays a toggle button.
  10. */
  11. class BS_ED_EXPORT GUIToggleField : public TGUIField<GUIToggleField>
  12. {
  13. public:
  14. /**
  15. * Returns type name of the GUI element used for finding GUI element styles.
  16. */
  17. static const String& getGUITypeName();
  18. /**
  19. * Returns style type name of the internal GUIToggle element.
  20. */
  21. static const String& getToggleStyleType();
  22. GUIToggleField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  23. const String& style, const GUIDimensions& dimensions, bool withLabel);
  24. /**
  25. * @brief Returns the current value of the toggle.
  26. */
  27. bool getValue() const { return mValue; }
  28. /**
  29. * @brief Activates/deactivates the toggle.
  30. */
  31. void setValue(bool value);
  32. /**
  33. * @copydoc GUIElement::setTint
  34. */
  35. void setTint(const Color& color) override;
  36. /**
  37. * @brief Sets a new value in the input field, and also allows you to choose should the field trigger an
  38. * onValueChanged event.
  39. */
  40. void _setValue(bool value, bool triggerEvent);
  41. Event<void(bool)> onValueChanged; /** Triggered when the value of the toggle changes. */
  42. protected:
  43. virtual ~GUIToggleField() { }
  44. /**
  45. * @copydoc GUIElement::styleUpdated
  46. */
  47. void styleUpdated() override;
  48. /**
  49. * @brief Triggered when the value of the internal toggle button changes.
  50. */
  51. void valueChanged(bool newValue);
  52. GUIToggle* mToggle;
  53. bool mValue;
  54. };
  55. }