Merge pull request #8999 from dobrykafe/pr-listbox-qol

Add support for vertical arrow key navigation in multi-column listboxes
This commit is contained in:
Dennis Felsing 2024-09-20 07:26:10 +00:00 committed by GitHub
commit b6f80e5375
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 9 deletions

View file

@ -408,6 +408,10 @@ bool CUi::OnInput(const IInput::CEvent &Event)
m_HotkeysPressed |= HOTKEY_UP;
else if(Event.m_Key == KEY_DOWN)
m_HotkeysPressed |= HOTKEY_DOWN;
else if(Event.m_Key == KEY_LEFT)
m_HotkeysPressed |= HOTKEY_LEFT;
else if(Event.m_Key == KEY_RIGHT)
m_HotkeysPressed |= HOTKEY_RIGHT;
else if(Event.m_Key == KEY_MOUSE_WHEEL_UP)
m_HotkeysPressed |= HOTKEY_SCROLL_UP;
else if(Event.m_Key == KEY_MOUSE_WHEEL_DOWN)

View file

@ -446,14 +446,16 @@ public:
HOTKEY_ESCAPE = 1 << 1,
HOTKEY_UP = 1 << 2,
HOTKEY_DOWN = 1 << 3,
HOTKEY_DELETE = 1 << 4,
HOTKEY_TAB = 1 << 5,
HOTKEY_SCROLL_UP = 1 << 6,
HOTKEY_SCROLL_DOWN = 1 << 7,
HOTKEY_PAGE_UP = 1 << 8,
HOTKEY_PAGE_DOWN = 1 << 9,
HOTKEY_HOME = 1 << 10,
HOTKEY_END = 1 << 11,
HOTKEY_LEFT = 1 << 4,
HOTKEY_RIGHT = 1 << 5,
HOTKEY_DELETE = 1 << 6,
HOTKEY_TAB = 1 << 7,
HOTKEY_SCROLL_UP = 1 << 8,
HOTKEY_SCROLL_DOWN = 1 << 9,
HOTKEY_PAGE_UP = 1 << 10,
HOTKEY_PAGE_DOWN = 1 << 11,
HOTKEY_HOME = 1 << 12,
HOTKEY_END = 1 << 13,
};
void ResetUIElement(CUIElement &UIElement) const;

View file

@ -100,8 +100,12 @@ void CListBox::DoStart(float RowHeight, int NumItems, int ItemsPerRow, int RowsP
if(m_Active && !Input()->ModifierIsPressed() && !Input()->ShiftIsPressed() && !Input()->AltIsPressed())
{
if(Ui()->ConsumeHotkey(CUi::HOTKEY_DOWN))
m_ListBoxNewSelOffset += 1;
m_ListBoxNewSelOffset += m_ListBoxItemsPerRow;
else if(Ui()->ConsumeHotkey(CUi::HOTKEY_UP))
m_ListBoxNewSelOffset -= m_ListBoxItemsPerRow;
else if(Ui()->ConsumeHotkey(CUi::HOTKEY_RIGHT) && m_ListBoxItemsPerRow > 1)
m_ListBoxNewSelOffset += 1;
else if(Ui()->ConsumeHotkey(CUi::HOTKEY_LEFT) && m_ListBoxItemsPerRow > 1)
m_ListBoxNewSelOffset -= 1;
else if(Ui()->ConsumeHotkey(CUi::HOTKEY_PAGE_UP))
m_ListBoxNewSelOffset = -ItemsPerRow * RowsPerScroll * 4;