| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- #include "BsGUILayout.h"
- #include "BsGUIElement.h"
- #include "BsGUILayoutX.h"
- #include "BsGUILayoutY.h"
- #include "BsGUISpace.h"
- #include "CmException.h"
- using namespace CamelotFramework;
- namespace BansheeEngine
- {
- GUILayout::GUILayout()
- :mOptimalWidth(0), mOptimalHeight(0), mActualWidth(0), mActualHeight(0)
- {
- }
- GUILayout::~GUILayout()
- {
- }
- void GUILayout::addElement(GUIElement* element)
- {
- GUIElementBase* parentElement = element->_getParent();
- if(parentElement != nullptr && parentElement->_getType() == GUIElementBase::Type::Layout)
- {
- GUILayout* layoutParent = static_cast<GUILayout*>(parentElement);
- layoutParent->removeElement(element);
- }
- element->_setParent(this);
- mChildren.push_back(element);
- markContentAsDirty();
- }
- void GUILayout::removeElement(GUIElement* element)
- {
- bool foundElem = false;
- for(auto iter = mChildren.begin(); iter != mChildren.end(); ++iter)
- {
- GUIElementBase* child = *iter;
- if(child->_getType() == GUIElementBase::Type::Element && child == element)
- {
- mChildren.erase(iter);
- element->_setParent(nullptr);
- foundElem = true;
-
- markContentAsDirty();
- break;
- }
- }
- if(!foundElem)
- CM_EXCEPT(InvalidParametersException, "Provided element is not a part of this layout.");
- }
- void GUILayout::insertElement(UINT32 idx, GUIElement* element)
- {
- if(idx < 0 || idx > (UINT32)mChildren.size())
- CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
- GUIElementBase* parentElement = element->_getParent();
- if(parentElement != nullptr && parentElement->_getType() == GUIElementBase::Type::Layout)
- {
- GUILayout* layoutParent = static_cast<GUILayout*>(parentElement);
- layoutParent->removeElement(element);
- }
- element->_setParent(this);
- mChildren.insert(mChildren.begin() + idx, element);
-
- markContentAsDirty();
- }
- void GUILayout::removeChildAt(CM::UINT32 idx)
- {
- if(idx < 0 || idx >= (UINT32)mChildren.size())
- CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
- GUIElementBase* child = mChildren[idx];
- mChildren.erase(mChildren.begin() + idx);
- if(child->_getType() == GUIElementBase::Type::Element)
- child->_setParent(nullptr);
- else
- cm_delete<PoolAlloc>(child);
- markContentAsDirty();
- }
- GUIFixedSpace& GUILayout::addSpace(UINT32 size)
- {
- GUIFixedSpace* entry = cm_new<GUIFixedSpace, PoolAlloc>(size);
- mChildren.push_back(entry);
- markContentAsDirty();
- return *entry;
- }
- void GUILayout::removeSpace(GUIFixedSpace& space)
- {
- bool foundElem = false;
- for(auto iter = mChildren.begin(); iter != mChildren.end(); ++iter)
- {
- GUIElementBase* child = *iter;
- if(child->_getType() == GUIElementBase::Type::FixedSpace && child == &space)
- {
- cm_delete<PoolAlloc>(child);
- mChildren.erase(iter);
- foundElem = true;
- markContentAsDirty();
- break;
- }
- }
- if(!foundElem)
- CM_EXCEPT(InvalidParametersException, "Provided element is not a part of this layout.");
- }
- GUIFixedSpace& GUILayout::insertSpace(UINT32 idx, UINT32 size)
- {
- if(idx < 0 || idx > (UINT32)mChildren.size())
- CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
- GUIFixedSpace* entry = cm_new<GUIFixedSpace, PoolAlloc>(size);
- mChildren.insert(mChildren.begin() + idx, entry);
- markContentAsDirty();
- return *entry;
- }
- GUIFlexibleSpace& GUILayout::addFlexibleSpace()
- {
- GUIFlexibleSpace* entry = cm_new<GUIFlexibleSpace, PoolAlloc>();
- mChildren.push_back(entry);
- markContentAsDirty();
- return *entry;
- }
- void GUILayout::removeFlexibleSpace(GUIFlexibleSpace& space)
- {
- bool foundElem = false;
- for(auto iter = mChildren.begin(); iter != mChildren.end(); ++iter)
- {
- GUIElementBase* child = *iter;
- if(child->_getType() == GUIElementBase::Type::FlexibleSpace && child == &space)
- {
- cm_delete<PoolAlloc>(child);
- mChildren.erase(iter);
- foundElem = true;
- markContentAsDirty();
- break;
- }
- }
- if(!foundElem)
- CM_EXCEPT(InvalidParametersException, "Provided element is not a part of this layout.");
- }
- GUIFlexibleSpace& GUILayout::insertFlexibleSpace(UINT32 idx)
- {
- if(idx < 0 || idx > (UINT32)mChildren.size())
- CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
- GUIFlexibleSpace* entry = cm_new<GUIFlexibleSpace, PoolAlloc>();
- mChildren.insert(mChildren.begin() + idx, entry);
- markContentAsDirty();
- return *entry;
- }
- }
|