Skip to content

Commit

Permalink
fixed callbacks and tools and examples UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Noy-Zini committed Nov 9, 2024
1 parent 390aa76 commit c57927f
Show file tree
Hide file tree
Showing 18 changed files with 431 additions and 56 deletions.
62 changes: 43 additions & 19 deletions common/device-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,8 +922,8 @@ namespace rs2
}
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_PopupBg, black);
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
ImGui::SetTooltip("%s", show_device_info ? "Hide Device Details" : "Show Device Details");
window.link_hovered();
ImGui::PopStyleColor(2);
Expand Down Expand Up @@ -1261,8 +1261,8 @@ namespace rs2
}
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_PopupBg, black);
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
std::string record_button_hover_text = get_record_button_hover_text(is_streaming);
ImGui::SetTooltip("%s", record_button_hover_text.c_str());
if (is_streaming) window.link_hovered();
Expand All @@ -1281,16 +1281,15 @@ namespace rs2
auto sync_button_color = is_sync_enabled ? light_blue : light_grey;
ImGui::PushStyleColor(ImGuiCol_Text, sync_button_color);
ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, sync_button_color);
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.5f, 0.5f, 0.5f, 1.f));
if (ImGui::ButtonEx(sync_button_name.c_str(), device_panel_icons_size, ImGuiItemFlags_Disabled))
{
is_sync_enabled = !is_sync_enabled;
}
ImGui::PopStyleColor(3);
ImGui::PopStyleColor(2);
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_PopupBg, black);
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
ImGui::SetTooltip("%s", is_sync_enabled ? "Disable streams synchronization" : "Enable streams synchronization");
ImGui::PopStyleColor(2);
}
Expand All @@ -1312,8 +1311,8 @@ namespace rs2
}
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_PopupBg, black);
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
ImGui::SetTooltip("%s", "Click for more");
window.link_hovered();
ImGui::PopStyleColor(2);
Expand Down Expand Up @@ -1372,8 +1371,8 @@ namespace rs2
}
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_PopupBg, black);
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
std::string tooltip = rsutils::string::from()
<< "Install official signed firmware from file to the device"
<< ( is_streaming ? " (Disabled while streaming)" : "" );
Expand Down Expand Up @@ -1401,8 +1400,8 @@ namespace rs2

if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_PopupBg, black);
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
std::string tooltip = rsutils::string::from() << "Check for SW / FW updates";
ImGui::SetTooltip("%s", tooltip.c_str());
ImGui::PopStyleColor(2);
Expand All @@ -1426,8 +1425,8 @@ namespace rs2
}
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_PopupBg, black);
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
std::string tooltip = rsutils::string::from()
<< "Install non official unsigned firmware from file to the device"
<< ( is_streaming ? " (Disabled while streaming)" : "" );
Expand Down Expand Up @@ -2318,7 +2317,7 @@ namespace rs2

if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_PopupBg, black);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::SetTooltip("Remove selected device from current view\n(can be restored by clicking Add Source)");
window.link_hovered();
Expand Down Expand Up @@ -2439,7 +2438,7 @@ namespace rs2
ImGui::PopStyleColor(2);

auto sensor_top_y = ImGui::GetCursorPosY();
ImGui::SetNextWindowContentSize(ImVec2(ImGui::GetWindowWidth() - 36, ImGui::GetWindowHeight()));
ImGui::SetWindowSize(ImVec2(windows_width -36, 0.0f));

ImGui::PushStyleColor(ImGuiCol_HeaderHovered, sensor_bg);
ImGui::PushStyleColor(ImGuiCol_Text, light_grey);
Expand Down Expand Up @@ -2467,7 +2466,7 @@ namespace rs2
ImGui_ScopePushStyleColor(ImGuiCol_Button, sensor_bg);
ImGui_ScopePushStyleColor(ImGuiCol_ButtonHovered, sensor_bg);
ImGui_ScopePushStyleColor(ImGuiCol_ButtonActive, sensor_bg);

ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(5, 5));
int font_size = window.get_font_size();
ImVec2 button_size = { font_size * 3.0f, font_size * 1.0f };

