BsGUIColorField.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "BsGUIColorField.h"
  2. #include "BsGUILayout.h"
  3. #include "BsGUILabel.h"
  4. #include "BsGUIColor.h"
  5. using namespace std::placeholders;
  6. namespace BansheeEngine
  7. {
  8. GUIColorField::GUIColorField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  9. const String& style, const GUIDimensions& dimensions, bool withLabel)
  10. :TGUIField(dummy, labelContent, labelWidth, style, dimensions, withLabel),
  11. mLabel(nullptr), mColor(nullptr), mLabelWidth(100)
  12. {
  13. mColor = GUIColor::create(getSubStyleName(getColorInputStyleType()));
  14. mColor->onClicked.connect(std::bind(&GUIColorField::clicked, this));
  15. mLayout->addElement(mColor);
  16. }
  17. GUIColorField::~GUIColorField()
  18. {
  19. }
  20. void GUIColorField::setValue(const Color& color)
  21. {
  22. mValue = color;
  23. mColor->setColor(color);
  24. }
  25. void GUIColorField::setTint(const Color& color)
  26. {
  27. if (mLabel != nullptr)
  28. mLabel->setTint(color);
  29. mColor->setTint(color);
  30. }
  31. Vector2I GUIColorField::_getOptimalSize() const
  32. {
  33. Vector2I optimalsize = mColor->_getOptimalSize();
  34. if(mLabel != nullptr)
  35. {
  36. optimalsize.x += mLabel->_getOptimalSize().x;
  37. optimalsize.y = std::max(optimalsize.y, mLabel->_getOptimalSize().y);
  38. }
  39. return optimalsize;
  40. }
  41. void GUIColorField::styleUpdated()
  42. {
  43. if (mLabel != nullptr)
  44. mLabel->setStyle(getSubStyleName(getLabelStyleType()));
  45. mColor->setStyle(getSubStyleName(getColorInputStyleType()));
  46. }
  47. void GUIColorField::clicked()
  48. {
  49. onClicked();
  50. }
  51. const String& GUIColorField::getGUITypeName()
  52. {
  53. static String typeName = "GUIColorField";
  54. return typeName;
  55. }
  56. const String& GUIColorField::getColorInputStyleType()
  57. {
  58. static String STYLE_TYPE = "EditorFieldColor";
  59. return STYLE_TYPE;
  60. }
  61. }