Ensure selected item is visible after menu becomes active

core4
nimetu 3 years ago
parent dc9ab8ec79
commit d2376f0203

@ -289,6 +289,8 @@ namespace NLGUI
sint32 _MaxVisibleLine; // -1 == no limit sint32 _MaxVisibleLine; // -1 == no limit
bool _ScrollToView;
friend class CGroupMenu; friend class CGroupMenu;
private: private:
/** Clone this menu, and set its new father /** Clone this menu, and set its new father

@ -1432,6 +1432,8 @@ namespace NLGUI
childElement->getCorner(childX, childY, childHotSpot); childElement->getCorner(childX, childY, childHotSpot);
if (_Vertical) if (_Vertical)
{ {
// remove previous scroll offset from child
childY -= _Target->getOfsY();
sint32 maxHReal= _Target->getMaxHReal(); sint32 maxHReal= _Target->getMaxHReal();
sint32 hReal= _Target->getHReal(); sint32 hReal= _Target->getHReal();
if(hReal > maxHReal) if(hReal > maxHReal)
@ -1473,6 +1475,8 @@ namespace NLGUI
} }
else else
{ {
// remove previous scroll offset from child
childX -= _Target->getOfsX();
sint32 maxWReal= _Target->getMaxWReal(); sint32 maxWReal= _Target->getMaxWReal();
sint32 wReal= _Target->getWReal(); sint32 wReal= _Target->getWReal();
if(wReal > maxWReal) if(wReal > maxWReal)

@ -133,6 +133,7 @@ namespace NLGUI
_Selected = -1; _Selected = -1;
_MaxVisibleLine = -1; _MaxVisibleLine = -1;
_ScrollBar = NULL; _ScrollBar = NULL;
_ScrollToView = false;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -590,6 +591,7 @@ namespace NLGUI
_GroupList->setMaxH(widgetMaxH*_MaxVisibleLine+_GroupList->getSpace()*(_MaxVisibleLine-1)); _GroupList->setMaxH(widgetMaxH*_MaxVisibleLine+_GroupList->getSpace()*(_MaxVisibleLine-1));
if (_ScrollBar == NULL) if (_ScrollBar == NULL)
{ {
_ScrollToView = true;
_ScrollBar = new CCtrlScroll(CViewBase::TCtorParam()); _ScrollBar = new CCtrlScroll(CViewBase::TCtorParam());
_ScrollBar->setParent (this); _ScrollBar->setParent (this);
_ScrollBar->setParentPos (_GroupList); _ScrollBar->setParentPos (_GroupList);
@ -897,6 +899,16 @@ namespace NLGUI
_SelectionView->setH (refElmHReal); _SelectionView->setH (refElmHReal);
_SelectionView->setY (refElmYReal - this->getYReal()); _SelectionView->setY (refElmYReal - this->getYReal());
} }
// initial scroll after becoming active
if (_ScrollBar && _ScrollToView)
{
_ScrollToView = false;
if (_Selected != -1 && _Lines[_Selected].ViewText != NULL)
_ScrollBar->ensureVisible(_Lines[_Selected].ViewText, Hotspot_Tx, Hotspot_Mx);
else
_ScrollBar->setTrackPos(_GroupList->getHReal());
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -1664,10 +1676,10 @@ namespace NLGUI
} }
} }
if(_ScrollBar && _GroupList)
_ScrollBar->setTrackPos(_GroupList->getHReal());
CGroupFrame::setActive(state); CGroupFrame::setActive(state);
// handle scrolling in next updateCoords() call
_ScrollToView = true;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -2538,6 +2550,10 @@ namespace NLGUI
CGroupFrame::setActive (state); CGroupFrame::setActive (state);
// skip rest if being hidden
if (!state)
return;
// must recompute now the pos of the menu // must recompute now the pos of the menu
uint32 i; uint32 i;
for (i = 0; i < _ChildrenGroups.size(); ++i) for (i = 0; i < _ChildrenGroups.size(); ++i)

Loading…
Cancel
Save