Expand Down Expand Up @@ -2498,15 +2497,21 @@ namespace rs2
{
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
// ImGui::SetTooltip("Selected configuration (FPS, Resolution) is not supported");
ImGui::SetTooltip("Selected value is not supported");
ImGui::PopStyleColor(2);
}
}
else
{
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
ImGui::SetTooltip("No stream selected");
ImGui::PopStyleColor(2);
}
}
}
Expand Down Expand Up @@ -2548,8 +2553,11 @@ namespace rs2
}
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
window.link_hovered();
ImGui::SizedToolTip("Start streaming data from this sensor");
ImGui::SetTooltip("Start streaming data from this sensor");
ImGui::PopStyleColor(2);
}
}
}
Expand Down Expand Up @@ -2583,8 +2591,11 @@ namespace rs2
}
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
window.link_hovered();
ImGui::SizedToolTip("Stop streaming data from selected sub-device");;
ImGui::SetTooltip("Stop streaming data from selected sub-device");
ImGui::PopStyleColor(2);
}
}

Expand All @@ -2604,6 +2615,7 @@ namespace rs2
}
}
}
ImGui::PopStyleVar();
});
}

Expand All @@ -2618,7 +2630,7 @@ namespace rs2
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { 10, 10 });
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, { 0, 0 });
ImGuiTreeNodeFlags flags{};
ImGui::AlignTextToFramePadding();
ImGui::AlignTextToFramePadding();//Ensures that text aligns visually with UI elements that have padding (for the TreeNode visual alignment)
if (show_depth_only) flags = ImGuiTreeNodeFlags_DefaultOpen;
if (ImGui::TreeNodeEx(label.c_str(), flags))
{
Expand Down Expand Up @@ -2767,8 +2779,11 @@ namespace rs2
}
if (ImGui::IsItemHovered())
{
ImGui::SizedToolTip("Enable post-processing filters");
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
ImGui::SetTooltip("Enable post-processing filters");
window.link_hovered();
ImGui::PopStyleColor(2);
}
}
else
Expand All @@ -2794,8 +2809,11 @@ namespace rs2
}
if (ImGui::IsItemHovered())
{
ImGui::SizedToolTip("Disable post-processing filters");
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
ImGui::SetTooltip("Disable post-processing filters");
window.link_hovered();
ImGui::PopStyleColor(2);
}
}
ImGui::PopStyleColor(5);
Expand Down Expand Up @@ -2876,9 +2894,12 @@ namespace rs2
}
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
label = rsutils::string::from() << "Enable " << pb->get_name() << " post-processing filter";
ImGui::SizedToolTip(label.c_str());
ImGui::SetTooltip(label.c_str());
window.link_hovered();
ImGui::PopStyleColor(2);
}
}
else
Expand All @@ -2897,10 +2918,13 @@ namespace rs2
}
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
label = rsutils::string::from()
<< "Disable " << pb->get_name() << " post-processing filter";
ImGui::SizedToolTip(label.c_str());
ImGui::SetTooltip(label.c_str());
window.link_hovered();
ImGui::PopStyleColor(2);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions common/option-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ bool option_model::draw_combobox( notifications_model & model,

try
{
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 All @@ -277,7 +276,6 @@ bool option_model::draw_combobox( notifications_model & model,
*invalidate_flag = true;
item_clicked = true;
}
ImGui::PopItemWidth();
}
catch( const error & e )
{
Expand Down
2 changes: 1 addition & 1 deletion common/stream-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ namespace rs2
bool draw_combo_box(const std::string& id, const std::vector<std::string>& device_names, int& new_index)
{
std::vector<const char*> device_names_chars = get_string_pointers(device_names);
return ImGui::Combo(id.c_str(), &new_index, device_names_chars.data(), static_cast<int>(device_names.size()));
return ImGui::CustomComboBox(id.c_str(), &new_index, device_names_chars.data(), static_cast<int>(device_names.size()));
}

void stream_model::show_stream_header(ImFont* font, const rect &stream_rect, viewer_model& viewer)
Expand Down
12 changes: 10 additions & 2 deletions common/updates-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void updates_model::draw(std::shared_ptr<notifications_model> not_model, ux_wind
ImGui::SetNextWindowSize({ positions.w, positions.h });

auto flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings ;
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoScrollbar;

ImGui::PushStyleColor(ImGuiCol_PopupBg, sensor_bg);
ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, white);
Expand Down Expand Up @@ -144,6 +144,8 @@ void updates_model::draw(std::shared_ptr<notifications_model> not_model, ux_wind
ImGui::SetCursorPos({ positions.w - 145, positions.h - 25 });

auto enabled = ignore || no_update_needed;
ImGui::PushStyleColor(ImGuiCol_Border, black);
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.5f);
if (enabled)
{
if (_fw_update_state != fw_update_states::started)
Expand Down Expand Up @@ -180,12 +182,16 @@ void updates_model::draw(std::shared_ptr<notifications_model> not_model, ux_wind
}
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
ImGui::SetTooltip("To close this window you must install all essential update\n"
"or agree to the warning of closing without it");

ImGui::PopStyleColor(2);
}
ImGui::PopStyleColor(2);
}
ImGui::PopStyleVar();
ImGui::PopStyleColor();
ImGui::EndPopup();
}
ImGui::PopStyleColor(3);
Expand Down Expand Up @@ -438,9 +444,11 @@ bool updates_model::draw_software_section(const char * window_name, update_profi

if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
std::string tooltip = "This will redirect you to download the selected software from:\n" + selected_software_update.download_link;
ImGui::SetTooltip("%s", tooltip.c_str());
window.link_hovered();
ImGui::PopStyleColor();
}

