Move the text too with the text button.

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

View file

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

View file

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

View file

@ -1814,9 +1814,18 @@ namespace NLGUI
if (_AutoClamp) if (_AutoClamp)
{ {
CViewBase::updateCoords (); 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)
{ {
CInterfaceGroup *parent = _Parent;
// avoid resizing parents to compute the limiter // avoid resizing parents to compute the limiter
while (parent && (parent->getResizeFromChildW() || parent->isGroupList() )) while (parent && (parent->getResizeFromChildW() || parent->isGroupList() ))
{ {