Highlight current selected menu item

core4
nimetu 3 years ago
parent 4a4e626f56
commit dc9ab8ec79

@ -188,6 +188,10 @@ namespace NLGUI
// Hide a line. // Hide a line.
void setHiddenLine(uint line, bool h); void setHiddenLine(uint line, bool h);
// Highlight single line
void setSelected(uint line) { _Selected = line < _Lines.size() ? line : -1; }
void clearSelected() { _Selected = -1; }
// Max Visible Line (-1 == no limit) // Max Visible Line (-1 == no limit)
void setMaxVisibleLine(sint32 mvl); void setMaxVisibleLine(sint32 mvl);
sint32 getMaxVisibleLine() { return _MaxVisibleLine; } sint32 getMaxVisibleLine() { return _MaxVisibleLine; }
@ -281,6 +285,7 @@ namespace NLGUI
CGroupMenu *_GroupMenu; // Master parent CGroupMenu *_GroupMenu; // Master parent
sint32 _MouseOver; sint32 _MouseOver;
sint32 _Selected;
sint32 _MaxVisibleLine; // -1 == no limit sint32 _MaxVisibleLine; // -1 == no limit
@ -371,6 +376,10 @@ namespace NLGUI
// Gray a line on the RootMenu // Gray a line on the RootMenu
void setGrayedLine(uint line, bool g); void setGrayedLine(uint line, bool g);
// Highlight single line
void setSelected(uint line) { if (_RootMenu) _RootMenu->setSelected(line); }
void clearSelected() { if(_RootMenu) _RootMenu->clearSelected(); }
CGroupSubMenu *getRootMenu() const { return _RootMenu; } CGroupSubMenu *getRootMenu() const { return _RootMenu; }
// Max Visible Line (-1 == no limit) // Max Visible Line (-1 == no limit)

@ -745,6 +745,10 @@ namespace NLGUI
groupMenu->setY(pCB->getYReal()); groupMenu->setY(pCB->getYReal());
groupMenu->setBaseY(pCB->getYReal()); groupMenu->setBaseY(pCB->getYReal());
sint selected = pCB->getSelection();
if (selected >= 0)
groupMenu->setSelected((uint)selected);
// Must ensure the combo menu has same windows priority than the combo box window // Must ensure the combo menu has same windows priority than the combo box window
CInterfaceGroup *rootWin= pCB->getRootWindow(); CInterfaceGroup *rootWin= pCB->getRootWindow();
if(rootWin) if(rootWin)

@ -130,6 +130,7 @@ namespace NLGUI
_GroupList = NULL; _GroupList = NULL;
_GroupMenu = NULL; _GroupMenu = NULL;
_MouseOver = -1; _MouseOver = -1;
_Selected = -1;
_MaxVisibleLine = -1; _MaxVisibleLine = -1;
_ScrollBar = NULL; _ScrollBar = NULL;
} }
@ -882,8 +883,8 @@ namespace NLGUI
_SelectionView->setH (8); _SelectionView->setH (8);
_SelectionView->setY (4); _SelectionView->setY (4);
sint highlight = _MouseOver != -1 ? _MouseOver : _Selected;
if (_MouseOver != -1 && _Lines[_MouseOver].ViewText != NULL) if (highlight != -1 && _Lines[highlight].ViewText != NULL)
{ {
CRGBA col= _GroupMenu->_HighLightOver; CRGBA col= _GroupMenu->_HighLightOver;
@ -891,7 +892,7 @@ namespace NLGUI
_SelectionView->setModulateGlobalColor(getModulateGlobalColor()); _SelectionView->setModulateGlobalColor(getModulateGlobalColor());
// get refElm and refElmYReal // get refElm and refElmYReal
GET_REF_ELM(_MouseOver) GET_REF_ELM(highlight)
_SelectionView->setH (refElmHReal); _SelectionView->setH (refElmHReal);
_SelectionView->setY (refElmYReal - this->getYReal()); _SelectionView->setY (refElmYReal - this->getYReal());
@ -916,7 +917,7 @@ namespace NLGUI
// CViewRenderer &rVR = *CViewRenderer::getInstance(); // CViewRenderer &rVR = *CViewRenderer::getInstance();
// Highlight (background under the selection) // Highlight (background under the selection)
if (_MouseOver != -1) if (_MouseOver != -1 || _Selected != -1)
{ {
// display hightlight // display hightlight
if(_GroupMenu->_HighLightOver.A > 0) if(_GroupMenu->_HighLightOver.A > 0)
@ -994,6 +995,9 @@ namespace NLGUI
(eventDesc.getY() <= (_YReal+ _HReal)))) (eventDesc.getY() <= (_YReal+ _HReal))))
return false; return false;
if (_ScrollBar && _ScrollBar->isIn(eventDesc.getX(), eventDesc.getY()))
return false;
uint32 i = 0; uint32 i = 0;
for (i = 0; i < _Lines.size(); ++i) for (i = 0; i < _Lines.size(); ++i)
{ {
@ -1409,6 +1413,13 @@ namespace NLGUI
//invalidate selection //invalidate selection
_MouseOver = -1; _MouseOver = -1;
if (_Selected != -1)
{
if (_Selected == index)
_Selected = -1;
else if (_Selected > index)
_Selected--;
}
if(_SubMenus[index]) if(_SubMenus[index])
{ {
@ -1442,6 +1453,7 @@ namespace NLGUI
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void CGroupSubMenu::reset() void CGroupSubMenu::reset()
{ {
_Selected = -1;
uint lineCount = (uint)_Lines.size(); uint lineCount = (uint)_Lines.size();
for(sint k = lineCount - 1; k >= 0; --k) for(sint k = lineCount - 1; k >= 0; --k)
{ {

Loading…
Cancel
Save