BsGUILayout.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "BsGUILayout.h"
  2. #include "BsGUIElement.h"
  3. #include "BsGUILayoutX.h"
  4. #include "BsGUILayoutY.h"
  5. #include "BsGUISpace.h"
  6. #include "BsException.h"
  7. namespace BansheeEngine
  8. {
  9. GUILayout::GUILayout(GUIArea* parentArea)
  10. :mParentGUIArea(parentArea)
  11. { }
  12. GUILayout::GUILayout(const GUIDimensions& dimensions)
  13. :GUIElementBase(dimensions), mParentGUIArea(nullptr)
  14. { }
  15. GUILayout::GUILayout()
  16. :mParentGUIArea(nullptr)
  17. { }
  18. GUILayout::~GUILayout()
  19. {
  20. if (mParentElement != nullptr)
  21. mParentElement->_unregisterChildElement(this);
  22. }
  23. void GUILayout::addElement(GUIElementBase* element)
  24. {
  25. _registerChildElement(element);
  26. }
  27. void GUILayout::removeElement(GUIElementBase* element)
  28. {
  29. _unregisterChildElement(element);
  30. }
  31. void GUILayout::insertElement(UINT32 idx, GUIElementBase* element)
  32. {
  33. if(idx < 0 || idx > (UINT32)mChildren.size())
  34. BS_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
  35. GUIElementBase* parentElement = element->_getParent();
  36. if(parentElement != nullptr)
  37. {
  38. parentElement->_unregisterChildElement(element);
  39. }
  40. element->_setParent(this);
  41. mChildren.insert(mChildren.begin() + idx, element);
  42. if (mIsDisabled)
  43. element->disableRecursively();
  44. markContentAsDirty();
  45. }
  46. void GUILayout::removeElementAt(UINT32 idx)
  47. {
  48. if(idx < 0 || idx >= (UINT32)mChildren.size())
  49. BS_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
  50. GUIElementBase* child = mChildren[idx];
  51. mChildren.erase(mChildren.begin() + idx);
  52. child->_setParent(nullptr);
  53. markContentAsDirty();
  54. }
  55. const RectOffset& GUILayout::_getPadding() const
  56. {
  57. static RectOffset padding;
  58. return padding;
  59. }
  60. void GUILayout::destroy(GUILayout* layout)
  61. {
  62. bs_delete(layout);
  63. }
  64. }