Move the text too with the text button.

This commit is contained in:
dfighter1985 2014-09-27 19:54:19 +02:00
parent a32ce96dde
commit 297d287f39
3 changed files with 29 additions and 15 deletions

View file

@ -204,6 +204,10 @@ namespace NLGUI
virtual void serial(NLMISC::IStream &f);
// Sets the parent element
// See the comment at the field
void setParentElm( CInterfaceElement *parent ){ _ParentElm = parent; }
protected:
std::string _HardtextFormat;
/// Text to display.
@ -379,6 +383,9 @@ namespace NLGUI
/// Dynamic tooltips
std::vector<CCtrlToolTip*> _Tooltips;
// Parent element is the element where this text belongs to
// For example: text button
CInterfaceElement *_ParentElm;
private:
void setup ();

View file

@ -66,8 +66,6 @@ namespace NLGUI
{
if( _ViewText != NULL )
{
if( _Parent != NULL )
_Parent->delView( _ViewText, true );
delete _ViewText;
_ViewText = NULL;
}
@ -569,6 +567,7 @@ namespace NLGUI
((CViewTextID*)_ViewText)->parseTextIdOptions(cur);
// Same RenderLayer as us.
_ViewText->setRenderLayer(getRenderLayer());
_ViewText->setParentElm(this);
// Parse the hardText (if not text id)
if(!_IsViewTextId)
{
@ -863,6 +862,12 @@ namespace NLGUI
}
if(getFrozen() && getFrozenHalfTone())
_ViewText->setAlpha(_ViewText->getAlpha()>>2);
// When dragging the button, the text needs to move too
if( CInterfaceElement::editorMode )
_ViewText->updateCoords();
_ViewText->draw();
}
}
@ -873,6 +878,8 @@ namespace NLGUI
// Should have been setuped with addCtrl
nlassert(_Setuped);
_ViewText->updateCoords();
// Compute Size according to bitmap and Text.
if (!(_SizeRef & 1))
{
@ -910,15 +917,13 @@ namespace NLGUI
}
// setup the viewText and add to parent
_ViewText->setParent (getParent());
_ViewText->setParentElm (this);
_ViewText->setParentPos (this);
_ViewText->setParentPosRef (_TextParentPosRef);
_ViewText->setPosRef (_TextPosRef);
_ViewText->setActive(_Active);
_ViewText->setX(_TextX);
_ViewText->setY(_TextY);
getParent()->addView(_ViewText);
}
// ***************************************************************************
@ -1007,17 +1012,10 @@ namespace NLGUI
// ***************************************************************************
void CCtrlTextButton::onRemoved()
{
if( _ViewText != NULL )
{
if( _Parent != NULL )
_Parent->delView( _ViewText, true );
}
}
void CCtrlTextButton::onWidgetDeleted( CInterfaceElement *e )
{
if( e == _ViewText )
_ViewText = NULL;
}
}

View file

@ -1814,9 +1814,18 @@ namespace NLGUI
if (_AutoClamp)
{
CViewBase::updateCoords ();
if (_Parent)
{
// If there's no parent, try the parent of the parent element.
// Since we will be under the same group
CInterfaceGroup *parent = _Parent;
if( parent == NULL )
{
if( _ParentElm != NULL )
parent = _ParentElm->getParent();
}
if (parent)
{
// avoid resizing parents to compute the limiter
while (parent && (parent->getResizeFromChildW() || parent->isGroupList() ))
{