Skip to content

Commit

Permalink
A bit better gamepad support code for CUITabControl (#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Jan 17, 2025
1 parent 8970888 commit 09a22f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/xrUICore/TabControl/UITabControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,8 @@ bool CUITabControl::OnKeyboardAction(int dik, EUIMessages keyboard_action)
{
switch (GetBindedAction(dik, EKeyContext::UI))
{
case kUI_TAB_PREV:
if (WINDOW_KEY_PRESSED == keyboard_action)
SetNextActiveTab(false, true);
return true;

case kUI_TAB_NEXT:
if (WINDOW_KEY_PRESSED == keyboard_action)
SetNextActiveTab(true, true);
return true;
case kUI_TAB_PREV: return SetNextActiveTab(false, true);
case kUI_TAB_NEXT: return SetNextActiveTab(true, true);
}
}
if (GetButtonsAcceleratorsMode())
Expand All @@ -253,6 +246,25 @@ bool CUITabControl::OnKeyboardAction(int dik, EUIMessages keyboard_action)
return false;
}

bool CUITabControl::OnControllerAction(int axis, float x, float y, EUIMessages controller_action)
{
if (WINDOW_KEY_PRESSED == controller_action)
{
if (GetButtonsAcceleratorsMode())
{
for (const auto& button : m_TabsArr)
{
if (button->IsAccelerator(axis))
{
SetActiveTab(button->m_btn_id);
return true;
}
}
}
}
return false;
}

CUITabButton* CUITabControl::GetButtonById(const shared_str& id)
{
TABS_VECTOR::const_iterator it = std::find(m_TabsArr.begin(), m_TabsArr.end(), id);
Expand Down
1 change: 1 addition & 0 deletions src/xrUICore/TabControl/UITabControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class XRUICORE_API CUITabControl : public CUIWindow, public CUIOptionsItem
virtual bool IsChangedOptValue() const; // backup!=current

virtual bool OnKeyboardAction(int dik, EUIMessages keyboard_action);
bool OnControllerAction(int axis, float x, float y, EUIMessages controller_action) override;
virtual void OnTabChange(const shared_str& sCur, const shared_str& sPrev);
virtual void OnStaticFocusReceive(CUIWindow* pWnd);
virtual void OnStaticFocusLost(CUIWindow* pWnd);
Expand Down

0 comments on commit 09a22f1

Please sign in to comment.