From c3af40a3f09a10e3cc53e2ccefcdb69182d63811 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Thu, 12 Sep 2024 16:22:02 +0800 Subject: [PATCH] [feat] add close button in control bar --- .../connection_status_window.cpp | 49 ++++++++++--------- src/single_window/control_bar.cpp | 15 ++++-- src/single_window/render.cpp | 6 ++- src/single_window/render.h | 4 +- 4 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/single_window/connection_status_window.cpp b/src/single_window/connection_status_window.cpp index 815428c..ac088d0 100644 --- a/src/single_window/connection_status_window.cpp +++ b/src/single_window/connection_status_window.cpp @@ -44,27 +44,33 @@ int Render::ConnectionStatusWindow() { text = localization::p2p_disconnected[localization_language_index_]; ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); - // Cancel + // ok if (ImGui::Button( - localization::cancel[localization_language_index_].c_str())) { + localization::ok[localization_language_index_].c_str()) || + ImGui::IsKeyPressed(ImGuiKey_Enter) || + ImGui::IsKeyPressed(ImGuiKey_Escape)) { show_connection_status_window_ = false; } } else if (ConnectionStatus::Failed == connection_status_) { text = localization::p2p_failed[localization_language_index_]; ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); - // Cancel + // ok if (ImGui::Button( - localization::cancel[localization_language_index_].c_str())) { + localization::ok[localization_language_index_].c_str()) || + ImGui::IsKeyPressed(ImGuiKey_Enter) || + ImGui::IsKeyPressed(ImGuiKey_Escape)) { show_connection_status_window_ = false; } } else if (ConnectionStatus::Closed == connection_status_) { text = localization::p2p_closed[localization_language_index_]; ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); - // Cancel + // ok if (ImGui::Button( - localization::ok[localization_language_index_].c_str())) { + localization::ok[localization_language_index_].c_str()) || + ImGui::IsKeyPressed(ImGuiKey_Enter) || + ImGui::IsKeyPressed(ImGuiKey_Escape)) { show_connection_status_window_ = false; } } else if (ConnectionStatus::IncorrectPassword == connection_status_) { @@ -86,19 +92,18 @@ int Render::ConnectionStatusWindow() { ImGui::SetKeyboardFocusHere(); focus_on_input_widget_ = false; } - bool enter_pressed = ImGui::InputText( - "##password", remote_password_, IM_ARRAYSIZE(remote_password_), - ImGuiInputTextFlags_CharsNoBlank | - ImGuiInputTextFlags_EnterReturnsTrue); + ImGui::InputText("##password", remote_password_, + IM_ARRAYSIZE(remote_password_), + ImGuiInputTextFlags_CharsNoBlank); ImGui::PopStyleVar(); ImGui::SetCursorPosX(window_width * 0.315f); ImGui::SetCursorPosY(window_height * 0.75f); - // OK - if (enter_pressed || - ImGui::Button( - localization::ok[localization_language_index_].c_str())) { + // ok + if (ImGui::Button( + localization::ok[localization_language_index_].c_str()) || + ImGui::IsKeyPressed(ImGuiKey_Enter)) { show_connection_status_window_ = true; password_validating_ = true; rejoin_ = true; @@ -106,27 +111,27 @@ int Render::ConnectionStatusWindow() { } ImGui::SameLine(); - + // cancel if (ImGui::Button( - localization::cancel[localization_language_index_].c_str())) { + localization::cancel[localization_language_index_].c_str()) || + ImGui::IsKeyPressed(ImGuiKey_Escape)) { memset(remote_password_, 0, sizeof(remote_password_)); show_connection_status_window_ = false; focus_on_input_widget_ = true; } - } else { + } else if (password_validating_) { text = localization::validate_password[localization_language_index_]; ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); } - } - - else if (ConnectionStatus::NoSuchTransmissionId == connection_status_) { + } else if (ConnectionStatus::NoSuchTransmissionId == connection_status_) { text = localization::no_such_id[localization_language_index_]; ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); - // Cancel + // ok if (ImGui::Button( - localization::cancel[localization_language_index_].c_str())) { + localization::ok[localization_language_index_].c_str()) || + ImGui::IsKeyPressed(ImGuiKey_Escape)) { show_connection_status_window_ = false; } } diff --git a/src/single_window/control_bar.cpp b/src/single_window/control_bar.cpp index cbddd37..09a9927 100644 --- a/src/single_window/control_bar.cpp +++ b/src/single_window/control_bar.cpp @@ -10,7 +10,7 @@ int Render::ControlBar() { if (control_bar_expand_) { ImGui::SetCursorPosX( is_control_bar_in_left_ ? (control_window_width_ + 5.0f) : 53.0f); - // Mouse control + // mouse control button ImDrawList* draw_list = ImGui::GetWindowDrawList(); if (is_control_bar_in_left_) { @@ -50,7 +50,7 @@ int Render::ControlBar() { } ImGui::SameLine(); - // Audio capture + // audio capture button float disable_audio_x = ImGui::GetCursorScreenPos().x + 4; float disable_audio_y = ImGui::GetCursorScreenPos().y + 4.0f; // std::string audio = audio_capture_button_pressed_ ? ICON_FA_VOLUME_HIGH @@ -87,7 +87,7 @@ int Render::ControlBar() { } ImGui::SameLine(); - // Fullscreen + // fullscreen button std::string fullscreen = fullscreen_button_pressed_ ? ICON_FA_COMPRESS : ICON_FA_EXPAND; if (ImGui::Button(fullscreen.c_str(), ImVec2(25, 25))) { @@ -103,6 +103,15 @@ int Render::ControlBar() { } } + ImGui::SameLine(); + // close button + std::string close_button = ICON_FA_XMARK; + if (ImGui::Button(close_button.c_str(), ImVec2(25, 25))) { + SDL_Event event; + event.type = SDL_QUIT; + SDL_PushEvent(&event); + } + ImGui::SameLine(); if (!is_control_bar_in_left_) { diff --git a/src/single_window/render.cpp b/src/single_window/render.cpp index 098a30e..d58923a 100644 --- a/src/single_window/render.cpp +++ b/src/single_window/render.cpp @@ -24,6 +24,9 @@ SDL_HitTestResult Render::HitTestCallback(SDL_Window *window, const SDL_Point *area, void *data) { Render *render = (Render *)data; + if (!render) { + return SDL_HITTEST_NORMAL; + } int window_width, window_height; SDL_GetWindowSize(window, &window_width, &window_height); @@ -387,7 +390,8 @@ int Render::Run() { IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO &io = ImGui::GetIO(); - + // Master keyboard navigation enable flag. Enable full Tabbing + directional + // arrows + space/enter to activate. io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io.ConfigFlags |= diff --git a/src/single_window/render.h b/src/single_window/render.h index 085fb39..f52c07a 100644 --- a/src/single_window/render.h +++ b/src/single_window/render.h @@ -146,8 +146,8 @@ class Render { int main_window_width_before_maximized_ = 960; int main_window_height_before_maximized_ = 570; int control_window_min_width_ = 20; - int control_window_max_width_ = 150; - int control_window_width_ = 150; + int control_window_max_width_ = 170; + int control_window_width_ = 170; int control_window_height_ = 40; int local_window_width_ = 350; int status_bar_height_ = 20;