set default focus on chat

This commit is contained in:
2023-10-04 22:28:52 +02:00
parent a24d1bed58
commit d77925ce82
2 changed files with 7 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ class GameChatGui : public GuiWidget, ChatListener {
private:
char InputBuf[256];
std::vector<std::string> Items;
bool m_FocusRequested = false;
void Draw(const char* title, bool* p_open);

View File

@@ -34,6 +34,11 @@ void GameChatGui::Draw(const char* title, bool* p_open) {
ImGui::EndChild();
ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_EscapeClearsAll;
if (m_FocusRequested) {
ImGui::SetKeyboardFocusHere(0);
m_FocusRequested = false;
}
ImGui::SetNextItemWidth(chatInput_width);
if (ImGui::InputText(" ", InputBuf, IM_ARRAYSIZE(InputBuf), input_text_flags)) {
utils::LOG(InputBuf);
@@ -51,6 +56,7 @@ void GameChatGui::Render() {
if (ImGui::IsKeyPressed(ImGuiKey_Enter)) {
showCHAT = true;
m_FocusRequested = true;
} else if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
showCHAT = false;
}