[fix] fix thumbnail order by using std::vector instead of std::unordered_map

This commit is contained in:
dijunkun
2025-07-23 16:38:29 +08:00
parent 1327b995f2
commit 147b9b2ddc
5 changed files with 34 additions and 31 deletions

View File

@@ -60,13 +60,11 @@ int Render::ShowRecentConnections() {
int count = 0; int count = 0;
float button_width = 22; float button_width = 22;
float button_height = 22; float button_height = 22;
for (auto it = recent_connections_.begin(); it != recent_connections_.end(); for (auto& it : recent_connections_) {
++it) { sub_containers_pos[it.first] = ImGui::GetCursorPos();
sub_containers_pos[it->first] = ImGui::GetCursorPos();
std::string recent_connection_sub_window_name = std::string recent_connection_sub_window_name =
"RecentConnectionsSubContainer" + it->first; "RecentConnectionsSubContainer" + it.first;
// recent connections sub container // recent connections sub container
ImGui::BeginChild(recent_connection_sub_window_name.c_str(), ImGui::BeginChild(recent_connection_sub_window_name.c_str(),
ImVec2(recent_connection_sub_container_width, ImVec2(recent_connection_sub_container_width,
recent_connection_sub_container_height), recent_connection_sub_container_height),
@@ -76,7 +74,7 @@ int Render::ShowRecentConnections() {
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoScrollbar); ImGuiWindowFlags_NoScrollbar);
std::string connection_info = it->first; std::string connection_info = it.first;
// remote id length is 9 // remote id length is 9
// password length is 6 // password length is 6
@@ -92,11 +90,11 @@ int Render::ShowRecentConnections() {
continue; continue;
} }
it->second.remote_id = connection_info.substr(0, pos_y); it.second.remote_id = connection_info.substr(0, pos_y);
it->second.remote_host_name = it.second.remote_host_name =
connection_info.substr(pos_y + 1, pos_at - pos_y - 1); connection_info.substr(pos_y + 1, pos_at - pos_y - 1);
it->second.password = connection_info.substr(pos_at + 1); it.second.password = connection_info.substr(pos_at + 1);
it->second.remember_password = true; it.second.remember_password = true;
} else if ('N' == connection_info[9] && connection_info.size() >= 10) { } else if ('N' == connection_info[9] && connection_info.size() >= 10) {
size_t pos_n = connection_info.find('N'); size_t pos_n = connection_info.find('N');
size_t pos_at = connection_info.find('@'); size_t pos_at = connection_info.find('@');
@@ -106,12 +104,12 @@ int Render::ShowRecentConnections() {
continue; continue;
} }
it->second.remote_id = connection_info.substr(0, pos_n); it.second.remote_id = connection_info.substr(0, pos_n);
it->second.remote_host_name = connection_info.substr(pos_n + 1); it.second.remote_host_name = connection_info.substr(pos_n + 1);
it->second.password = ""; it.second.password = "";
it->second.remember_password = false; it.second.remember_password = false;
} else { } else {
it->second.remote_host_name = "unknown"; it.second.remote_host_name = "unknown";
} }
ImVec2 image_screen_pos = ImVec2(ImGui::GetCursorScreenPos().x + 5.0f, ImVec2 image_screen_pos = ImVec2(ImGui::GetCursorScreenPos().x + 5.0f,
@@ -119,7 +117,7 @@ int Render::ShowRecentConnections() {
ImVec2 image_pos = ImVec2 image_pos =
ImVec2(ImGui::GetCursorPosX() + 5.0f, ImGui::GetCursorPosY() + 5.0f); ImVec2(ImGui::GetCursorPosX() + 5.0f, ImGui::GetCursorPosY() + 5.0f);
ImGui::SetCursorPos(image_pos); ImGui::SetCursorPos(image_pos);
ImGui::Image((ImTextureID)(intptr_t)it->second.texture, ImGui::Image((ImTextureID)(intptr_t)it.second.texture,
ImVec2((float)recent_connection_image_width_, ImVec2((float)recent_connection_image_width_,
(float)recent_connection_image_height_)); (float)recent_connection_image_height_));
@@ -131,7 +129,7 @@ int Render::ShowRecentConnections() {
ImVec2 dummy_button_pos = ImVec2 dummy_button_pos =
ImVec2(image_pos.x, image_pos.y + recent_connection_image_height_); ImVec2(image_pos.x, image_pos.y + recent_connection_image_height_);
std::string dummy_button_name = "##DummyButton" + it->second.remote_id; std::string dummy_button_name = "##DummyButton" + it.second.remote_id;
ImGui::SetCursorPos(dummy_button_pos); ImGui::SetCursorPos(dummy_button_pos);
ImGui::SetWindowFontScale(0.6f); ImGui::SetWindowFontScale(0.6f);
ImGui::Button(dummy_button_name.c_str(), ImGui::Button(dummy_button_name.c_str(),
@@ -141,14 +139,14 @@ int Render::ShowRecentConnections() {
ImGui::SetCursorPos( ImGui::SetCursorPos(
ImVec2(dummy_button_pos.x + 2.0f, dummy_button_pos.y + 1.0f)); ImVec2(dummy_button_pos.x + 2.0f, dummy_button_pos.y + 1.0f));
ImGui::SetWindowFontScale(0.65f); ImGui::SetWindowFontScale(0.65f);
ImGui::Text("%s", it->second.remote_id.c_str()); ImGui::Text("%s", it.second.remote_id.c_str());
ImGui::SetWindowFontScale(1.0f); ImGui::SetWindowFontScale(1.0f);
ImGui::PopStyleColor(3); ImGui::PopStyleColor(3);
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip(); ImGui::BeginTooltip();
ImGui::SetWindowFontScale(0.5f); ImGui::SetWindowFontScale(0.5f);
ImGui::Text("%s", it->second.remote_host_name.c_str()); ImGui::Text("%s", it.second.remote_host_name.c_str());
ImGui::SetWindowFontScale(1.0f); ImGui::SetWindowFontScale(1.0f);
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
@@ -173,11 +171,11 @@ int Render::ShowRecentConnections() {
if (ImGui::Button(recent_connection_delete_button_name.c_str(), if (ImGui::Button(recent_connection_delete_button_name.c_str(),
ImVec2(button_width, button_height))) { ImVec2(button_width, button_height))) {
show_confirm_delete_connection_ = true; show_confirm_delete_connection_ = true;
delete_connection_name_ = it->first; delete_connection_name_ = it.first;
} }
if (delete_connection_ && delete_connection_name_ == it->first) { if (delete_connection_ && delete_connection_name_ == it.first) {
if (!thumbnail_->DeleteThumbnail(it->first)) { if (!thumbnail_->DeleteThumbnail(it.first)) {
reload_recent_connections_ = true; reload_recent_connections_ = true;
delete_connection_ = false; delete_connection_ = false;
} }
@@ -192,11 +190,11 @@ int Render::ShowRecentConnections() {
ImGui::SetCursorPos(connect_button_pos); ImGui::SetCursorPos(connect_button_pos);
std::string connect = ICON_FA_ARROW_RIGHT_LONG; std::string connect = ICON_FA_ARROW_RIGHT_LONG;
std::string connect_to_this_connection_button_name = std::string connect_to_this_connection_button_name =
connect + "##ConnectionTo" + it->first; connect + "##ConnectionTo" + it.first;
if (ImGui::Button(connect_to_this_connection_button_name.c_str(), if (ImGui::Button(connect_to_this_connection_button_name.c_str(),
ImVec2(button_width, button_height))) { ImVec2(button_width, button_height))) {
ConnectTo(it->second.remote_id, it->second.password.c_str(), ConnectTo(it.second.remote_id, it.second.password.c_str(),
it->second.remember_password); it.second.remember_password);
} }
} }
ImGui::SetWindowFontScale(1.0f); ImGui::SetWindowFontScale(1.0f);

View File

@@ -1140,6 +1140,8 @@ void Render::CleanupFactories() {
} }
void Render::CleanupPeer(std::shared_ptr<SubStreamWindowProperties> props) { void Render::CleanupPeer(std::shared_ptr<SubStreamWindowProperties> props) {
SDL_FlushEvent(STREAM_FRASH);
if (props->dst_buffer_) { if (props->dst_buffer_) {
thumbnail_->SaveToThumbnail( thumbnail_->SaveToThumbnail(
(char*)props->dst_buffer_, props->video_width_, props->video_height_, (char*)props->dst_buffer_, props->video_width_, props->video_height_,

View File

@@ -277,7 +277,7 @@ class Render {
std::unique_ptr<Thumbnail> thumbnail_; std::unique_ptr<Thumbnail> thumbnail_;
// recent connections // recent connections
std::unordered_map<std::string, Thumbnail::RecentConnection> std::vector<std::pair<std::string, Thumbnail::RecentConnection>>
recent_connections_; recent_connections_;
int recent_connection_image_width_ = 160; int recent_connection_image_width_ = 160;
int recent_connection_image_height_ = 90; int recent_connection_image_height_ = 90;

View File

@@ -195,7 +195,8 @@ int Thumbnail::SaveToThumbnail(const char* yuv420p, int width, int height,
int Thumbnail::LoadThumbnail( int Thumbnail::LoadThumbnail(
SDL_Renderer* renderer, SDL_Renderer* renderer,
std::unordered_map<std::string, RecentConnection>& recent_connections, std::vector<std::pair<std::string, Thumbnail::RecentConnection>>&
recent_connections,
int* width, int* height) { int* width, int* height) {
for (auto& it : recent_connections) { for (auto& it : recent_connections) {
if (it.second.texture != nullptr) { if (it.second.texture != nullptr) {
@@ -255,10 +256,11 @@ int Thumbnail::LoadThumbnail(
} }
std::string image_path = save_path_ + cipher_image_name; std::string image_path = save_path_ + cipher_image_name;
recent_connections[original_image_name].texture = nullptr; recent_connections.emplace_back(
std::make_pair(original_image_name, Thumbnail::RecentConnection()));
LoadTextureFromFile(image_path.c_str(), renderer, LoadTextureFromFile(image_path.c_str(), renderer,
&(recent_connections[original_image_name].texture), &(recent_connections[i].second.texture), width,
width, height); height);
} }
return 0; return 0;
} }

View File

@@ -38,7 +38,8 @@ class Thumbnail {
int LoadThumbnail( int LoadThumbnail(
SDL_Renderer* renderer, SDL_Renderer* renderer,
std::unordered_map<std::string, RecentConnection>& recent_connections, std::vector<std::pair<std::string, Thumbnail::RecentConnection>>&
recent_connections,
int* width, int* height); int* width, int* height);
int DeleteThumbnail(const std::string& filename_keyword); int DeleteThumbnail(const std::string& filename_keyword);