MCPcopy Create free account
hub / github.com/Nelarius/imnodes / show_editor

Function show_editor

example/multi_editor.cpp:35–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33};
34
35void 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 }

Callers 1

NodeEditorShowFunction · 0.85

Calls 15

EditorContextSetFunction · 0.85
BeginNodeEditorFunction · 0.85
IsEditorHoveredFunction · 0.85
SetNodeScreenSpacePosFunction · 0.85
BeginNodeFunction · 0.85
BeginNodeTitleBarFunction · 0.85
EndNodeTitleBarFunction · 0.85
BeginInputAttributeFunction · 0.85
EndInputAttributeFunction · 0.85
BeginStaticAttributeFunction · 0.85
DragFloatFunction · 0.85
EndStaticAttributeFunction · 0.85

Tested by

no test coverage detected