[fix] fix connection status window gui display

This commit is contained in:
dijunkun
2025-08-19 17:47:09 +08:00
parent 6f8fd6a030
commit 374453775f
5 changed files with 161 additions and 158 deletions

View File

@@ -5,9 +5,8 @@
bool Render::ConnectionStatusWindow( bool Render::ConnectionStatusWindow(
std::shared_ptr<SubStreamWindowProperties> &props) { std::shared_ptr<SubStreamWindowProperties> &props) {
if (show_connection_status_window_) {
const ImGuiViewport *viewport = ImGui::GetMainViewport(); const ImGuiViewport *viewport = ImGui::GetMainViewport();
bool ret_flag = false;
ImGui::SetNextWindowPos(ImVec2((viewport->WorkSize.x - viewport->WorkPos.x - ImGui::SetNextWindowPos(ImVec2((viewport->WorkSize.x - viewport->WorkPos.x -
connection_status_window_width_) / connection_status_window_width_) /
2, 2,
@@ -43,8 +42,7 @@ bool Render::ConnectionStatusWindow(
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// ok // ok
if (ImGui::Button( if (ImGui::Button(localization::ok[localization_language_index_].c_str()) ||
localization::ok[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_Enter) ||
ImGui::IsKeyPressed(ImGuiKey_Escape)) { ImGui::IsKeyPressed(ImGuiKey_Escape)) {
show_connection_status_window_ = false; show_connection_status_window_ = false;
@@ -54,8 +52,7 @@ bool Render::ConnectionStatusWindow(
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// ok // ok
if (ImGui::Button( if (ImGui::Button(localization::ok[localization_language_index_].c_str()) ||
localization::ok[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_Enter) ||
ImGui::IsKeyPressed(ImGuiKey_Escape)) { ImGui::IsKeyPressed(ImGuiKey_Escape)) {
show_connection_status_window_ = false; show_connection_status_window_ = false;
@@ -65,8 +62,7 @@ bool Render::ConnectionStatusWindow(
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// ok // ok
if (ImGui::Button( if (ImGui::Button(localization::ok[localization_language_index_].c_str()) ||
localization::ok[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_Enter) ||
ImGui::IsKeyPressed(ImGuiKey_Escape)) { ImGui::IsKeyPressed(ImGuiKey_Escape)) {
show_connection_status_window_ = false; show_connection_status_window_ = false;
@@ -76,14 +72,12 @@ bool Render::ConnectionStatusWindow(
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// ok // ok
if (ImGui::Button( if (ImGui::Button(localization::ok[localization_language_index_].c_str()) ||
localization::ok[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_Enter) ||
ImGui::IsKeyPressed(ImGuiKey_Escape)) { ImGui::IsKeyPressed(ImGuiKey_Escape)) {
show_connection_status_window_ = false; show_connection_status_window_ = false;
} }
} else if (ConnectionStatus::IncorrectPassword == } else if (ConnectionStatus::IncorrectPassword == props->connection_status_) {
props->connection_status_) {
if (!password_validating_) { if (!password_validating_) {
if (password_validating_time_ == 1) { if (password_validating_time_ == 1) {
text = localization::input_password[localization_language_index_]; text = localization::input_password[localization_language_index_];
@@ -115,8 +109,7 @@ bool Render::ConnectionStatusWindow(
.c_str()); .c_str());
ImGui::SetCursorPosX((window_width - text_size.x) * 0.5f - 13.0f); ImGui::SetCursorPosX((window_width - text_size.x) * 0.5f - 13.0f);
ImGui::Checkbox( ImGui::Checkbox(
localization::remember_password[localization_language_index_] localization::remember_password[localization_language_index_].c_str(),
.c_str(),
&(props->remember_password_)); &(props->remember_password_));
ImGui::SetWindowFontScale(0.5f); ImGui::SetWindowFontScale(0.5f);
ImGui::PopStyleVar(); ImGui::PopStyleVar();
@@ -154,13 +147,12 @@ bool Render::ConnectionStatusWindow(
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// ok // ok
if (ImGui::Button( if (ImGui::Button(localization::ok[localization_language_index_].c_str()) ||
localization::ok[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Enter)) { ImGui::IsKeyPressed(ImGuiKey_Enter)) {
show_connection_status_window_ = false; show_connection_status_window_ = false;
re_enter_remote_id_ = true; re_enter_remote_id_ = true;
DestroyPeer(&props->peer_); DestroyPeer(&props->peer_);
return true; ret_flag = true;
} }
} }
@@ -174,6 +166,6 @@ bool Render::ConnectionStatusWindow(
ImGui::End(); ImGui::End();
ImGui::PopStyleVar(); ImGui::PopStyleVar();
}
return false; return ret_flag;
} }

View File

@@ -29,13 +29,20 @@ int Render::MainWindow() {
RecentConnectionsWindow(); RecentConnectionsWindow();
StatusBar(); StatusBar();
for (auto it = client_properties_.begin(); it != client_properties_.end();) { if (show_connection_status_window_) {
for (auto it = client_properties_.begin();
it != client_properties_.end();) {
auto& props = it->second; auto& props = it->second;
if (focused_remote_id_ == props->remote_id_) {
if (ConnectionStatusWindow(props)) { if (ConnectionStatusWindow(props)) {
it = client_properties_.erase(it); it = client_properties_.erase(it);
} else { } else {
++it; ++it;
} }
} else {
++it;
}
}
} }
return 0; return 0;

View File

@@ -132,6 +132,7 @@ static int InputTextCallback(ImGuiInputTextCallbackData *data) {
int Render::ConnectTo(const std::string &remote_id, const char *password, int Render::ConnectTo(const std::string &remote_id, const char *password,
bool remember_password) { bool remember_password) {
LOG_INFO("Connect to [{}]", remote_id); LOG_INFO("Connect to [{}]", remote_id);
focused_remote_id_ = remote_id;
if (client_properties_.find(remote_id) == client_properties_.end()) { if (client_properties_.find(remote_id) == client_properties_.end()) {
client_properties_[remote_id] = client_properties_[remote_id] =

View File

@@ -343,6 +343,7 @@ class Render {
bool need_to_rejoin_ = false; bool need_to_rejoin_ = false;
bool just_created_ = false; bool just_created_ = false;
std::string controlled_remote_id_ = ""; std::string controlled_remote_id_ = "";
std::string focused_remote_id_ = "";
bool need_to_send_host_info_ = false; bool need_to_send_host_info_ = false;
SDL_Event last_mouse_event; SDL_Event last_mouse_event;

View File

@@ -114,6 +114,8 @@ int Render::StreamWindow() {
ControlWindow(props); ControlWindow(props);
focused_remote_id_ = props->remote_id_;
if (!props->peer_) { if (!props->peer_) {
it = client_properties_.erase(it); it = client_properties_.erase(it);
if (client_properties_.empty()) { if (client_properties_.empty()) {