Pos and Size parent setters should now use the widget directly as well.

This commit is contained in:
dfighter1985 2014-10-13 15:43:10 +02:00
parent 126631020f
commit b8d16d8b9b

View file

@ -1534,17 +1534,36 @@ namespace NLGUI
void CInterfaceElement::setPosParent( const std::string &id ) void CInterfaceElement::setPosParent( const std::string &id )
{ {
std::string Id = stripId( id ); // Parent or empty id simply means the group parent
if( ( id == "parent" ) || ( id.empty() ) )
if( Id != "parent" )
{ {
std::string idParent; setParentPos( getParent() );
if( _Parent != NULL ) return;
idParent = _Parent->getId() + ":";
else
idParent = "ui:";
CWidgetManager::getInstance()->getParser()->addParentPositionAssociation( this, idParent + Id );
} }
CInterfaceElement *pp = NULL;
// Check if it's a short Id
std::string::size_type idx = id.find( "ui:" );
if( idx == std::string::npos )
{
// If it is, find the widget in the parent group and set as posparent
CInterfaceGroup *p = getParent();
if( p != NULL )
{
pp = p->findFromShortId( id );
}
}
else
{
// If it is not, find using the widgetmanager
// TODO: refactor, shouldn't use a singleton
pp = CWidgetManager::getInstance()->getElementFromId( id );
}
if( pp != NULL )
setParentPos( pp );
} }
void CInterfaceElement::getPosParent( std::string &id ) const void CInterfaceElement::getPosParent( std::string &id ) const
@ -1579,25 +1598,35 @@ namespace NLGUI
void CInterfaceElement::setSizeParent( const std::string &id ) void CInterfaceElement::setSizeParent( const std::string &id )
{ {
std::string Id = stripId( id ); // Parent or empty id simply means the group parent
std::string idParent; if( ( id == "parent" ) || ( id.empty() ) )
{
setParentSize( getParent() );
return;
}
if( Id != "parent" ) CInterfaceElement *pp = NULL;
// Check if it's a short Id
std::string::size_type idx = id.find( "ui:" );
if( idx == std::string::npos )
{ {
if( _Parent != NULL ) // If it is, find the widget in the parent group and set as posparent
idParent = _Parent->getId() + ":"; CInterfaceGroup *p = getParent();
else if( p != NULL )
idParent = "ui:"; {
CWidgetManager::getInstance()->getParser()->addParentSizeAssociation( this, idParent + Id ); pp = p->findFromShortId( id );
}
} }
else else
{ {
if( _Parent != NULL ) // If it is not, find using the widgetmanager
{ // TODO: refactor, shouldn't use a singleton
idParent = _Parent->getId(); pp = CWidgetManager::getInstance()->getElementFromId( id );
CWidgetManager::getInstance()->getParser()->addParentSizeAssociation( this, idParent );
}
} }
if( pp != NULL )
setParentSize( pp );
} }
void CInterfaceElement::getSizeParent( std::string &id ) const void CInterfaceElement::getSizeParent( std::string &id ) const