| 399 | |
| 400 | template<typename T> |
| 401 | int CEditor::DoEditBoxDropdown(SEditBoxDropdownContext *pDropdown, CLineInput *pLineInput, const CUIRect *pEditBoxRect, int x, float MaxHeight, bool AutoWidth, const std::vector<T> &vData, const FDropdownRenderCallback<T> &pfnMatchCallback) |
| 402 | { |
| 403 | // Do an edit box with a possible dropdown |
| 404 | // This is a generic method which can display any data we want |
| 405 | |
| 406 | pDropdown->m_Selected = std::clamp(pDropdown->m_Selected, -1, (int)vData.size() - 1); |
| 407 | |
| 408 | if(Input()->KeyPress(KEY_SPACE) && Input()->ModifierIsPressed()) |
| 409 | { // Handle Ctrl+Space to show available options |
| 410 | pDropdown->m_ShortcutUsed = true; |
| 411 | // Remove inserted space |
| 412 | pLineInput->SetRange("", pLineInput->GetCursorOffset() - 1, pLineInput->GetCursorOffset()); |
| 413 | } |
| 414 | |
| 415 | if((!pDropdown->m_ShouldHide && !pLineInput->IsEmpty() && (pLineInput->IsActive() || pDropdown->m_MousePressedInside)) || pDropdown->m_ShortcutUsed) |
| 416 | { |
| 417 | if(!pDropdown->m_Visible) |
| 418 | { |
| 419 | pDropdown->m_DidBecomeVisible = true; |
| 420 | pDropdown->m_Visible = true; |
| 421 | } |
| 422 | else if(pDropdown->m_DidBecomeVisible) |
| 423 | pDropdown->m_DidBecomeVisible = false; |
| 424 | |
| 425 | if(!pLineInput->IsEmpty() || !pLineInput->IsActive()) |
| 426 | pDropdown->m_ShortcutUsed = false; |
| 427 | |
| 428 | int CurrentSelected = pDropdown->m_Selected; |
| 429 | |
| 430 | // Use tab to navigate through entries |
| 431 | if(Ui()->ConsumeHotkey(CUi::HOTKEY_TAB) && !vData.empty()) |
| 432 | { |
| 433 | int Direction = Input()->ShiftIsPressed() ? -1 : 1; |
| 434 | |
| 435 | pDropdown->m_Selected += Direction; |
| 436 | if(pDropdown->m_Selected < 0) |
| 437 | pDropdown->m_Selected = (int)vData.size() - 1; |
| 438 | pDropdown->m_Selected %= vData.size(); |
| 439 | } |
| 440 | |
| 441 | int Selected = RenderEditBoxDropdown<T>(pDropdown, *pEditBoxRect, pLineInput, x, MaxHeight, AutoWidth, vData, pfnMatchCallback); |
| 442 | if(Selected != -1) |
| 443 | pDropdown->m_Selected = Selected; |
| 444 | |
| 445 | if(CurrentSelected != pDropdown->m_Selected) |
| 446 | pDropdown->m_ListBox.ScrollToSelected(); |
| 447 | |
| 448 | return pDropdown->m_Selected; |
| 449 | } |
| 450 | else |
| 451 | { |
| 452 | pDropdown->m_ShortcutUsed = false; |
| 453 | pDropdown->m_Visible = false; |
| 454 | pDropdown->m_ListBox.SetActive(false); |
| 455 | pDropdown->m_Selected = -1; |
| 456 | } |
| 457 | |
| 458 | return -1; |
nothing calls this directly
no test coverage detected