Skip to content

Commit

Permalink
Allow to autoselect items in combobox using right mouse button
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Jan 11, 2025
1 parent f1fdbb1 commit a0c02d0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/xrUICore/ComboBox/UIComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,34 @@ void CUIComboBox::SetItemToken(int tok_id)
SetItemIDX(idx);
}

bool CUIComboBox::SetNextItemSelected(bool next, bool loop)
{
const auto lastItem = (int)m_list_box.GetSize() - 1;

int idx = (int)m_list_box.GetSelectedIDX();

if (next)
{
if (idx < lastItem)
idx++;
else if (loop)
idx = 0;
else
return false;
}
else
{
if (idx > 0)
--idx;
else if (loop)
idx = lastItem;
else
return false;
}
SetItemIDX(idx);
return true;
}

void CUIComboBox::OnBtnClicked() { ShowList(!m_list_frame.IsShown()); }
void CUIComboBox::ShowList(bool bShow)
{
Expand Down Expand Up @@ -290,6 +318,10 @@ bool CUIComboBox::OnMouseAction(float x, float y, EUIMessages mouse_action)
return true;
}
}
else if (mouse_action == WINDOW_RBUTTON_DOWN)
{
SetNextItemSelected(true, true);
}

return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/xrUICore/ComboBox/UIComboBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class XRUICORE_API CUIComboBox final : public CUIWindow, public CUIOptionsItem,
u32 GetSelectedIDX();
void SetSelectedIDX(u32 idx);

bool SetNextItemSelected(bool next, bool loop);

virtual void SendMessage(CUIWindow* pWnd, s16 msg, void* pData = 0);
virtual void OnFocusLost();
virtual void OnFocusReceive();
Expand Down

0 comments on commit a0c02d0

Please sign in to comment.