From 390aa76628299ea0d614aec680910c80c62a161e Mon Sep 17 00:00:00 2001 From: Noy-Zini Date: Sun, 3 Nov 2024 09:23:30 +0200 Subject: [PATCH] GUI adjustments --- common/device-model.cpp | 27 +++++++++------------------ common/option-model.cpp | 14 ++++++++------ common/realsense-ui-advanced-mode.h | 26 +++++++++++++------------- common/ux-window.cpp | 13 +++++++------ third-party/imgui/realsense_imgui.cpp | 25 ++++++++++++++++++------- third-party/imgui/realsense_imgui.h | 1 + 6 files changed, 56 insertions(+), 50 deletions(-) diff --git a/common/device-model.cpp b/common/device-model.cpp index 8811e2aa90f..6136689dec0 100644 --- a/common/device-model.cpp +++ b/common/device-model.cpp @@ -2461,7 +2461,7 @@ namespace rs2 { bool stop_recording = false; - ImGui::SetCursorPos({ windows_width - 60, pos.y + 3 }); + ImGui::SetCursorPos({ windows_width - 60, pos.y + 7 }); ImGui_ScopePushFont(window.get_font()); ImGui_ScopePushStyleColor(ImGuiCol_Button, sensor_bg); @@ -2548,13 +2548,8 @@ namespace rs2 } if (ImGui::IsItemHovered()) { - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(5, 5)); - ImGui::SetNextWindowSize(ImVec2(255, 30)); window.link_hovered(); - ImGui::BeginTooltipEx(ImGuiTooltipFlags_None,ImGuiWindowFlags_NoScrollbar); - ImGui::TextUnformatted("Start streaming data from this sensor"); - ImGui::EndTooltip(); - ImGui::PopStyleVar(); + ImGui::SizedToolTip("Start streaming data from this sensor"); } } } @@ -2588,13 +2583,8 @@ namespace rs2 } if (ImGui::IsItemHovered()) { - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(5, 5)); - ImGui::SetNextWindowSize(ImVec2(310, 30)); window.link_hovered(); - ImGui::BeginTooltipEx(ImGuiTooltipFlags_None, ImGuiWindowFlags_NoScrollbar); - ImGui::TextUnformatted("Stop streaming data from selected sub-device"); - ImGui::EndTooltip(); - ImGui::PopStyleVar(); + ImGui::SizedToolTip("Stop streaming data from selected sub-device");; } } @@ -2628,6 +2618,7 @@ namespace rs2 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { 10, 10 }); ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, { 0, 0 }); ImGuiTreeNodeFlags flags{}; + ImGui::AlignTextToFramePadding(); if (show_depth_only) flags = ImGuiTreeNodeFlags_DefaultOpen; if (ImGui::TreeNodeEx(label.c_str(), flags)) { @@ -2776,7 +2767,7 @@ namespace rs2 } if (ImGui::IsItemHovered()) { - ImGui::SetTooltip("Enable post-processing filters"); + ImGui::SizedToolTip("Enable post-processing filters"); window.link_hovered(); } } @@ -2803,7 +2794,7 @@ namespace rs2 } if (ImGui::IsItemHovered()) { - ImGui::SetTooltip("Disable post-processing filters"); + ImGui::SizedToolTip("Disable post-processing filters"); window.link_hovered(); } } @@ -2886,7 +2877,7 @@ namespace rs2 if (ImGui::IsItemHovered()) { label = rsutils::string::from() << "Enable " << pb->get_name() << " post-processing filter"; - ImGui::SetTooltip("%s", label.c_str()); + ImGui::SizedToolTip(label.c_str()); window.link_hovered(); } } @@ -2908,7 +2899,7 @@ namespace rs2 { label = rsutils::string::from() << "Disable " << pb->get_name() << " post-processing filter"; - ImGui::SetTooltip("%s", label.c_str()); + ImGui::SizedToolTip(label.c_str()); window.link_hovered(); } } @@ -2947,7 +2938,7 @@ namespace rs2 ImGui::PopStyleVar(); ImGui::PopStyleColor(3); - ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10); + ImGui::SetCursorPosY(ImGui::GetCursorPosY()); } for (auto&& sub : subdevices) diff --git a/common/option-model.cpp b/common/option-model.cpp index 64c5b075d40..52bf7a2e3a8 100644 --- a/common/option-model.cpp +++ b/common/option-model.cpp @@ -257,7 +257,8 @@ bool option_model::draw_combobox( notifications_model & model, if( new_line ) ImGui::SetCursorPosX( combo_position_x ); - ImGui::PushItemWidth( new_line ? -1.f : 100.f ); + float combo_width = 315 - combo_position_x; + ImGui::PushItemWidth( new_line ? combo_width : 100.f ); int selected; std::vector< const char * > labels = get_combo_labels( &selected ); @@ -265,7 +266,7 @@ bool option_model::draw_combobox( notifications_model & model, try { - ImGui::PushItemWidth(184); // Set the width for the combo box itself + ImGui::PushItemWidth(combo_width); // Set the width for the combo box itself if( ImGui::CustomComboBox( id.c_str(), &selected, labels.data(), static_cast< int >( labels.size() ) ) ) { float tmp_value = range.min + range.step * selected; @@ -394,8 +395,9 @@ bool option_model::draw_slider( notifications_model & model, } } - ImGui::PushItemWidth( -1 ); - + ImGui::PushItemWidth(245); + ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, black); + ImGui::PushStyleColor(ImGuiCol_FrameBgActive, black); try { if( read_only ) @@ -503,7 +505,7 @@ bool option_model::draw_slider( notifications_model & model, static_cast< int >( range.min ), static_cast< int >( range.max ), static_cast< int >( range.step ), - "%.0f" ) ) // integers don't have any precision + "%.3f" ) ) // integers don't have any precision { // TODO: Round to step? slider_clicked = slider_selected( opt, @@ -582,7 +584,7 @@ bool option_model::draw_slider( notifications_model & model, { error_message = error_to_string( e ); } - + ImGui::PopStyleColor(2); return slider_clicked; } diff --git a/common/realsense-ui-advanced-mode.h b/common/realsense-ui-advanced-mode.h index 1ede7cda450..b5e4c5b44fb 100644 --- a/common/realsense-ui-advanced-mode.h +++ b/common/realsense-ui-advanced-mode.h @@ -232,7 +232,7 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced, if (ImGui::TreeNode("Depth Control")) { - ImGui::PushItemWidth(-1); + ImGui::PushItemWidth(ImGui::CalcItemWidth()); auto to_set = false; @@ -268,7 +268,7 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced, if (ImGui::TreeNode("Rsm")) { - ImGui::PushItemWidth(-1); + ImGui::PushItemWidth(ImGui::CalcItemWidth()); auto to_set = false; @@ -299,7 +299,7 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced, if (ImGui::TreeNode("Rau Support Vector Control")) { - ImGui::PushItemWidth(-1); + ImGui::PushItemWidth(ImGui::CalcItemWidth()); auto to_set = false; @@ -333,7 +333,7 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced, if (ImGui::TreeNode("Color Control")) { - ImGui::PushItemWidth(-1); + ImGui::PushItemWidth(ImGui::CalcItemWidth()); auto to_set = false; @@ -364,7 +364,7 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced, if (ImGui::TreeNode("Rau Color Thresholds Control")) { - ImGui::PushItemWidth(-1); + ImGui::PushItemWidth(ImGui::CalcItemWidth()); auto to_set = false; @@ -393,7 +393,7 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced, if (ImGui::TreeNode("SLO Color Thresholds Control")) { - ImGui::PushItemWidth(-1); + ImGui::PushItemWidth(ImGui::CalcItemWidth()); auto to_set = false; @@ -422,7 +422,7 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced, if (ImGui::TreeNode("SLO Penalty Control")) { - ImGui::PushItemWidth(-1); + ImGui::PushItemWidth(ImGui::CalcItemWidth()); auto to_set = false; @@ -454,7 +454,7 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced, if (ImGui::TreeNode("HDAD")) { - ImGui::PushItemWidth(-1); + ImGui::PushItemWidth(ImGui::CalcItemWidth()); auto to_set = false; @@ -485,7 +485,7 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced, if (ImGui::TreeNode("Color Correction")) { - ImGui::PushItemWidth(-1); + ImGui::PushItemWidth(ImGui::CalcItemWidth()); auto to_set = false; @@ -523,7 +523,7 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced, if (ImGui::TreeNode("Depth Table")) { - ImGui::PushItemWidth(-1); + ImGui::PushItemWidth(ImGui::CalcItemWidth()); auto to_set = false; @@ -554,7 +554,7 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced, if (ImGui::TreeNode("AE Control")) { - ImGui::PushItemWidth(-1); + ImGui::PushItemWidth(ImGui::CalcItemWidth()); auto to_set = false; @@ -581,7 +581,7 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced, if (ImGui::TreeNode("Census Enable Reg")) { - ImGui::PushItemWidth(-1); + ImGui::PushItemWidth(ImGui::CalcItemWidth()); auto to_set = false; @@ -609,7 +609,7 @@ inline void draw_advanced_mode_controls(rs400::advanced_mode& advanced, if (ImGui::TreeNode("Disparity Modulation")) { - ImGui::PushItemWidth(-1); + ImGui::PushItemWidth(ImGui::CalcItemWidth()); auto to_set = false; diff --git a/common/ux-window.cpp b/common/ux-window.cpp index 371e472bfbf..9de8956f57f 100644 --- a/common/ux-window.cpp +++ b/common/ux-window.cpp @@ -216,11 +216,6 @@ namespace rs2 void ux_window::open_window() { - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); - io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls - io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange; // added in order to prevents cursor chang when interacting with other element (when nedded remove the flag accordingly) if (_win) { @@ -228,6 +223,7 @@ namespace rs2 if (_use_glsl_proc) rs2::gl::shutdown_processing(); ImGui::GetIO().Fonts->ClearFonts(); // To be refactored into Viewer theme object + ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); glfwDestroyWindow(_win); @@ -379,6 +375,11 @@ namespace rs2 setup_icon(); + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange; // added in order to prevents cursor chang when interacting with other element (when nedded remove the flag accordingly) ImGui_ImplGlfw_InitForOpenGL(_win, false); ImGui_ImplOpenGL3_Init(); @@ -592,7 +593,7 @@ namespace rs2 while (res && (!_app_ready || _splash_timer.get_elapsed_ms() < 2000.f)) { res = !glfwWindowShouldClose(_win); - // glfwPollEvents(); + glfwPollEvents(); begin_frame(); diff --git a/third-party/imgui/realsense_imgui.cpp b/third-party/imgui/realsense_imgui.cpp index ccc77603bd6..02bbe66a7d0 100644 --- a/third-party/imgui/realsense_imgui.cpp +++ b/third-party/imgui/realsense_imgui.cpp @@ -65,17 +65,18 @@ bool ImGui::SliderIntWithSteps(const char* label, int* v, int v_min, int v_max, if (!display_format) display_format = "%d"; - int tmp_val = *v; - bool value_changed = ImGui::SliderInt(label, &tmp_val, v_min, v_max, display_format); + if (!display_format) + display_format = "%.0f"; + + float v_f = (float)*v; + bool value_changed = SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f); - // Round the actual slider value to the cloasest bound interval - if (v_step > 1) - tmp_val -= (tmp_val - v_min) % v_step; - *v = tmp_val; + *v = (int)v_f; return value_changed; } + // Parse display precision back from the display format string int ImGui::ParseFormatPrecision(const char* fmt, int default_precision) { @@ -163,7 +164,6 @@ IMGUI_API bool ImGui::CustomComboBox(const char* label, int* current_item, const // the preview value - selected item const char* preview_value = (*current_item >= 0 && *current_item < items_count) ? items[*current_item] : "Select an item"; - if (ImGui::BeginCombo(label, "")) { //insert combobox items @@ -197,3 +197,14 @@ IMGUI_API bool ImGui::CustomComboBox(const char* label, int* current_item, const ImGui::PopItemWidth(); return value_changed; } + +IMGUI_API void ImGui::SizedToolTip(const char* text) +{ + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(5, 5)); + const ImVec2 text_size = ImGui::CalcTextSize(text); + ImGui::SetNextWindowSize(ImVec2(text_size.x + 10 , text_size.y + 10)); + ImGui::BeginTooltipEx(ImGuiTooltipFlags_None, ImGuiWindowFlags_NoScrollbar); + ImGui::TextUnformatted(text); + ImGui::EndTooltip(); + ImGui::PopStyleVar(1); +} diff --git a/third-party/imgui/realsense_imgui.h b/third-party/imgui/realsense_imgui.h index 54b036992ed..688a201b7ef 100644 --- a/third-party/imgui/realsense_imgui.h +++ b/third-party/imgui/realsense_imgui.h @@ -37,6 +37,7 @@ namespace ImGui //IMGUI_API bool SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags, bool render_bg); IMGUI_API float RoundScalar(float value, int decimal_precision); IMGUI_API bool CustomComboBox(const char* label, int* current_item, const char* const items[], int items_count); + IMGUI_API void SizedToolTip(const char* text); } #define CONCAT_(x,y) x##y #define CONCAT(x,y) CONCAT_(x,y)