From 664412dd4e0a625a3e46e10a5c96f32c340e8545 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Thu, 8 Aug 2024 15:56:20 +0800 Subject: [PATCH] [feat] enable Enter key pressing for ImGui::InputText() method --- src/single_window/connection_status_window.cpp | 9 ++++++--- src/single_window/remote_peer_window.cpp | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/single_window/connection_status_window.cpp b/src/single_window/connection_status_window.cpp index 57aa110..91f02cc 100644 --- a/src/single_window/connection_status_window.cpp +++ b/src/single_window/connection_status_window.cpp @@ -81,14 +81,17 @@ int Render::ConnectionStatusWindow() { ImGui::SetNextItemWidth(IPUT_WINDOW_WIDTH / 2); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); - ImGui::InputText("##password", (char *)remote_password_.c_str(), 7, - ImGuiInputTextFlags_CharsNoBlank); + bool enter_pressed = + ImGui::InputText("##password", (char *)remote_password_.c_str(), 7, + ImGuiInputTextFlags_CharsNoBlank | + ImGuiInputTextFlags_EnterReturnsTrue); ImGui::PopStyleVar(); ImGui::SetCursorPosX(window_width * 0.315f); ImGui::SetCursorPosY(window_height * 0.75f); // OK - if (ImGui::Button( + if (enter_pressed || + ImGui::Button( localization::ok[localization_language_index_].c_str())) { show_connection_status_window_ = true; password_validating_ = true; diff --git a/src/single_window/remote_peer_window.cpp b/src/single_window/remote_peer_window.cpp index 419c521..1bb5564 100644 --- a/src/single_window/remote_peer_window.cpp +++ b/src/single_window/remote_peer_window.cpp @@ -46,12 +46,14 @@ int Render::RemoteWindow() { ImGui::SetNextItemWidth(IPUT_WINDOW_WIDTH); ImGui::SetWindowFontScale(1.0f); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); - ImGui::InputText( + bool enter_pressed = ImGui::InputText( "##remote_id_", remote_id_, IM_ARRAYSIZE(remote_id_), - ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank); + ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | + ImGuiInputTextFlags_EnterReturnsTrue); ImGui::PopStyleVar(); ImGui::SameLine(); - if (ImGui::Button(ICON_FA_ARROW_RIGHT_LONG, ImVec2(55, 38)) || rejoin_) { + if (ImGui::Button(ICON_FA_ARROW_RIGHT_LONG, ImVec2(55, 38)) || + enter_pressed || rejoin_) { connect_button_pressed_ = true; connection_status_ = ConnectionStatus::Connecting; int ret = -1;