Make control bar scrollable

This commit is contained in:
dijunkun
2024-07-05 16:05:50 +08:00
parent 872152f1be
commit 9702805331
6 changed files with 82 additions and 45 deletions

View File

@@ -5,8 +5,9 @@
#include "render.h"
int Render::ControlBar() {
ImGui::SetWindowFontScale(0.5f);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
if (control_bar_button_pressed_) {
// Mouse control
std::string mouse = ICON_FA_COMPUTER_MOUSE;
if (ImGui::Button(mouse.c_str(), ImVec2(25, 25))) {
@@ -44,5 +45,19 @@ int Render::ControlBar() {
}
}
ImGui::SameLine();
ImGui::Dummy(ImVec2(main_window_width_ * 0.91f, 0));
ImGui::SameLine();
}
std::string control_bar =
control_bar_button_pressed_ ? ICON_FA_ANGLE_LEFT : ICON_FA_ANGLE_RIGHT;
if (ImGui::Button(control_bar.c_str(), ImVec2(25, 25))) {
control_bar_button_pressed_ = !control_bar_button_pressed_;
control_bar_button_pressed_time_ = ImGui::GetTime();
}
ImGui::PopStyleVar();
return 0;
}

View File

@@ -1,16 +1,31 @@
#include "render.h"
int Render::ControlWindow() {
ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0));
static bool a, b, c, d, e;
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
ImGui::SetWindowFontScale(0.5f);
auto time_duration = ImGui::GetTime() - control_bar_button_pressed_time_;
auto control_window_width =
!control_bar_button_pressed_
? time_duration < 0.25f
? main_window_width_ -
(main_window_width_ - control_window_min_width_) * 4 *
time_duration
: control_window_min_width_
: time_duration < 0.25f
? control_window_min_width_ +
(main_window_width_ - control_window_min_width_) * 4 *
time_duration
: main_window_width_;
ImGui::BeginChild("ControlWindow",
ImVec2(main_window_width_, menu_window_height_),
ImGuiChildFlags_Border, ImGuiWindowFlags_NoScrollbar);
ImVec2(control_window_width, control_window_height_),
ImGuiChildFlags_Border, ImGuiWindowFlags_NoDecoration);
ImGui::SetWindowFontScale(1.0f);
ControlBar();
ImGui::SetWindowFontScale(1.0f);
ImGui::PopStyleColor();
ImGui::EndChild();

View File

@@ -26,10 +26,10 @@ int Render::LocalWindow() {
{
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0, 0, 0, 0.05));
ImGui::BeginChild(
"LocalDesktopWindow_1", ImVec2(330, 180), ImGuiChildFlags_Border,
ImGui::BeginChild("LocalDesktopWindow_1", ImVec2(330, 180),
ImGuiChildFlags_Border,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus);
{
ImGui::SetWindowFontScale(0.5f);

View File

@@ -325,15 +325,18 @@ int Render::Run() {
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
ImGui::SetNextWindowSize(
ImVec2(main_window_width_,
streaming_ ? menu_window_height_ : main_window_height_),
streaming_ ? control_window_height_ : main_window_height_),
ImGuiCond_Always);
ImGui::Begin("Render", nullptr,
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar);
ImGui::PopStyleVar();
ImGui::PopStyleColor();
if (!streaming_) {
MainWindow();
} else {

View File

@@ -127,6 +127,8 @@ class Render {
int main_window_width_before_fullscreen_ = 1280;
int main_window_height_before_fullscreen_ = 720;
int menu_window_height_ = 30;
int control_window_min_width_ = 40;
int control_window_height_ = 40;
int local_window_width_ = 350;
int status_bar_height_ = 20;
int connection_status_window_width_ = 200;
@@ -156,6 +158,7 @@ class Render {
bool connection_established_ = false;
bool subwindow_hovered_ = false;
bool connect_button_pressed_ = false;
bool control_bar_button_pressed_ = false;
bool fullscreen_button_pressed_ = false;
bool mouse_control_button_pressed_ = false;
bool settings_button_pressed_ = false;
@@ -172,6 +175,7 @@ class Render {
double copy_start_time_ = 0;
double regenerate_password_start_time_ = 0;
double control_bar_button_pressed_time_ = 0;
int fps_ = 0;
uint32_t start_time_;

View File

@@ -11,7 +11,7 @@ int Render::SettingButton() {
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0, 0, 0, 0));
std::string gear = ICON_FA_GEAR;
if (ImGui::Button(gear.c_str(), ImVec2(40, 35))) {
if (ImGui::Button(gear.c_str(), ImVec2(40, 30))) {
settings_button_pressed_ = !settings_button_pressed_;
settings_window_pos_reset_ = true;
}