From 582e9facab462fa123314b2fc57861c5177b81d2 Mon Sep 17 00:00:00 2001 From: dobrykafe Date: Thu, 19 Sep 2024 23:50:21 +0200 Subject: [PATCH] add support for vertical arrow key navigation in multi-column listboxes --- src/game/client/ui.cpp | 4 ++++ src/game/client/ui.h | 18 ++++++++++-------- src/game/client/ui_listbox.cpp | 6 +++++- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/game/client/ui.cpp b/src/game/client/ui.cpp index 62658be81..138b01ae2 100644 --- a/src/game/client/ui.cpp +++ b/src/game/client/ui.cpp @@ -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) diff --git a/src/game/client/ui.h b/src/game/client/ui.h index 8cf21bd30..72972d9f3 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -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; diff --git a/src/game/client/ui_listbox.cpp b/src/game/client/ui_listbox.cpp index 2a84aebd7..cfbe18ddb 100644 --- a/src/game/client/ui_listbox.cpp +++ b/src/game/client/ui_listbox.cpp @@ -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;