ImGui::PopStyleColor(3);
Expand Down
8 changes: 6 additions & 2 deletions common/ux-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ namespace rs2
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_ImplGlfw_InitForOpenGL(_win, true);
ImGui_ImplOpenGL3_Init();

if (_use_glsl_render)
Expand All @@ -395,19 +395,21 @@ namespace rs2

glfwSetCursorPosCallback(_win, [](GLFWwindow* w, double cx, double cy)
{
ImGui_ImplGlfw_CursorPosCallback(w, cx, cy); // Forward the cursor position to ImGui
auto data = reinterpret_cast<ux_window*>(glfwGetWindowUserPointer(w));
data->_mouse.cursor = { (float)cx / data->_scale_factor,
(float)cy / data->_scale_factor };
});
glfwSetMouseButtonCallback(_win, [](GLFWwindow* w, int button, int action, int mods)
{
ImGui_ImplGlfw_MouseButtonCallback(w, button, action, mods);
ImGui_ImplGlfw_MouseButtonCallback(w, button, action, mods);// Forward the event to ImGui's GLFW implementation
auto data = reinterpret_cast<ux_window*>(glfwGetWindowUserPointer(w));
data->_mouse.mouse_down[0] = (button == GLFW_MOUSE_BUTTON_1) && (action != GLFW_RELEASE);
data->_mouse.mouse_down[1] = (button == GLFW_MOUSE_BUTTON_2) && (action != GLFW_RELEASE);
});
glfwSetScrollCallback(_win, [](GLFWwindow * w, double xoffset, double yoffset)
{
ImGui_ImplGlfw_ScrollCallback(w, xoffset, yoffset); // Forwards scroll events to ImGui
auto data = reinterpret_cast<ux_window*>(glfwGetWindowUserPointer(w));
data->_mouse.mouse_wheel = static_cast<int>(yoffset);
data->_mouse.ui_wheel += static_cast<int>(yoffset);
Expand All @@ -425,6 +427,8 @@ namespace rs2
}
});

glfwSetKeyCallback(_win, ImGui_ImplGlfw_KeyCallback);

rs2::gl::init_rendering(_use_glsl_render);
if (_use_glsl_proc) rs2::gl::init_processing(_win, _use_glsl_proc);

Expand Down
Loading

0 comments on commit c57927f

Please sign in to comment.