[feat] make control bar can only move along left border of the main window

This commit is contained in:
dijunkun
2024-08-02 17:31:01 +08:00
parent 0dc0b87bc4
commit ceb3d9fe20
3 changed files with 28 additions and 7 deletions

View File

@@ -5,9 +5,12 @@
#include "render.h" #include "render.h"
int Render::ControlBar() { int Render::ControlBar() {
ImVec2 bar_pos = ImGui::GetWindowPos();
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
if (control_bar_button_pressed_) { if (control_bar_button_pressed_) {
ImGui::SetCursorPosX(control_winodw_pos_.x + 22);
// Mouse control // Mouse control
std::string mouse = ICON_FA_COMPUTER_MOUSE; std::string mouse = ICON_FA_COMPUTER_MOUSE;
if (ImGui::Button(mouse.c_str(), ImVec2(25, 25))) { if (ImGui::Button(mouse.c_str(), ImVec2(25, 25))) {
@@ -40,12 +43,17 @@ int Render::ControlBar() {
} }
ImGui::SameLine(); ImGui::SameLine();
ImGui::SetCursorPosX(control_window_max_width_ - 35); ImGui::SetCursorPosX(control_winodw_pos_.x + control_window_max_width_ -
35);
} }
ImGui::SetCursorPosX(control_winodw_pos_.x +
(control_bar_button_pressed_
? (control_window_max_width_ - 18)
: (control_window_min_width_)));
std::string control_bar = std::string control_bar =
control_bar_button_pressed_ ? ICON_FA_ANGLE_LEFT : ICON_FA_ANGLE_RIGHT; control_bar_button_pressed_ ? ICON_FA_ANGLE_LEFT : ICON_FA_ANGLE_RIGHT;
if (ImGui::Button(control_bar.c_str(), ImVec2(25, 25))) { if (ImGui::Button(control_bar.c_str(), ImVec2(15, 25))) {
control_bar_button_pressed_ = !control_bar_button_pressed_; control_bar_button_pressed_ = !control_bar_button_pressed_;
control_bar_button_pressed_time_ = ImGui::GetTime(); control_bar_button_pressed_time_ = ImGui::GetTime();
} }

View File

@@ -15,9 +15,13 @@ int Render::ControlWindow() {
time_duration time_duration
: control_window_max_width_; : control_window_max_width_;
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0)); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1, 1, 1, 1));
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_), ImGuiCond_Once); ImGui::SetNextWindowPos(
ImVec2(-control_window_min_width_ / 2, title_bar_height_),
ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(control_window_width, control_window_height_), ImGui::SetNextWindowSize(ImVec2(control_window_width, control_window_height_),
ImGuiCond_Always); ImGuiCond_Always);
ImGui::Begin("ControlWindow", nullptr, ImGui::Begin("ControlWindow", nullptr,
@@ -26,6 +30,13 @@ int Render::ControlWindow() {
ImGuiWindowFlags_NoBringToFrontOnFocus); ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopStyleVar(); ImGui::PopStyleVar();
control_winodw_pos_ = ImGui::GetWindowPos();
if (control_winodw_pos_.x != -control_window_min_width_ / 2) {
ImGui::SetWindowPos(
ImVec2(-control_window_min_width_ / 2, control_winodw_pos_.y),
ImGuiCond_Always);
}
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
static bool a, b, c, d, e; static bool a, b, c, d, e;
ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_), ImGuiCond_Once); ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_), ImGuiCond_Once);
@@ -40,8 +51,8 @@ int Render::ControlWindow() {
ControlBar(); ControlBar();
ImGui::EndChild(); ImGui::EndChild();
ImGui::End(); ImGui::End();
ImGui::PopStyleVar();
ImGui::PopStyleColor(); ImGui::PopStyleColor();
return 0; return 0;

View File

@@ -123,7 +123,6 @@ class Render {
std::string local_id_ = ""; std::string local_id_ = "";
char remote_id_[20] = ""; char remote_id_[20] = "";
char client_password_[20] = ""; char client_password_[20] = "";
bool is_client_mode_ = false;
private: private:
int title_bar_width_ = 960; int title_bar_width_ = 960;
@@ -192,15 +191,18 @@ class Render {
bool show_password_ = true; bool show_password_ = true;
bool password_inited_ = false; bool password_inited_ = false;
bool regenerate_password_ = false; bool regenerate_password_ = false;
bool streaming_ = false;
bool show_about_window_ = false; bool show_about_window_ = false;
bool show_connection_status_window_ = false; bool show_connection_status_window_ = false;
bool window_maximized_ = false; bool window_maximized_ = false;
bool streaming_ = true;
bool is_client_mode_ = true;
double copy_start_time_ = 0; double copy_start_time_ = 0;
double regenerate_password_start_time_ = 0; double regenerate_password_start_time_ = 0;
double control_bar_button_pressed_time_ = 0; double control_bar_button_pressed_time_ = 0;
ImVec2 control_winodw_pos_;
int fps_ = 0; int fps_ = 0;
uint32_t start_time_; uint32_t start_time_;
uint32_t end_time_; uint32_t end_time_;