feat(shaders_lab): drag-and-drop to reorder DAG steps
ImGui native BeginDragDropSource/Target over each CollapsingHeader. Drag source adjusted if ahead of target to keep final position correct. Move Up/Down buttons kept for keyboard/touchpad fallback. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -95,6 +95,8 @@ bool dag_panel(std::vector<DagStep>& 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<DagStep>& 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<const int*>(pl->Data);
|
||||
drop_target_idx = i;
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
if (open) {
|
||||
ImGui::Indent(8.0f);
|
||||
|
||||
@@ -221,6 +236,16 @@ bool dag_panel(std::vector<DagStep>& pipeline) {
|
||||
std::swap(pipeline[static_cast<size_t>(move_down_idx)], pipeline[static_cast<size_t>(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<int>(pipeline.size()) &&
|
||||
drop_target_idx < static_cast<int>(pipeline.size())) {
|
||||
DagStep moved = pipeline[static_cast<size_t>(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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user