113 lines
3.1 KiB
Plaintext
113 lines
3.1 KiB
Plaintext
#include "cLayout.hpp"
|
|
|
|
using GUIEngine::cLayout;
|
|
|
|
/*static*/ const cString cLayout::sNAME = "layout";
|
|
/*static*/ const GUIHelpers::eOrientation cLayout::sORIENTATION = GUIHelpers::eOrientation::VERTICAL;
|
|
|
|
cLayout::cLayout(cWindow* parent, const signed int id, const GUIHelpers::eOrientation& orientation /*= sORIENTATION*/, const GUIHelpers::eAlign& align /*= sALIGN*/,
|
|
const GUIHelpers::eLayout& layout /*= sLAYOUT*/, const GUIHelpers::Position& pos /*= sPOSITION*/, const GUIHelpers::Size& size /*= sSIZE*/,
|
|
const GUIHelpers::Padding& padding /*= sPADDING*/, const cString& name /*= sNAME*/)
|
|
: cWindow(parent, id, align, layout, pos, size, padding, name)
|
|
{
|
|
//Create(parent, id, orientation, align, layout, pos, size, padding, name);
|
|
if (this->getParent() != nullptr) {
|
|
this->getParent()->AddChild(this);
|
|
}
|
|
setOrientation(orientation);
|
|
}
|
|
|
|
/*virtual*/ cLayout::~cLayout()
|
|
{}
|
|
|
|
///Functions
|
|
void cLayout::Create(cWindow* parent, const signed int id, const GUIHelpers::eOrientation& orientation /*= sORIENTATION*/, const GUIHelpers::eAlign& align /*= sALIGN*/,
|
|
const GUIHelpers::eLayout& layout /*= sLAYOUT*/, const GUIHelpers::Position& pos /*= sPOSITION*/, const GUIHelpers::Size& size /*= sSIZE*/,
|
|
const GUIHelpers::Padding& padding/* = sPADDING*/, const cString& name /*= sNAME*/)
|
|
{
|
|
//cWindow(parent, id, align, layout, pos, size, padding, name);
|
|
this->getParent()->AddChild(this);
|
|
setOrientation(orientation);
|
|
}
|
|
|
|
/*virtual*/ void cLayout::Display()
|
|
{
|
|
cWindow::Display();
|
|
}
|
|
|
|
///Set
|
|
void cLayout::setOrientation(const GUIHelpers::eOrientation& orientation /*= GUIHelpers::eOrientation::VERTICAL*/)
|
|
{
|
|
m_orientation = orientation;
|
|
}
|
|
|
|
///Get
|
|
const GUIHelpers::eOrientation& cLayout::getOrientation() const
|
|
{
|
|
return m_orientation;
|
|
}
|
|
|
|
/*virtual*/ const GUIHelpers::eType cLayout::getType() const
|
|
{
|
|
return GUIHelpers::eType::CLAYOUT;
|
|
}
|
|
|
|
/*virtual*/ void cLayout::Resize()
|
|
{
|
|
RebuildLayout(this->getLayout());
|
|
}
|
|
|
|
/*virtual*/ void cLayout::RebuildLayout(const GUIHelpers::eLayout& layout)
|
|
{
|
|
GUIHelpers::Size mySize = (0, 0);
|
|
switch (layout)
|
|
{
|
|
case GUIHelpers::eLayout::MATCH_PARENT:
|
|
case GUIHelpers::eLayout::FILL_PARENT:
|
|
cWindow::RebuildLayout(layout);
|
|
break;
|
|
case GUIHelpers::eLayout::WRAP_CONTENT:
|
|
std::vector<cWindow*> children = this->getChildren();
|
|
std::vector<cWindow*>::iterator it;
|
|
|
|
for (it = children.begin(); it < children.end(); it++) {
|
|
(*it)->Resize();
|
|
GUIHelpers::Size size = (*it)->getSize();
|
|
GUIHelpers::Padding pad = (*it)->getPadding();
|
|
size.x += pad.x + pad.w;
|
|
size.y += pad.y + pad.z;
|
|
AddSize(size.x, size.y, mySize);
|
|
}
|
|
this->setSize(mySize);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// /*virtual*/ void cLayout::RebuildPos()
|
|
// {
|
|
// cWindow::RebuildPos();
|
|
// }
|
|
|
|
///Private
|
|
/*virtual*/ void cLayout::AddSize(int x, int y, GUIHelpers::Size& mySize) const
|
|
{
|
|
int& addFrom = x;
|
|
int& largestFrom = y;
|
|
|
|
int& addTo = mySize.x;
|
|
int& largestTo = mySize.y;
|
|
|
|
if (m_orientation == GUIHelpers::eOrientation::HORIZONTAL) {
|
|
addFrom = y;
|
|
largestFrom = x;
|
|
|
|
addTo = mySize.y;
|
|
largestTo = mySize.x;
|
|
}
|
|
|
|
/*We do the real work here.*/
|
|
if (largestTo > largestFrom)
|
|
largestTo = largestFrom;
|
|
|
|
addTo += addFrom;
|
|
} |