BsGUIFieldBase.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "BsGUIFieldBase.h"
  2. #include "BsGUILabel.h"
  3. #include "BsGUILayoutX.h"
  4. #include "BsGUIWidget.h"
  5. #include "BsGUISkin.h"
  6. #include "BsGUILayoutUtility.h"
  7. namespace BansheeEngine
  8. {
  9. const UINT32 GUIFieldBase::DEFAULT_LABEL_WIDTH = 100;
  10. GUIFieldBase::GUIFieldBase(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  11. const String& style, const GUIDimensions& dimensions, bool withLabel)
  12. :GUIElementContainer(dimensions, style), mLabel(nullptr)
  13. {
  14. mLayout = GUILayoutX::create();
  15. _registerChildElement(mLayout);
  16. if(withLabel)
  17. {
  18. mLabel = GUILabel::create(labelContent, GUIOptions(GUIOption::fixedWidth(labelWidth)), getSubStyleName(getLabelStyleType()));
  19. mLayout->addElement(mLabel);
  20. }
  21. }
  22. void GUIFieldBase::_updateLayoutInternal(const GUILayoutData& data)
  23. {
  24. GUILayoutData childData = data;
  25. childData.clipRect.x -= data.area.x;
  26. childData.clipRect.y -= data.area.y;
  27. mLayout->_setLayoutData(childData);
  28. childData.clipRect = data.clipRect;
  29. mLayout->_updateLayoutInternal(childData);
  30. }
  31. Vector2I GUIFieldBase::_getOptimalSize() const
  32. {
  33. return GUILayoutUtility::calcOptimalSize(mLayout);
  34. }
  35. void GUIFieldBase::styleUpdated()
  36. {
  37. if (mLabel != nullptr)
  38. mLabel->setStyle(getSubStyleName(getLabelStyleType()));
  39. }
  40. }