fix(shaders_lab): drop zone no longer eats node/slider input + inline tests

The previous InvisibleButton captured mouse events, so you could drag
from the Functions palette into the canvas, but node dragging and
slider interaction inside the canvas stopped working.

Fix: watch the global drag-drop payload without an explicit target. When
the mouse releases LMB over the DAG window with a "DAG_NODE_TYPE"
payload active, queue an add at that canvas position. No button, no
capture.

Tests (compiled standalone with preprocessor defines):
- dag_compile: 6/6 asserts (empty, single gen, op chain, multi-source
  blend, Output-driven fragColor, unconnected-Output fallback).
- dag_catalog: 8/8 asserts (uniqueness, per-kind input invariants,
  exactly one Output, body_glsl present & returns, control param
  indices valid).
Build with:
  g++ -std=c++17 -Icpp/functions -DDAG_COMPILE_TEST cpp/functions/gfx/dag_compile.cpp cpp/functions/gfx/dag_catalog.cpp -o /tmp/dag_compile_test
  g++ -std=c++17 -Icpp/functions -DDAG_CATALOG_TEST cpp/functions/gfx/dag_catalog.cpp -o /tmp/dag_catalog_test

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-24 22:24:39 +02:00
parent 0be4b29a4b
commit dfbe26da01
3 changed files with 169 additions and 13 deletions
+75
View File
@@ -257,3 +257,78 @@ const DagNodeDef* dag_find(const std::string& name) {
}
} // namespace fn::gfx
#ifdef DAG_CATALOG_TEST
#include <cassert>
#include <cstdio>
#include <set>
int main() {
using namespace fn::gfx;
const auto& cat = dag_catalog();
// 1. Catalog not empty
assert(!cat.empty());
// 2. All node names are unique
std::set<std::string> names;
for (const auto& n : cat) {
assert(names.insert(n.name).second && "duplicate node name");
}
// 3. Invariants by kind
int gen_count = 0, op_count = 0, blend_count = 0, output_count = 0;
for (const auto& n : cat) {
switch (n.kind) {
case DagKind::Gen:
assert(n.num_inputs == 0 && "Gen must have 0 inputs");
++gen_count; break;
case DagKind::Op:
assert(n.num_inputs >= 1 && "Op must have >= 1 input");
++op_count; break;
case DagKind::Blend:
assert(n.num_inputs >= 2 && "Blend must have >= 2 inputs");
++blend_count; break;
case DagKind::Output:
assert(n.num_inputs == 1 && "Output must have exactly 1 input");
++output_count; break;
}
assert(n.num_inputs >= 0 && n.num_inputs <= 4);
assert(n.body_glsl && "body_glsl must be set");
}
// 4. Exactly one Output in the catalog
assert(output_count == 1 && "catalog must declare exactly one Output node");
// 5. At least one Gen and one Op
assert(gen_count >= 1);
assert(op_count >= 1);
assert(blend_count >= 1);
// 6. dag_find works and returns nullptr for unknown names
assert(dag_find("output") != nullptr);
assert(dag_find("plasma") != nullptr);
assert(dag_find("__nonexistent__") == nullptr);
// 7. Every non-Output body emits non-empty GLSL
for (const auto& n : cat) {
if (n.kind == DagKind::Output) continue;
auto body = n.body_glsl(0);
assert(!body.empty() && "non-Output nodes must emit body");
// sanity: should contain a return statement
assert(body.find("return") != std::string::npos);
}
// 8. Control param indices stay within 0..3
for (const auto& n : cat) {
for (const auto& c : n.controls) {
for (int idx : c.param_idx) {
assert(idx >= -1 && idx < 4);
}
}
}
std::printf("dag_catalog: 8/8 asserts passed (%zu nodes)\n", cat.size());
return 0;
}
#endif