From c487d3a62cebed28ebf49497593d6d65444b75fe Mon Sep 17 00:00:00 2001 From: dijunkun Date: Sat, 18 Jul 2026 22:03:10 +0800 Subject: [PATCH] [fix] refine recent connections overflow layout, refs #85 --- src/gui/panels/recent_connections_panel.cpp | 67 +++++++++------------ src/gui/render.cpp | 40 ++++++------ 2 files changed, 48 insertions(+), 59 deletions(-) diff --git a/src/gui/panels/recent_connections_panel.cpp b/src/gui/panels/recent_connections_panel.cpp index c2a4a90..9565b3d 100644 --- a/src/gui/panels/recent_connections_panel.cpp +++ b/src/gui/panels/recent_connections_panel.cpp @@ -82,6 +82,16 @@ int Render::ShowRecentConnections() { float recent_connection_footer_height = recent_connection_button_height * 1.18f; float recent_connection_name_width = recent_connection_image_width; + const float recent_connection_spacing = recent_connection_image_width * 0.16f; + const float recent_connections_content_width = + recent_connections_.empty() + ? 0.0f + : recent_connections_.size() * recent_connection_sub_container_width + + (recent_connections_.size() - 1) * recent_connection_spacing; + const float recent_connections_available_width = + recent_connection_panel_width - 2.0f * ImGui::GetStyle().WindowPadding.x; + const bool has_horizontal_overflow = + recent_connections_content_width > recent_connections_available_width; ImGui::SetCursorPos( ImVec2(io.DisplaySize.x * 0.045f, io.DisplaySize.y * 0.1f)); @@ -92,10 +102,10 @@ int Render::ShowRecentConnections() { ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f); const ImGuiWindowFlags container_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | - ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoScrollWithMouse | - (recent_connections_.empty() - ? ImGuiWindowFlags_None - : ImGuiWindowFlags_AlwaysHorizontalScrollbar); + ImGuiWindowFlags_NoBringToFrontOnFocus | + ImGuiWindowFlags_NoScrollWithMouse | + (has_horizontal_overflow ? ImGuiWindowFlags_AlwaysHorizontalScrollbar + : ImGuiWindowFlags_None); ImGui::BeginChild( "RecentConnectionsContainer", ImVec2(recent_connection_panel_width, recent_connection_panel_height), @@ -221,21 +231,19 @@ int Render::ShowRecentConnections() { if (show_image_tooltip) { const ImVec2 mouse_pos = ImGui::GetMousePos(); - const bool place_tooltip_on_left = - mouse_pos.x > io.DisplaySize.x * 0.7f; + const bool place_tooltip_on_left = mouse_pos.x > io.DisplaySize.x * 0.7f; ImGui::SetNextWindowPos( ImVec2(mouse_pos.x + (place_tooltip_on_left ? -12.0f : 12.0f), mouse_pos.y - 8.0f), - ImGuiCond_Always, - ImVec2(place_tooltip_on_left ? 1.0f : 0.0f, 1.0f)); + ImGuiCond_Always, ImVec2(place_tooltip_on_left ? 1.0f : 0.0f, 1.0f)); ImGui::BeginTooltip(); ImGui::SetWindowFontScale(0.4f); - ImGui::Text("%s: %s", - localization::device_name[localization_language_index_] - .c_str(), - display_name.c_str()); + ImGui::Text( + "%s: %s", + localization::device_name[localization_language_index_].c_str(), + display_name.c_str()); if (!it.second.remote_host_name.empty() && it.second.remote_host_name != display_name) { @@ -295,8 +303,8 @@ int Render::ShowRecentConnections() { const float t = static_cast(i) / halo_layers; const float r = dot_radius + (halo_radius - dot_radius) * t; const int alpha = static_cast(14.0f * (1.0f - t) + 4.0f); - draw_list->AddCircleFilled( - dot_center, r, IM_COL32(74, 222, 128, alpha)); + draw_list->AddCircleFilled(dot_center, r, + IM_COL32(74, 222, 128, alpha)); } } draw_list->AddCircleFilled(dot_center, dot_radius, dot_color); @@ -306,12 +314,11 @@ int Render::ShowRecentConnections() { ImVec2 text_min = ImVec2(status_block_end_x + status_gap, footer_screen_pos.y); - ImVec2 text_max = - ImVec2(card_hovered - ? toolbar_screen_pos.x - status_gap - : footer_screen_end.x - - recent_connection_name_width * 0.05f, - footer_screen_end.y); + ImVec2 text_max = ImVec2( + card_hovered + ? toolbar_screen_pos.x - status_gap + : footer_screen_end.x - recent_connection_name_width * 0.05f, + footer_screen_end.y); ImGui::SetWindowFontScale(0.52f); @@ -424,20 +431,6 @@ int Render::ShowRecentConnections() { ImGui::PopStyleVar(3); } - if (count != recent_connections_count - 1) { - ImVec2 line_start = - ImVec2(image_screen_pos.x + recent_connection_image_width * 1.19f, - image_screen_pos.y); - - ImVec2 line_end = - ImVec2(image_screen_pos.x + recent_connection_image_width * 1.19f, - image_screen_pos.y + recent_connection_image_height + - recent_connection_footer_height); - - ImGui::GetWindowDrawList()->AddLine(line_start, line_end, - IM_COL32(0, 0, 0, 122), 1.0f); - } - if (delete_connection_ && delete_connection_name_ == it.first) { if (!thumbnail_->DeleteThumbnail(it.first)) { recent_connection_aliases_.erase(it.second.remote_id); @@ -451,10 +444,10 @@ int Render::ShowRecentConnections() { if (count != recent_connections_count - 1) { ImVec2 line_start = - ImVec2(image_screen_pos.x + recent_connection_image_width * 1.19f, + ImVec2(image_screen_pos.x + recent_connection_image_width * 1.18f, image_screen_pos.y); ImVec2 line_end = - ImVec2(image_screen_pos.x + recent_connection_image_width * 1.19f, + ImVec2(image_screen_pos.x + recent_connection_image_width * 1.18f, image_screen_pos.y + recent_connection_image_height + recent_connection_footer_height); ImGui::GetWindowDrawList()->AddLine(line_start, line_end, @@ -463,7 +456,7 @@ int Render::ShowRecentConnections() { count++; ImGui::SameLine(0, count != recent_connections_count - ? (recent_connection_image_width * 0.165f) + ? recent_connection_spacing : 0.0f); } diff --git a/src/gui/render.cpp b/src/gui/render.cpp index 43b55d7..2bec934 100644 --- a/src/gui/render.cpp +++ b/src/gui/render.cpp @@ -742,10 +742,9 @@ void Render::BeginEditRecentConnectionAlias( memset(edit_connection_alias_, 0, sizeof(edit_connection_alias_)); const auto alias_it = recent_connection_aliases_.find(connection.remote_id); - std::string alias = - alias_it != recent_connection_aliases_.end() - ? alias_it->second - : GetRecentConnectionDisplayName(connection); + std::string alias = alias_it != recent_connection_aliases_.end() + ? alias_it->second + : GetRecentConnectionDisplayName(connection); if (!alias.empty()) { strncpy(edit_connection_alias_, alias.c_str(), @@ -781,21 +780,17 @@ int Render::ScreenCapturerInit() { fps, [this, fps](unsigned char* data, int size, int width, int height, const char* display_name) -> void { - const auto now_time = - static_cast(std::chrono::duration_cast< - std::chrono::milliseconds>( - std::chrono::steady_clock::now() - .time_since_epoch()) - .count()); + const auto now_time = static_cast( + std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch()) + .count()); auto duration = now_time - last_frame_time_; if (duration * fps >= 1000) { // ~60 FPS const std::string stream_id = display_name ? display_name : ""; const bool resumed_after_gap = - last_frame_time_ != 0 && - duration >= kCaptureResumeKeyFrameGapMs; - const bool stream_changed = - !last_video_frame_stream_id_.empty() && - last_video_frame_stream_id_ != stream_id; + last_frame_time_ != 0 && duration >= kCaptureResumeKeyFrameGapMs; + const bool stream_changed = !last_video_frame_stream_id_.empty() && + last_video_frame_stream_id_ != stream_id; if (resumed_after_gap || stream_changed) { if (RequestVideoKeyFrame(peer_, stream_id.c_str()) == 0) { LOG_INFO( @@ -1151,8 +1146,7 @@ int Render::CreateConnectionPeer() { ConfigCenter::VIDEO_ENCODE_FORMAT::AV1 ? true : false; - params_.turn_mode = - static_cast(config_center_->GetTurnMode()); + params_.turn_mode = static_cast(config_center_->GetTurnMode()); params_.enable_srtp = config_center_->IsEnableSrtp(); params_.video_quality = static_cast(config_center_->GetVideoQuality()); @@ -1386,9 +1380,8 @@ int Render::CreateMainWindow() { tray_ = std::make_unique(main_window_, "CrossDesk", localization_language_index_); #elif defined(__linux__) && !defined(__APPLE__) - tray_ = std::make_unique(main_window_, "CrossDesk", - localization_language_index_, - APP_EXIT_EVENT); + tray_ = std::make_unique( + main_window_, "CrossDesk", localization_language_index_, APP_EXIT_EVENT); #endif ImGui_ImplSDL3_InitForSDLRenderer(main_window_, main_renderer_); @@ -1937,7 +1930,9 @@ int Render::Run() { } else { latest_version_ = ""; update_available_ = false; - LOG_WARN("Update check skipped: version.json is empty or missing latest_version"); + LOG_WARN( + "Update check skipped: version.json is empty or missing " + "latest_version"); } InitializeSettings(); @@ -2292,7 +2287,8 @@ void Render::HandleWindowsServiceIntegration() { last_logged_service_error_code = 0; } - RemoteAction remote_action = BuildWindowsServiceStatusAction(broadcast_status); + RemoteAction remote_action = + BuildWindowsServiceStatusAction(broadcast_status); std::string msg = remote_action.to_json(); int ret = SendReliableDataFrame(peer_, msg.data(), msg.size(), control_data_label_.c_str());