From d2376f0203884428d7aba4f49b9034d5a0bc245e Mon Sep 17 00:00:00 2001 From: nimetu Date: Sat, 22 Jan 2022 00:59:48 +0200 Subject: [PATCH] Ensure selected item is visible after menu becomes active --- nel/include/nel/gui/group_menu.h | 2 ++ nel/src/gui/ctrl_scroll.cpp | 4 ++++ nel/src/gui/group_menu.cpp | 22 +++++++++++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/nel/include/nel/gui/group_menu.h b/nel/include/nel/gui/group_menu.h index c7bd017ae..25ec43f96 100644 --- a/nel/include/nel/gui/group_menu.h +++ b/nel/include/nel/gui/group_menu.h @@ -289,6 +289,8 @@ namespace NLGUI sint32 _MaxVisibleLine; // -1 == no limit + bool _ScrollToView; + friend class CGroupMenu; private: /** Clone this menu, and set its new father diff --git a/nel/src/gui/ctrl_scroll.cpp b/nel/src/gui/ctrl_scroll.cpp index 28d7f2fed..0587e5caf 100644 --- a/nel/src/gui/ctrl_scroll.cpp +++ b/nel/src/gui/ctrl_scroll.cpp @@ -1432,6 +1432,8 @@ namespace NLGUI childElement->getCorner(childX, childY, childHotSpot); if (_Vertical) { + // remove previous scroll offset from child + childY -= _Target->getOfsY(); sint32 maxHReal= _Target->getMaxHReal(); sint32 hReal= _Target->getHReal(); if(hReal > maxHReal) @@ -1473,6 +1475,8 @@ namespace NLGUI } else { + // remove previous scroll offset from child + childX -= _Target->getOfsX(); sint32 maxWReal= _Target->getMaxWReal(); sint32 wReal= _Target->getWReal(); if(wReal > maxWReal) diff --git a/nel/src/gui/group_menu.cpp b/nel/src/gui/group_menu.cpp index 9398ea4b1..72bf3c8c9 100644 --- a/nel/src/gui/group_menu.cpp +++ b/nel/src/gui/group_menu.cpp @@ -133,6 +133,7 @@ namespace NLGUI _Selected = -1; _MaxVisibleLine = -1; _ScrollBar = NULL; + _ScrollToView = false; } // ------------------------------------------------------------------------------------------------ @@ -590,6 +591,7 @@ namespace NLGUI _GroupList->setMaxH(widgetMaxH*_MaxVisibleLine+_GroupList->getSpace()*(_MaxVisibleLine-1)); if (_ScrollBar == NULL) { + _ScrollToView = true; _ScrollBar = new CCtrlScroll(CViewBase::TCtorParam()); _ScrollBar->setParent (this); _ScrollBar->setParentPos (_GroupList); @@ -897,6 +899,16 @@ namespace NLGUI _SelectionView->setH (refElmHReal); _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); + + // handle scrolling in next updateCoords() call + _ScrollToView = true; } // ------------------------------------------------------------------------------------------------ @@ -2538,6 +2550,10 @@ namespace NLGUI CGroupFrame::setActive (state); + // skip rest if being hidden + if (!state) + return; + // must recompute now the pos of the menu uint32 i; for (i = 0; i < _ChildrenGroups.size(); ++i)