[feat] change UI layouts

This commit is contained in:
dijunkun
2024-11-05 17:29:39 +08:00
parent 863070a8a7
commit 19ea426efc
5 changed files with 85 additions and 78 deletions

View File

@@ -7,18 +7,16 @@
#include "render.h"
int Render::LocalWindow() {
ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_), ImGuiCond_Always);
ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_ + 1), ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::BeginChild(
"LocalDesktopWindow",
ImVec2(local_window_width_, main_window_height_default_ -
title_bar_height_ - status_bar_height_),
ImGuiChildFlags_Border,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::BeginChild("LocalDesktopWindow",
ImVec2(local_window_width_, local_window_height_),
ImGuiChildFlags_Border,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopStyleColor();
ImGui::SetWindowFontScale(1.0f);
@@ -27,6 +25,8 @@ int Render::LocalWindow() {
ImGui::Spacing();
{
ImGui::SetNextWindowPos(ImVec2(30, title_bar_height_ + 50),
ImGuiCond_Always);
ImGui::PushStyleColor(ImGuiCol_ChildBg,
ImVec4(239.0 / 255, 240.0 / 255, 242.0 / 255, 1.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);

View File

@@ -2,9 +2,9 @@
int Render::MainWindow() {
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
ImGui::SetNextWindowSize(
ImVec2(main_window_width_default_, main_window_height_default_),
ImGuiCond_Always);
// ImGui::SetNextWindowSize(
// ImVec2(main_window_width_default_, main_window_height_default_),
// ImGuiCond_Always);
LocalWindow();
RemoteWindow();

View File

@@ -17,15 +17,13 @@ static int InputTextCallback(ImGuiInputTextCallbackData *data) {
}
int Render::RemoteWindow() {
ImGui::SetNextWindowPos(ImVec2(local_window_width_ - 1, title_bar_height_),
ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_ + local_window_height_),
ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::BeginChild("RemoteDesktopWindow",
ImVec2(main_window_width_ - local_window_width_ + 1,
main_window_height_default_ - title_bar_height_ -
status_bar_height_),
ImVec2(remote_window_width_, remote_window_height_),
ImGuiChildFlags_Border,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
@@ -37,73 +35,79 @@ int Render::RemoteWindow() {
"%s", localization::remote_desktop[localization_language_index_].c_str());
ImGui::Spacing();
ImGui::PushStyleColor(ImGuiCol_ChildBg,
ImVec4(239.0 / 255, 240.0 / 255, 242.0 / 255, 1.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
ImGui::BeginChild("RemoteDesktopWindow_1", ImVec2(330, 180),
ImGuiChildFlags_Border,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopStyleVar();
ImGui::PopStyleColor();
{
ImGui::SetWindowFontScale(0.5f);
ImGui::Text("%s",
localization::remote_id[localization_language_index_].c_str());
ImGui::Spacing();
ImGui::SetNextItemWidth(IPUT_WINDOW_WIDTH);
ImGui::SetWindowFontScale(1.0f);
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
bool enter_pressed = ImGui::InputText(
"##remote_id_", remote_id_display_, IM_ARRAYSIZE(remote_id_display_),
ImGuiInputTextFlags_CharsUppercase |
ImGuiInputTextFlags_EnterReturnsTrue |
ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_CharsNoBlank,
InputTextCallback);
ImGui::SetNextWindowPos(
ImVec2(30, title_bar_height_ + local_window_height_ + 50),
ImGuiCond_Always);
ImGui::PushStyleColor(ImGuiCol_ChildBg,
ImVec4(239.0 / 255, 240.0 / 255, 242.0 / 255, 1.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
ImGui::BeginChild(
"RemoteDesktopWindow_1", ImVec2(330, 180), ImGuiChildFlags_Border,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopStyleVar();
ImGui::SameLine();
if (ImGui::Button(ICON_FA_ARROW_RIGHT_LONG, ImVec2(55, 38)) ||
enter_pressed || rejoin_) {
connect_button_pressed_ = true;
connection_status_ = ConnectionStatus::Connecting;
int ret = -1;
if (signal_connected_) {
if (!connection_established_) {
remote_id_ = remote_id_display_;
remote_id_.erase(remove_if(remote_id_.begin(), remote_id_.end(),
static_cast<int (*)(int)>(&isspace)),
remote_id_.end());
if (0 == strcmp(remote_id_.c_str(), client_id_) && !peer_reserved_) {
peer_reserved_ = CreatePeer(&params_);
if (peer_reserved_) {
LOG_INFO("Create peer[reserved] instance successful");
std::string client_id = "C-";
client_id += client_id_;
Init(peer_reserved_, client_id.c_str());
LOG_INFO("Peer[reserved] init finish");
} else {
LOG_INFO("Create peer[reserved] instance failed");
ImGui::PopStyleColor();
{
ImGui::SetWindowFontScale(0.5f);
ImGui::Text(
"%s", localization::remote_id[localization_language_index_].c_str());
ImGui::Spacing();
ImGui::SetNextItemWidth(IPUT_WINDOW_WIDTH);
ImGui::SetWindowFontScale(1.0f);
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
bool enter_pressed = ImGui::InputText(
"##remote_id_", remote_id_display_, IM_ARRAYSIZE(remote_id_display_),
ImGuiInputTextFlags_CharsUppercase |
ImGuiInputTextFlags_EnterReturnsTrue |
ImGuiInputTextFlags_CallbackEdit |
ImGuiInputTextFlags_CharsNoBlank,
InputTextCallback);
ImGui::PopStyleVar();
ImGui::SameLine();
if (ImGui::Button(ICON_FA_ARROW_RIGHT_LONG, ImVec2(55, 38)) ||
enter_pressed || rejoin_) {
connect_button_pressed_ = true;
connection_status_ = ConnectionStatus::Connecting;
int ret = -1;
if (signal_connected_) {
if (!connection_established_) {
remote_id_ = remote_id_display_;
remote_id_.erase(remove_if(remote_id_.begin(), remote_id_.end(),
static_cast<int (*)(int)>(&isspace)),
remote_id_.end());
if (0 == strcmp(remote_id_.c_str(), client_id_) &&
!peer_reserved_) {
peer_reserved_ = CreatePeer(&params_);
if (peer_reserved_) {
LOG_INFO("Create peer[reserved] instance successful");
std::string client_id = "C-";
client_id += client_id_;
Init(peer_reserved_, client_id.c_str());
LOG_INFO("Peer[reserved] init finish");
} else {
LOG_INFO("Create peer[reserved] instance failed");
}
}
ret = JoinConnection(peer_reserved_ ? peer_reserved_ : peer_,
remote_id_.c_str(), remote_password_);
if (0 == ret) {
is_client_mode_ = true;
rejoin_ = false;
} else {
rejoin_ = true;
}
}
ret = JoinConnection(peer_reserved_ ? peer_reserved_ : peer_,
remote_id_.c_str(), remote_password_);
if (0 == ret) {
is_client_mode_ = true;
rejoin_ = false;
} else {
rejoin_ = true;
}
}
}
}
ImGui::EndChild();
}
ImGui::EndChild();
ImGui::EndChild();
ImGui::PopStyleVar();
return 0;

View File

@@ -155,9 +155,9 @@ class Render {
int screen_width_ = 1280;
int screen_height_ = 720;
int main_window_width_default_ = 960;
int main_window_height_default_ = 570;
int main_window_height_default_ = 590;
int main_window_width_ = 960;
int main_window_height_ = 570;
int main_window_height_ = 590;
int main_window_width_last_ = 960;
int main_window_height_last_ = 540;
int stream_window_width_default_ = 1280;
@@ -167,12 +167,15 @@ class Render {
int stream_window_width_last_ = 1280;
int stream_window_height_last_ = 720;
int main_window_width_before_maximized_ = 960;
int main_window_height_before_maximized_ = 570;
int main_window_height_before_maximized_ = 590;
int control_window_min_width_ = 20;
int control_window_max_width_ = 170;
int control_window_width_ = 170;
int control_window_height_ = 40;
int local_window_width_ = 350;
int local_window_width_ = 720;
int local_window_height_ = 270;
int remote_window_width_ = 720;
int remote_window_height_ = 270;
int status_bar_height_ = 20;
int connection_status_window_width_ = 200;
int connection_status_window_height_ = 150;

View File

@@ -12,7 +12,7 @@ int Render::TitleBar(bool main_window) {
"TitleBar",
ImVec2(main_window ? main_window_width_ : stream_window_width_,
title_bar_height_),
ImGuiChildFlags_None,
ImGuiChildFlags_Border,
ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_NoBringToFrontOnFocus);
ImDrawList* draw_list = ImGui::GetWindowDrawList();