| 33 | }; |
| 34 | |
| 35 | void show_editor(const char* editor_name, Editor& editor) |
| 36 | { |
| 37 | ImNodes::EditorContextSet(editor.context); |
| 38 | |
| 39 | ImGui::Begin(editor_name); |
| 40 | ImGui::TextUnformatted("A -- add node"); |
| 41 | |
| 42 | ImNodes::BeginNodeEditor(); |
| 43 | |
| 44 | if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) && |
| 45 | ImNodes::IsEditorHovered() && ImGui::IsKeyReleased(SDL_SCANCODE_A)) |
| 46 | { |
| 47 | const int node_id = ++editor.current_id; |
| 48 | ImNodes::SetNodeScreenSpacePos(node_id, ImGui::GetMousePos()); |
| 49 | editor.nodes.push_back(Node(node_id, 0.f)); |
| 50 | } |
| 51 | |
| 52 | for (Node& node : editor.nodes) |
| 53 | { |
| 54 | ImNodes::BeginNode(node.id); |
| 55 | |
| 56 | ImNodes::BeginNodeTitleBar(); |
| 57 | ImGui::TextUnformatted("node"); |
| 58 | ImNodes::EndNodeTitleBar(); |
| 59 | |
| 60 | ImNodes::BeginInputAttribute(node.id << 8); |
| 61 | ImGui::TextUnformatted("input"); |
| 62 | ImNodes::EndInputAttribute(); |
| 63 | |
| 64 | ImNodes::BeginStaticAttribute(node.id << 16); |
| 65 | ImGui::PushItemWidth(120.0f); |
| 66 | ImGui::DragFloat("value", &node.value, 0.01f); |
| 67 | ImGui::PopItemWidth(); |
| 68 | ImNodes::EndStaticAttribute(); |
| 69 | |
| 70 | ImNodes::BeginOutputAttribute(node.id << 24); |
| 71 | const float text_width = ImGui::CalcTextSize("output").x; |
| 72 | ImGui::Indent(120.f + ImGui::CalcTextSize("value").x - text_width); |
| 73 | ImGui::TextUnformatted("output"); |
| 74 | ImNodes::EndOutputAttribute(); |
| 75 | |
| 76 | ImNodes::EndNode(); |
| 77 | } |
| 78 | |
| 79 | for (const Link& link : editor.links) |
| 80 | { |
| 81 | ImNodes::Link(link.id, link.start_attr, link.end_attr); |
| 82 | } |
| 83 | |
| 84 | ImNodes::EndNodeEditor(); |
| 85 | |
| 86 | { |
| 87 | Link link; |
| 88 | if (ImNodes::IsLinkCreated(&link.start_attr, &link.end_attr)) |
| 89 | { |
| 90 | link.id = ++editor.current_id; |
| 91 | editor.links.push_back(link); |
| 92 | } |
no test coverage detected