diff --git a/common/device-model.cpp b/common/device-model.cpp index 6ffcba2fcf..0e814fc10f 100644 --- a/common/device-model.cpp +++ b/common/device-model.cpp @@ -562,7 +562,8 @@ namespace rs2 //////////////////// Step Backwards Button //////////////////// ImGui::SetCursorPosX(ImGui::GetCursorPosX() + space_width); std::string label = rsutils::string::from() << textual_icons::step_backward << "##Step Backward " << id; - if (ImGui::ButtonEx(label.c_str(), button_dim, supports_playback_step ? 0 : ImGuiItemFlags_Disabled)) + ImGui::BeginDisabled(!supports_playback_step); + if (ImGui::ButtonEx(label.c_str(), button_dim)) { int fps = 0; for (auto&& s : viewer.streams) @@ -577,6 +578,7 @@ namespace rs2 p.seek(std::chrono::nanoseconds(curr_frame - step)); } } + ImGui::EndDisabled(); if (ImGui::IsItemHovered()) { std::string tooltip = rsutils::string::from() << "Step Backwards" << (supports_playback_step ? "" : "(Not available)"); @@ -665,7 +667,8 @@ namespace rs2 //////////////////// Step Forward Button //////////////////// ImGui::SetCursorPosX(ImGui::GetCursorPosX() + space_width); label = rsutils::string::from() << textual_icons::step_forward << "##Step Forward " << id; - if (ImGui::ButtonEx(label.c_str(), button_dim, supports_playback_step ? 0 : ImGuiItemFlags_Disabled)) + ImGui::BeginDisabled(!supports_playback_step); + if (ImGui::ButtonEx(label.c_str(), button_dim)) { int fps = 0; for (auto&& s : viewer.streams) @@ -677,6 +680,7 @@ namespace rs2 uint64_t step = fps ? uint64_t(1000.0 / (float)fps * 1e6) : 1000000ULL; p.seek(std::chrono::nanoseconds(curr_frame + step)); } + ImGui::EndDisabled(); if (ImGui::IsItemHovered()) { std::string tooltip = rsutils::string::from() << "Step Forward" << (supports_playback_step ? "" : "(Not available)"); @@ -1225,11 +1229,11 @@ namespace rs2 auto record_button_color = is_recording ? light_blue : light_grey; ImGui::PushStyleColor(ImGuiCol_Text, record_button_color); ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, record_button_color); - bool button_disabled = disable_record_button_logic(is_streaming, is_playback_device); - if (button_disabled) - ImGui::PushStyleColor(ImGuiCol_Text,ImVec4(0.5f,0.5f,0.5f,1.f)); - if (ImGui::ButtonEx(record_button_name.c_str(), device_panel_icons_size, (disable_record_button_logic(is_streaming, is_playback_device)) ? ImGuiItemFlags_Disabled : 0)) + bool disable_button = disable_record_button_logic(is_streaming, is_playback_device); + ImGui::BeginDisabled(disable_button); // Disable the button if needed + + if (ImGui::ButtonEx(record_button_name.c_str(), device_panel_icons_size)) { if (is_recording) //is_recording is changed inside stop/start_recording { @@ -1259,6 +1263,7 @@ namespace rs2 if (path != "") start_recording(path, error_message); } } + ImGui::EndDisabled(); if (ImGui::IsItemHovered()) { ImGui::PushStyleColor(ImGuiCol_Text, white); @@ -1268,10 +1273,7 @@ namespace rs2 if (is_streaming) window.link_hovered(); ImGui::PopStyleColor(2); } - if(button_disabled) - ImGui::PopStyleColor(3); - else - ImGui::PopStyleColor(2); + ImGui::PopStyleColor(2); ImGui::SameLine(); //////////////////////////////////////// // Draw Sync icon @@ -1281,10 +1283,12 @@ 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); - if (ImGui::ButtonEx(sync_button_name.c_str(), device_panel_icons_size, ImGuiItemFlags_Disabled)) + ImGui::BeginDisabled(); + if (ImGui::ButtonEx(sync_button_name.c_str(), device_panel_icons_size)) { is_sync_enabled = !is_sync_enabled; } + ImGui::EndDisabled(); ImGui::PopStyleColor(2); if (ImGui::IsItemHovered()) { @@ -1472,11 +1476,15 @@ namespace rs2 ImGui::PushStyleColor(ImGuiCol_Text, record_button_color); ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, record_button_color); - ImGui::ButtonEx(is_recording ? "Stop" : "Record", device_panel_icons_size, (!is_streaming ? ImGuiItemFlags_Disabled : 0)); + ImGui::BeginDisabled(!is_streaming); + ImGui::ButtonEx(is_recording ? "Stop" : "Record", device_panel_icons_size); + ImGui::EndDisabled(); if (ImGui::IsItemHovered() && is_streaming) window.link_hovered(); ImGui::PopStyleColor(2); - ImGui::SameLine(); ImGui::ButtonEx("Sync", device_panel_icons_size, ImGuiItemFlags_Disabled); + ImGui::BeginDisabled(); + ImGui::SameLine(); ImGui::ButtonEx("Sync", device_panel_icons_size); + ImGui::EndDisabled(); auto info_button_color = show_device_info ? light_blue : light_grey; ImGui::PushStyleColor(ImGuiCol_Text, info_button_color); @@ -2068,7 +2076,7 @@ namespace rs2 const ImVec2 icons_size{ 20, 20 }; //TODO: Change this once we have support for loading jsons with more data than only advanced controls bool is_streaming = std::any_of(subdevices.begin(), subdevices.end(), [](const std::shared_ptr& sm) { return sm->streaming; }); - const int buttons_flags = serializable ? 0 : ImGuiItemFlags_Disabled; + const bool buttons_disable = !serializable; static bool require_advanced_mode_enable_prompt = false; auto advanced_dev = dev.as(); auto is_advanced_device = false; @@ -2092,8 +2100,10 @@ namespace rs2 std::string upload_button_name = rsutils::string::from() << textual_icons::upload << "##" << id; ImGui::PushStyleColor(ImGuiCol_Text, light_grey); ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, light_grey); - - if (ImGui::ButtonEx(upload_button_name.c_str(), icons_size, (is_streaming && !load_json_if_streaming) ? ImGuiItemFlags_Disabled : buttons_flags)) + + bool load_button_disabled = (is_streaming && !load_json_if_streaming) || buttons_disable; + ImGui::BeginDisabled(load_button_disabled); + if (ImGui::ButtonEx(upload_button_name.c_str(), icons_size)) { if (serializable && (!is_advanced_device || is_advanced_mode_enabled)) { @@ -2118,7 +2128,7 @@ namespace rs2 require_advanced_mode_enable_prompt = true; } } - + ImGui::EndDisabled(); if (ImGui::IsItemHovered()) { ImGui::PushStyleColor(ImGuiCol_PopupBg, black); @@ -2137,7 +2147,8 @@ namespace rs2 //////////////////////////////////////// std::string save_button_name = rsutils::string::from() << textual_icons::download << "##" << id; ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 1); //Align the two icons to buttom - if (ImGui::ButtonEx(save_button_name.c_str(), icons_size, buttons_flags)) + ImGui::BeginDisabled(buttons_disable); + if (ImGui::ButtonEx(save_button_name.c_str(), icons_size)) { if (serializable && (!is_advanced_device || is_advanced_mode_enabled)) { @@ -2153,6 +2164,7 @@ namespace rs2 } } + ImGui::EndDisabled(); if (ImGui::IsItemHovered()) { ImGui::PushStyleColor(ImGuiCol_PopupBg, black); @@ -2860,7 +2872,9 @@ namespace rs2 ImGui::PushStyleColor(ImGuiCol_Text, redish); ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, redish + 0.1f); - ImGui::ButtonEx(label.c_str(), button_size, ImGuiItemFlags_Disabled); + ImGui::BeginDisabled(); + ImGui::ButtonEx(label.c_str(), button_size); + ImGui::EndDisabled(); } else { @@ -2870,7 +2884,9 @@ namespace rs2 << pb->get_name(); ImGui::PushStyleColor(ImGuiCol_Text, light_blue); ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, light_blue + 0.1f); - ImGui::ButtonEx(label.c_str(), button_size, ImGuiItemFlags_Disabled); + ImGui::BeginDisabled(); + ImGui::ButtonEx(label.c_str(), button_size); + ImGui::EndDisabled(); } } else diff --git a/common/viewer.cpp b/common/viewer.cpp index 17a944650e..7fcfac543b 100644 --- a/common/viewer.cpp +++ b/common/viewer.cpp @@ -2258,7 +2258,7 @@ namespace rs2 ImGui::SetNextWindowPos({ panel_width, 0 }); ImGui::SetNextWindowSize({ window.width() - panel_width, panel_y }); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(5, 5)); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); ImGui::PushStyleColor(ImGuiCol_WindowBg, button_color); ImGui::Begin("Toolbar Panel", nullptr, flags);