Add a button which can copy local id to clipboard

This commit is contained in:
dijunkun
2024-07-03 11:03:04 +08:00
parent 95ad605b36
commit b822221d7f
6 changed files with 1366 additions and 1189 deletions

View File

@@ -18,32 +18,40 @@ int Render::ConnectionStatusWindow() {
connection_status_window_height_));
ImGui::SetWindowFontScale(0.5f);
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0, 1.0, 1.0, 1.0));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
ImGui::Begin("ConnectionStatusWindow", nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoSavedSettings);
ImGui::SetWindowFontScale(1.0f);
ImGui::SetCursorPosX(connection_status_window_width_ * 1 / 3);
ImGui::SetCursorPosY(connection_status_window_height_ * 1 / 3);
ImGui::SetWindowFontScale(0.5f);
ImGui::SetWindowFontScale(0.6f);
std::string text;
if (ConnectionStatus::Connecting == connection_status_) {
ImGui::Text("Connecting...");
text = "Connecting...";
} else if (ConnectionStatus::Connected == connection_status_) {
ImGui::Text("Connected");
text = "Connected";
} else if (ConnectionStatus::Disconnected == connection_status_) {
ImGui::Text("Disonnected");
text = "Disonnected";
} else if (ConnectionStatus::Failed == connection_status_) {
ImGui::Text("Failed");
text = "Failed";
} else if (ConnectionStatus::Closed == connection_status_) {
ImGui::Text("Closed");
text = "Closed";
} else if (ConnectionStatus::IncorrectPassword == connection_status_) {
ImGui::Text("Incorrect password");
text = "Incorrect password";
} else if (ConnectionStatus::NoSuchTransmissionId == connection_status_) {
ImGui::Text("No such transmissionId");
text = "No such transmissionId";
}
auto window_width = ImGui::GetWindowSize().x;
auto window_height = ImGui::GetWindowSize().y;
auto text_width = ImGui::CalcTextSize(text.c_str()).x;
ImGui::SetCursorPosX((window_width - text_width) * 0.5f);
ImGui::SetCursorPosY(window_height * 0.3f);
ImGui::Text("%s", text.c_str());
ImGui::SetWindowFontScale(1.0f);
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
@@ -59,6 +67,8 @@ int Render::ConnectionStatusWindow() {
ImGui::SetWindowFontScale(0.5f);
ImGui::End();
ImGui::PopStyleVar(2);
ImGui::PopStyleColor();
ImGui::SetWindowFontScale(1.0f);
}
return 0;

View File

@@ -1,6 +1,7 @@
#include "IconsFontAwesome6.h"
#include "layout_style.h"
#include "localization.h"
#include "log.h"
#include "render.h"
int Render::LocalWindow() {
@@ -41,6 +42,62 @@ int Render::LocalWindow() {
"##local_id", (char *)mac_addr_str_.c_str(),
mac_addr_str_.length() + 1,
ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_ReadOnly);
ImGui::SameLine();
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));
ImGui::SetWindowFontScale(0.5f);
if (ImGui::Button(ICON_FA_COPY, ImVec2(35, 38))) {
local_id_copied_ = true;
ImGui::SetClipboardText(mac_addr_str_.c_str());
copy_start_time_ = ImGui::GetTime();
}
auto time_duration = ImGui::GetTime() - copy_start_time_;
if (local_id_copied_ && time_duration < 1.0f) {
const ImGuiViewport *viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(
ImVec2((viewport->WorkSize.x - viewport->WorkPos.x -
notification_window_width_) /
2,
(viewport->WorkSize.y - viewport->WorkPos.y -
notification_window_height_) /
2));
ImGui::SetNextWindowSize(
ImVec2(notification_window_width_, notification_window_height_));
ImGui::PushStyleColor(ImGuiCol_WindowBg,
ImVec4(1.0, 1.0, 1.0, 1.0 - time_duration));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
ImGui::Begin("ConnectionStatusWindow", nullptr,
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoSavedSettings);
auto window_width = ImGui::GetWindowSize().x;
auto window_height = ImGui::GetWindowSize().y;
ImGui::SetWindowFontScale(0.8f);
std::string text = localization::local_id_copied_to_clipboard
[localization_language_index_];
auto text_width = ImGui::CalcTextSize(text.c_str()).x;
ImGui::SetCursorPosX((window_width - text_width) * 0.5f);
ImGui::SetCursorPosY(window_height * 0.5f);
ImGui::PushStyleColor(ImGuiCol_Text,
ImVec4(0, 0, 0, 1.0 - time_duration));
ImGui::Text("%s", text.c_str());
ImGui::PopStyleColor();
ImGui::SetWindowFontScale(1.0f);
ImGui::End();
ImGui::PopStyleVar(2);
ImGui::PopStyleColor();
}
ImGui::SetWindowFontScale(1.0f);
ImGui::PopStyleColor(3);
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();

View File

@@ -45,6 +45,7 @@ int Render::RemoteWindow() {
ImGui::SameLine();
if (ImGui::Button(ICON_FA_ARROW_RIGHT_LONG, ImVec2(55, 38)) || rejoin_) {
connect_button_pressed_ = true;
connection_status_ = ConnectionStatus::Connecting;
int ret = -1;
if (signal_connected_) {
if (!connection_established_) {

View File

@@ -128,6 +128,8 @@ class Render {
int status_bar_height_ = 20;
int connection_status_window_width_ = 200;
int connection_status_window_height_ = 150;
int notification_window_width_ = 200;
int notification_window_height_ = 80;
int main_window_width_real_ = 960;
int main_window_height_real_ = 540;
@@ -159,10 +161,12 @@ class Render {
bool audio_buffer_fresh_ = false;
bool rejoin_ = false;
bool control_mouse_ = false;
bool local_id_copied_ = false;
bool show_password_ = true;
bool regenerate_password_ = false;
bool streaming_ = false;
double copy_start_time_ = 0;
int regenerate_password_frame_count_ = 0;
int fps_ = 0;