Skip to content

Commit

Permalink
button disabled functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Noy-Zini committed Dec 10, 2024
1 parent 41a586b commit a64e4a3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
56 changes: 36 additions & 20 deletions common/device-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)");
Expand Down Expand Up @@ -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)
Expand All @@ -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)");
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -1259,6 +1263,7 @@ namespace rs2
if (path != "") start_recording(path, error_message);
}
}
ImGui::EndDisabled();
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_Text, white);
Expand All @@ -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
Expand All @@ -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())
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<subdevice_model>& 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<advanced_mode>();
auto is_advanced_device = false;
Expand All @@ -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))
{
Expand All @@ -2118,7 +2128,7 @@ namespace rs2
require_advanced_mode_enable_prompt = true;
}
}

ImGui::EndDisabled();
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_PopupBg, black);
Expand All @@ -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))
{
Expand All @@ -2153,6 +2164,7 @@ namespace rs2
}

}
ImGui::EndDisabled();
if (ImGui::IsItemHovered())
{
ImGui::PushStyleColor(ImGuiCol_PopupBg, black);
Expand Down Expand Up @@ -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
{
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion common/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit a64e4a3

Please sign in to comment.