BsGUIFieldBase.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "GUI/BsGUIFieldBase.h"
  4. #include "GUI/BsGUILabel.h"
  5. #include "GUI/BsGUILayoutX.h"
  6. #include "GUI/BsGUILayoutUtility.h"
  7. namespace bs
  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. mLayout->_setLayoutData(data);
  25. mLayout->_updateLayoutInternal(data);
  26. }
  27. Vector2I GUIFieldBase::_getOptimalSize() const
  28. {
  29. return GUILayoutUtility::calcOptimalSize(mLayout);
  30. }
  31. void GUIFieldBase::styleUpdated()
  32. {
  33. if (mLabel != nullptr)
  34. mLabel->setStyle(getSubStyleName(getLabelStyleType()));
  35. }
  36. }