BsGUIFieldBase.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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(INT32 x, INT32 y, UINT32 width, UINT32 height,
  23. Rect2I clipRect, UINT8 widgetDepth, INT16 panelDepth, UINT16 panelDepthRangeMin, UINT16 panelDepthRangeMax)
  24. {
  25. mLayout->_setPosition(Vector2I(x, y));
  26. mLayout->_setWidth(width);
  27. mLayout->_setHeight(height);
  28. mLayout->_setWidgetDepth(widgetDepth);
  29. mLayout->_setAreaDepth(panelDepth);
  30. mLayout->_setPanelDepthRange(panelDepthRangeMin, panelDepthRangeMax);
  31. Rect2I elemClipRect(clipRect.x - x, clipRect.y - y, clipRect.width, clipRect.height);
  32. mLayout->_setClipRect(elemClipRect);
  33. mLayout->_updateLayoutInternal(x, y, width, height, clipRect, widgetDepth, panelDepth, panelDepthRangeMin, panelDepthRangeMax);
  34. }
  35. Vector2I GUIFieldBase::_getOptimalSize() const
  36. {
  37. return GUILayoutUtility::calcOptimalSize(mLayout);
  38. }
  39. void GUIFieldBase::styleUpdated()
  40. {
  41. if (mLabel != nullptr)
  42. mLabel->setStyle(getSubStyleName(getLabelStyleType()));
  43. }
  44. }