mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
GameUI: developer console UX improvements
A common request was to make the tab key select the highlighted item in the autocomplete suggest window, much like the enter key. This key however could also be used to instantly select the first item in the autocomplete suggest window without having to move the cursor there.
This commit is contained in:
parent
bd06ddcb74
commit
e05d137acd
@ -280,20 +280,6 @@ bool CConsole::DrawSurface(void)
|
||||
|
||||
ImGui::Text("%s", m_summaryTextBuf);
|
||||
|
||||
const std::function<void(void)> fnHandleInput = [&](void)
|
||||
{
|
||||
if (m_inputTextBuf[0])
|
||||
{
|
||||
ProcessCommand(m_inputTextBuf);
|
||||
ResetAutoCompleteData();
|
||||
|
||||
m_inputTextBufModified = true;
|
||||
}
|
||||
|
||||
BuildSummaryText("");
|
||||
m_reclaimFocus = true;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
const static int inputTextFieldFlags =
|
||||
ImGuiInputTextFlags_EnterReturnsTrue |
|
||||
@ -311,18 +297,19 @@ bool CConsole::DrawSurface(void)
|
||||
// command from that instead
|
||||
if (m_suggestPos > ConAutoCompletePos_e::kPark)
|
||||
{
|
||||
DetermineInputTextFromSelectedSuggestion(m_vecSuggest[m_suggestPos], m_selectedSuggestionText);
|
||||
BuildSummaryText(m_selectedSuggestionText.c_str());
|
||||
|
||||
m_inputTextBufModified = true;
|
||||
m_reclaimFocus = true;
|
||||
HandleSuggest();
|
||||
}
|
||||
else
|
||||
{
|
||||
fnHandleInput();
|
||||
HandleCommand();
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Tab))
|
||||
{
|
||||
HandleSuggest();
|
||||
}
|
||||
|
||||
// Auto-focus input field on window apparition.
|
||||
ImGui::SetItemDefaultFocus();
|
||||
|
||||
@ -338,7 +325,7 @@ bool CConsole::DrawSurface(void)
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Submit"))
|
||||
{
|
||||
fnHandleInput();
|
||||
HandleCommand();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
@ -1104,6 +1091,50 @@ int CConsole::TextEditCallbackStub(ImGuiInputTextCallbackData* iData)
|
||||
return pConsole->TextEditCallback(iData);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: handle anything in the command buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
void CConsole::HandleCommand()
|
||||
{
|
||||
if (m_inputTextBuf[0])
|
||||
{
|
||||
ProcessCommand(m_inputTextBuf);
|
||||
ResetAutoCompleteData();
|
||||
|
||||
m_inputTextBufModified = true;
|
||||
}
|
||||
|
||||
BuildSummaryText("");
|
||||
m_reclaimFocus = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: handle the suggested item that was selected
|
||||
//-----------------------------------------------------------------------------
|
||||
void CConsole::HandleSuggest()
|
||||
{
|
||||
const bool parked = m_suggestPos == ConAutoCompletePos_e::kPark;
|
||||
|
||||
if (parked && m_vecSuggest.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Note: we should never be able to move the suggest pos
|
||||
// if the suggest list is empty. Suggest pos must always
|
||||
// be cleared if the list is cleared.
|
||||
Assert(!m_vecSuggest.empty());
|
||||
|
||||
// Use the first item if the suggest position is parked.
|
||||
const int vecIndex = parked ? 0 : m_suggestPos;
|
||||
|
||||
DetermineInputTextFromSelectedSuggestion(m_vecSuggest[vecIndex], m_selectedSuggestionText);
|
||||
BuildSummaryText(m_selectedSuggestionText.c_str());
|
||||
|
||||
m_inputTextBufModified = true;
|
||||
m_reclaimFocus = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: adds logs to the console; this is the only place text is added to
|
||||
// the vector, do not call 'm_Logger.InsertText' elsewhere as we also manage
|
||||
|
@ -61,6 +61,9 @@ public:
|
||||
static void ClearHistory_f();
|
||||
|
||||
private: // Internals.
|
||||
void HandleCommand();
|
||||
void HandleSuggest();
|
||||
|
||||
void AddLog(const ImU32 color, const char* fmt, ...) /*IM_FMTARGS(2)*/;
|
||||
|
||||
void ClampLogSize(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user