BsGUIToggleField.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "BsGUIToggleField.h"
  2. #include "BsGUIArea.h"
  3. #include "BsGUILayout.h"
  4. #include "BsGUILabel.h"
  5. #include "BsGUIToggle.h"
  6. #include "BsBuiltinResources.h"
  7. #include "BsGUIWidget.h"
  8. #include "BsGUIMouseEvent.h"
  9. #include "BsGUIWidget.h"
  10. #include "BsCmdInputFieldValueChange.h"
  11. using namespace std::placeholders;
  12. namespace BansheeEngine
  13. {
  14. GUIToggleField::GUIToggleField(const PrivatelyConstruct& dummy, const GUIContent& labelContent,
  15. UINT32 labelWidth, const String& style, const GUILayoutOptions& layoutOptions, bool withLabel)
  16. :TGUIField(dummy, labelContent, labelWidth, style, layoutOptions, withLabel), mToggle(nullptr), mValue(false)
  17. {
  18. mToggle = GUIToggle::create(HString(L""), getSubStyleName(getToggleStyleType()));
  19. mToggle->onToggled.connect(std::bind(&GUIToggleField::valueChanged, this, _1));
  20. mLayout->addElement(mToggle);
  21. }
  22. void GUIToggleField::setValue(bool value)
  23. {
  24. mValue = value;
  25. if(value)
  26. mToggle->toggleOn();
  27. else
  28. mToggle->toggleOff();
  29. }
  30. void GUIToggleField::setTint(const Color& color)
  31. {
  32. if (mLabel != nullptr)
  33. mLabel->setTint(color);
  34. mToggle->setTint(color);
  35. }
  36. void GUIToggleField::styleUpdated()
  37. {
  38. if (mLabel != nullptr)
  39. mLabel->setStyle(getSubStyleName(getLabelStyleType()));
  40. mToggle->setStyle(getSubStyleName(getToggleStyleType()));
  41. }
  42. void GUIToggleField::valueChanged(bool newValue)
  43. {
  44. CmdInputFieldValueChange<GUIToggleField, bool>::execute(this, newValue);
  45. if (!onValueChanged.empty())
  46. onValueChanged(newValue);
  47. }
  48. const String& GUIToggleField::getGUITypeName()
  49. {
  50. static String typeName = "GUIToggleField";
  51. return typeName;
  52. }
  53. const String& GUIToggleField::getToggleStyleType()
  54. {
  55. static String STYLE_TYPE = "EditorFieldToggleInput";
  56. return STYLE_TYPE;
  57. }
  58. }