| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
|---|---|
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #include "GUI/BsGUILayout.h" |
| 4 | #include "GUI/BsGUIElement.h" |
| 5 | #include "GUI/BsGUILayoutX.h" |
| 6 | #include "GUI/BsGUILayoutY.h" |
| 7 | #include "GUI/BsGUISpace.h" |
| 8 | #include "Error/BsException.h" |
| 9 | |
| 10 | namespace bs |
| 11 | { |
| 12 | GUILayout::GUILayout(const GUIDimensions& dimensions) |
| 13 | :GUIElementBase(dimensions) |
| 14 | { } |
| 15 | |
| 16 | GUILayout::GUILayout() |
| 17 | { } |
| 18 | |
| 19 | GUILayout::~GUILayout() |
| 20 | { |
| 21 | if (mParentElement != nullptr) |
| 22 | mParentElement->_unregisterChildElement(this); |
| 23 | } |
| 24 | |
| 25 | void GUILayout::addElement(GUIElementBase* element) |
| 26 | { |
| 27 | if (!element->_isDestroyed()) |
| 28 | _registerChildElement(element); |
| 29 | } |
| 30 | |
| 31 | void GUILayout::removeElement(GUIElementBase* element) |
| 32 | { |
| 33 | _unregisterChildElement(element); |
| 34 | } |
| 35 | |
| 36 | void GUILayout::insertElement(UINT32 idx, GUIElementBase* element) |
| 37 | { |
| 38 | if(idx > (UINT32)mChildren.size()) |
| 39 | BS_EXCEPT(InvalidParametersException, "Index out of range: "+ toString(idx) + ". Valid range: 0 .. "+ toString((UINT32)mChildren.size())); |
| 40 | |
| 41 | if (element->_isDestroyed()) |
| 42 | return; |
| 43 | |
| 44 | GUIElementBase* parentElement = element->_getParent(); |
| 45 | if(parentElement != nullptr) |
| 46 | { |
| 47 | parentElement->_unregisterChildElement(element); |
| 48 | } |
| 49 | |
| 50 | element->_setParent(this); |
| 51 | mChildren.insert(mChildren.begin() + idx, element); |
| 52 | |
| 53 | element->_setActive(_isActive()); |
| 54 | element->_setVisible(_isVisible()); |
| 55 | element->_setDisabled(_isDisabled()); |
| 56 | |
| 57 | _markLayoutAsDirty(); |
| 58 | } |
| 59 | |
| 60 | void GUILayout::clear() |
| 61 | { |
| 62 | destroyChildElements(); |
| 63 | } |
| 64 | |
| 65 | void GUILayout::removeElementAt(UINT32 idx) |
| 66 | { |
| 67 | if(idx >= (UINT32)mChildren.size()) |
| 68 | BS_EXCEPT(InvalidParametersException, "Index out of range: "+ toString(idx) + ". Valid range: 0 .. "+ toString((UINT32)mChildren.size())); |
| 69 | |
| 70 | GUIElementBase* child = mChildren[idx]; |
| 71 | mChildren.erase(mChildren.begin() + idx); |
| 72 | |
| 73 | child->_setParent(nullptr); |
| 74 | |
| 75 | _markLayoutAsDirty(); |
| 76 | } |
| 77 | |
| 78 | const RectOffset& GUILayout::_getPadding() const |
| 79 | { |
| 80 | static RectOffset padding; |
| 81 | |
| 82 | return padding; |
| 83 | } |
| 84 | |
| 85 | void GUILayout::destroy(GUILayout* layout) |
| 86 | { |
| 87 | bs_delete(layout); |
| 88 | } |
| 89 | } |