diff --git a/cpp/functions/gfx/dag_panel.cpp b/cpp/functions/gfx/dag_panel.cpp index af42e49d..589bf803 100644 --- a/cpp/functions/gfx/dag_panel.cpp +++ b/cpp/functions/gfx/dag_panel.cpp @@ -95,6 +95,8 @@ bool dag_panel(std::vector& pipeline) { int delete_idx = -1; int move_up_idx = -1; int move_down_idx = -1; + int drop_src_idx = -1; + int drop_target_idx = -1; ImGui::BeginChild("dag_pipeline_scroll", ImVec2(0, 0), false); @@ -115,6 +117,19 @@ bool dag_panel(std::vector& pipeline) { ImGui::PopStyleColor(3); + if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { + ImGui::SetDragDropPayload("DAG_STEP", &i, sizeof(int)); + ImGui::Text("Move %s", def->label.c_str()); + ImGui::EndDragDropSource(); + } + if (ImGui::BeginDragDropTarget()) { + if (const ImGuiPayload* pl = ImGui::AcceptDragDropPayload("DAG_STEP")) { + drop_src_idx = *static_cast(pl->Data); + drop_target_idx = i; + } + ImGui::EndDragDropTarget(); + } + if (open) { ImGui::Indent(8.0f); @@ -221,6 +236,16 @@ bool dag_panel(std::vector& pipeline) { std::swap(pipeline[static_cast(move_down_idx)], pipeline[static_cast(move_down_idx + 1)]); changed = true; } + if (drop_src_idx >= 0 && drop_target_idx >= 0 && drop_src_idx != drop_target_idx && + drop_src_idx < static_cast(pipeline.size()) && + drop_target_idx < static_cast(pipeline.size())) { + DagStep moved = pipeline[static_cast(drop_src_idx)]; + pipeline.erase(pipeline.begin() + drop_src_idx); + int target = drop_target_idx; + if (drop_src_idx < drop_target_idx) target--; + pipeline.insert(pipeline.begin() + target, moved); + changed = true; + } return changed; }