Skip to content

Commit

Permalink
GUI adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Noy-Zini committed Nov 3, 2024
1 parent 4b5f3a8 commit 390aa76
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 50 deletions.
27 changes: 9 additions & 18 deletions common/device-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}
}
}
Expand Down Expand Up @@ -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");;
}
}

Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -2776,7 +2767,7 @@ namespace rs2
}
if (ImGui::IsItemHovered())
{
ImGui::SetTooltip("Enable post-processing filters");
ImGui::SizedToolTip("Enable post-processing filters");
window.link_hovered();
}
}
Expand All @@ -2803,7 +2794,7 @@ namespace rs2
}
if (ImGui::IsItemHovered())
{
ImGui::SetTooltip("Disable post-processing filters");
ImGui::SizedToolTip("Disable post-processing filters");
window.link_hovered();
}
}
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -2947,7 +2938,7 @@ namespace rs2
ImGui::PopStyleVar();
ImGui::PopStyleColor(3);

ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10);
ImGui::SetCursorPosY(ImGui::GetCursorPosY());
}

for (auto&& sub : subdevices)
Expand Down
14 changes: 8 additions & 6 deletions common/option-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,16 @@ 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 );
ImGui::PushStyleColor( ImGuiCol_TextSelectedBg, { 1, 1, 1, 1 } );

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;
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -582,7 +584,7 @@ bool option_model::draw_slider( notifications_model & model,
{
error_message = error_to_string( e );
}

ImGui::PopStyleColor(2);
return slider_clicked;
}

Expand Down
26 changes: 13 additions & 13 deletions common/realsense-ui-advanced-mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
13 changes: 7 additions & 6 deletions common/ux-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,14 @@ 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)
{
rs2::gl::shutdown_rendering();
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);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -592,7 +593,7 @@ namespace rs2
while (res && (!_app_ready || _splash_timer.get_elapsed_ms() < 2000.f))
{
res = !glfwWindowShouldClose(_win);
// glfwPollEvents();
glfwPollEvents();

begin_frame();

Expand Down
25 changes: 18 additions & 7 deletions third-party/imgui/realsense_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions third-party/imgui/realsense_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 390aa76

Please sign in to comment.