Skip to content

Commit

Permalink
Merge pull request ddnet#8999 from dobrykafe/pr-listbox-qol
Browse files Browse the repository at this point in the history
Add support for vertical arrow key navigation in multi-column listboxes
  • Loading branch information
def- authored Sep 20, 2024
2 parents 5558a69 + 582e9fa commit b6f80e5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/game/client/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 10 additions & 8 deletions src/game/client/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,16 @@ class CUi
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;
Expand Down
6 changes: 5 additions & 1 deletion src/game/client/ui_listbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b6f80e5

Please sign in to comment.