[feat] delete recent connection supported

This commit is contained in:
dijunkun
2024-11-08 17:52:19 +08:00
parent edcf5d408c
commit b6671bdbe7
5 changed files with 69 additions and 19 deletions

View File

@@ -1,3 +1,4 @@
#include "IconsFontAwesome6.h"
#include "localization.h"
#include "rd_log.h"
#include "render.h"
@@ -69,6 +70,13 @@ int Render::MainWindow() {
int Render::ShowRecentConnections() {
ImGui::SetCursorPosX(25.0f);
ImVec2 sub_window_pos = ImGui::GetCursorPos();
std::map<std::string, ImVec2> sub_containers_pos;
int recent_connection_sub_container_width =
recent_connection_image_width_ + 16.0f;
int recent_connection_sub_container_height =
recent_connection_image_height_ + 32.0f;
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::BeginChild("RecentConnectionsContainer",
ImVec2(main_window_width_default_ - 50.0f, 152.0f),
ImGuiChildFlags_Border,
@@ -76,39 +84,66 @@ int Render::ShowRecentConnections() {
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_AlwaysHorizontalScrollbar);
ImGui::PopStyleColor();
int recent_connections_count = recent_connection_textures_.size();
int count = 0;
for (auto it = recent_connection_textures_.begin();
it != recent_connection_textures_.end(); ++it) {
sub_containers_pos[it->first] = ImGui::GetCursorPos();
std::string recent_connection_sub_window_name =
"RecentConnectionsSubWindow" + it->first;
"RecentConnectionsSubContainer" + it->first;
ImGui::BeginChild(recent_connection_sub_window_name.c_str(),
ImVec2(recent_connection_image_width_ + 16.0f,
recent_connection_image_height_ + 32.0f),
ImVec2(recent_connection_sub_container_width,
recent_connection_sub_container_height),
ImGuiChildFlags_Border,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoScrollbar);
ImGui::Image((ImTextureID)(intptr_t)it->second,
ImVec2((float)recent_connection_image_width_,
(float)recent_connection_image_height_));
size_t pos1 = it->first.find('\\') + 1;
size_t pos2 = it->first.rfind('@');
std::string host_name = it->first.substr(pos1, pos2 - pos1);
ImGui::SetWindowFontScale(0.4f);
ImVec2 window_size = ImGui::GetWindowSize();
ImVec2 text_size = ImGui::CalcTextSize(it->first.c_str());
ImVec2 text_size = ImGui::CalcTextSize(host_name.c_str());
ImVec2 pos = ImGui::GetCursorPos();
pos.x = (window_size.x - text_size.x) / 2.0f;
ImGui::SetCursorPos(pos);
ImGui::Text("%s", it->first.c_str());
ImGui::Text(host_name.c_str());
ImGui::SetWindowFontScale(1.0f);
ImGui::Image((ImTextureID)(intptr_t)it->second,
ImVec2((float)recent_connection_image_width_,
(float)recent_connection_image_height_));
ImGui::EndChild();
count++;
ImGui::SameLine(0, count != recent_connections_count ? 23.0f : 0.0f);
}
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0, 0, 0, 0));
for (const auto& pos : sub_containers_pos) {
ImVec2 delete_button_pos =
ImVec2(pos.second.x + recent_connection_sub_container_width - 11.0f,
pos.second.y - 7.0f);
ImGui::SetCursorPos(delete_button_pos);
ImGui::SetWindowFontScale(0.5f);
std::string xmake = ICON_FA_CIRCLE_XMARK;
std::string recent_connection_delete_button_name =
xmake + "##RecentConnectionDelete" +
std::to_string(delete_button_pos.x);
if (ImGui::SmallButton(recent_connection_delete_button_name.c_str())) {
if (!thumbnail_.DeleteThumbnail(pos.first)) {
reload_recent_connections_ = true;
}
}
ImGui::SetWindowFontScale(1.0f);
}
ImGui::PopStyleColor(3);
ImGui::EndChild();
return 0;