From 9f62e01ab872ae708bedce1e9d7af2ec36bc06b1 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Thu, 19 Sep 2024 13:43:39 +0200 Subject: [PATCH] wip stream manager ui rework --- src/debug_video_tap.cpp | 4 +- src/stream_manager_ui.cpp | 197 +++++++++++++++++++++++++++----------- 2 files changed, 145 insertions(+), 56 deletions(-) diff --git a/src/debug_video_tap.cpp b/src/debug_video_tap.cpp index 698c3fc..f76bdcc 100644 --- a/src/debug_video_tap.cpp +++ b/src/debug_video_tap.cpp @@ -139,7 +139,7 @@ float DebugVideoTap::render(void) { // list sources dropdown to connect too std::string preview_label {"none"}; if (static_cast(_selected_src)) { - preview_label = std::to_string(entt::to_integral(_selected_src.entity())) + " (" + _selected_src.get().name + ")"; + preview_label = std::to_string(entt::to_integral(entt::to_entity(_selected_src.entity()))) + " (" + _selected_src.get().name + ")"; } if (ImGui::BeginCombo("selected source", preview_label.c_str())) { @@ -151,7 +151,7 @@ float DebugVideoTap::render(void) { if (ss.frame_type_name != entt::type_name::value()) { continue; } - std::string label = std::to_string(entt::to_integral(oc)) + " (" + ss.name + ")"; + std::string label = std::to_string(entt::to_integral(entt::to_entity(oc))) + " (" + ss.name + ")"; if (ImGui::Selectable(label.c_str())) { switchTo({_os.registry(), oc}); } diff --git a/src/stream_manager_ui.cpp b/src/stream_manager_ui.cpp index 11a4a4c..e832127 100644 --- a/src/stream_manager_ui.cpp +++ b/src/stream_manager_ui.cpp @@ -20,82 +20,171 @@ void StreamManagerUI::render(void) { ImGui::SeparatorText("Sources"); - // TODO: tables of id, button connect->to, name, type - // list sources - for (const auto& [oc, ss] : _os.registry().view().each()) { - ImGui::Text("src %d (%s)[%s]", entt::to_integral(entt::to_entity(oc)), ss.name.c_str(), ss.frame_type_name.c_str()); + if (ImGui::BeginTable("sources_and_sinks", 4, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_BordersInnerV)) { + ImGui::TableSetupColumn("id"); + ImGui::TableSetupColumn("name"); + ImGui::TableSetupColumn("##conn"); + ImGui::TableSetupColumn("type"); + + ImGui::TableHeadersRow(); + + for (const auto& [oc, ss] : _os.registry().view().each()) { + //ImGui::Text("src %d (%s)[%s]", entt::to_integral(entt::to_entity(oc)), ss.name.c_str(), ss.frame_type_name.c_str()); + + ImGui::TableNextColumn(); + ImGui::Text("%d", entt::to_integral(entt::to_entity(oc))); + + const auto *ssrc = _os.registry().try_get(oc); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(ssrc!=nullptr?ssrc->name.c_str():"none"); + + ImGui::TableNextColumn(); + if (ImGui::SmallButton("->")) { + // TODO: list type sinks + } + + ImGui::TableNextColumn(); + ImGui::TextUnformatted(ssrc!=nullptr?ssrc->frame_type_name.c_str():"???"); + } + + ImGui::EndTable(); } ImGui::SeparatorText("Sinks"); // list sinks - for (const auto& [oc, ss] : _os.registry().view().each()) { - ImGui::PushID(entt::to_integral(oc)); - ImGui::Text("sink %d (%s)[%s]", entt::to_integral(entt::to_entity(oc)), ss.name.c_str(), ss.frame_type_name.c_str()); + if (ImGui::BeginTable("sources_and_sinks", 4, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_BordersInnerV)) { + ImGui::TableSetupColumn("id"); + ImGui::TableSetupColumn("name"); + ImGui::TableSetupColumn("##conn"); + ImGui::TableSetupColumn("type"); - if (ImGui::BeginPopupContextItem("sink_connect")) { - if (ImGui::BeginMenu("connect video", ss.frame_type_name == entt::type_name::value())) { - for (const auto& [oc_src, s_src] : _os.registry().view().each()) { - if (s_src.frame_type_name != ss.frame_type_name) { - continue; + ImGui::TableHeadersRow(); + + for (const auto& [oc, ss] : _os.registry().view().each()) { + //ImGui::Text("sink %d (%s)[%s]", entt::to_integral(entt::to_entity(oc)), ss.name.c_str(), ss.frame_type_name.c_str()); + + //ImGui::PushID(entt::to_integral(oc)); + + ImGui::TableNextColumn(); + ImGui::Text("%d", entt::to_integral(entt::to_entity(oc))); + + const auto *ssink = _os.registry().try_get(oc); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(ssink!=nullptr?ssink->name.c_str():"none"); + + ImGui::TableNextColumn(); + if (ImGui::SmallButton("->")) { + // TODO: list type sinks + } + if (ImGui::BeginPopupContextItem("sink_connect")) { + if (ImGui::BeginMenu("connect video", ss.frame_type_name == entt::type_name::value())) { + for (const auto& [oc_src, s_src] : _os.registry().view().each()) { + if (s_src.frame_type_name != ss.frame_type_name) { + continue; + } + + ImGui::PushID(entt::to_integral(oc_src)); + + std::string source_label {"src "}; + source_label += std::to_string(entt::to_integral(entt::to_entity(oc_src))); + source_label += " ("; + source_label += s_src.name; + source_label += ")["; + source_label += s_src.frame_type_name; + source_label += "]"; + if (ImGui::MenuItem(source_label.c_str())) { + _sm.connect(oc_src, oc); + } + + ImGui::PopID(); } - ImGui::PushID(entt::to_integral(oc_src)); - - std::string source_label {"src "}; - source_label += std::to_string(entt::to_integral(entt::to_entity(oc_src))); - source_label += " ("; - source_label += s_src.name; - source_label += ")["; - source_label += s_src.frame_type_name; - source_label += "]"; - if (ImGui::MenuItem(source_label.c_str())) { - _sm.connect(oc_src, oc); - } - - ImGui::PopID(); + ImGui::EndMenu(); } - ImGui::EndMenu(); - } + if (ImGui::BeginMenu("connect audio", ss.frame_type_name == entt::type_name::value())) { + for (const auto& [oc_src, s_src] : _os.registry().view().each()) { + if (s_src.frame_type_name != ss.frame_type_name) { + continue; + } - if (ImGui::BeginMenu("connect audio", ss.frame_type_name == entt::type_name::value())) { - for (const auto& [oc_src, s_src] : _os.registry().view().each()) { - if (s_src.frame_type_name != ss.frame_type_name) { - continue; + ImGui::PushID(entt::to_integral(oc_src)); + + std::string source_label {"src "}; + source_label += std::to_string(entt::to_integral(entt::to_entity(oc_src))); + source_label += " ("; + source_label += s_src.name; + source_label += ")["; + source_label += s_src.frame_type_name; + source_label += "]"; + if (ImGui::MenuItem(source_label.c_str())) { + _sm.connect(oc_src, oc); + } + + ImGui::PopID(); } - ImGui::PushID(entt::to_integral(oc_src)); - - std::string source_label {"src "}; - source_label += std::to_string(entt::to_integral(entt::to_entity(oc_src))); - source_label += " ("; - source_label += s_src.name; - source_label += ")["; - source_label += s_src.frame_type_name; - source_label += "]"; - if (ImGui::MenuItem(source_label.c_str())) { - _sm.connect(oc_src, oc); - } - - ImGui::PopID(); + ImGui::EndMenu(); } - - ImGui::EndMenu(); + ImGui::EndPopup(); } - ImGui::EndPopup(); + + ImGui::TableNextColumn(); + ImGui::TextUnformatted(ssink!=nullptr?ssink->frame_type_name.c_str():"???"); + + //ImGui::PopID(); } - ImGui::PopID(); + + ImGui::EndTable(); } ImGui::SeparatorText("Connections"); - // TODO: table of id, button disconnect, context x->y, from name, to name, type? - // list connections - for (const auto& con : _sm._connections) { - ImGui::Text("con %d->%d", entt::to_integral(entt::to_entity(con->src.entity())), entt::to_integral(entt::to_entity(con->sink.entity()))); + if (ImGui::BeginTable("connections", 6, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_BordersInnerV)) { + ImGui::TableSetupColumn("##id"); // TODO: remove? + ImGui::TableSetupColumn("##disco"); + ImGui::TableSetupColumn("##qdesc"); + ImGui::TableSetupColumn("from"); + ImGui::TableSetupColumn("to"); + ImGui::TableSetupColumn("type"); + + ImGui::TableHeadersRow(); + + for (const auto& con : _sm._connections) { + //ImGui::Text("con %d->%d", entt::to_integral(entt::to_entity(con->src.entity())), entt::to_integral(entt::to_entity(con->sink.entity()))); + + ImGui::TableNextColumn(); + ImGui::Text("%d", -1); // do connections have ids? + + ImGui::TableNextColumn(); + if (ImGui::SmallButton("X")) { + // TODO: disconnect + } + + ImGui::TableNextColumn(); + ImGui::Text("%d->%d", entt::to_integral(entt::to_entity(con->src.entity())), entt::to_integral(entt::to_entity(con->sink.entity()))); + + const auto *ssrc = con->src.try_get(); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(ssrc!=nullptr?ssrc->name.c_str():"none"); + + const auto *ssink = con->sink.try_get(); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(ssink!=nullptr?ssink->name.c_str():"none"); + + ImGui::TableNextColumn(); + ImGui::TextUnformatted( + (ssrc!=nullptr)? + ssrc->frame_type_name.c_str(): + (ssink!=nullptr)? + ssink->frame_type_name.c_str() + :"???" + ); + } + ImGui::EndTable(); } } ImGui::End();