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

Method show

example/save_load.cpp:39–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37 SaveLoadEditor() : nodes_(), links_(), current_id_(0) {}
38
39 void show()
40 {
41 ImGui::Begin("Save & load example");
42 ImGui::TextUnformatted("A -- add node");
43 ImGui::TextUnformatted(
44 "Close the executable and rerun it -- your nodes should be exactly "
45 "where you left them!");
46
47 ImNodes::BeginNodeEditor();
48
49 if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
50 ImNodes::IsEditorHovered() && ImGui::IsKeyReleased(SDL_SCANCODE_A))
51 {
52 const int node_id = ++current_id_;
53 ImNodes::SetNodeScreenSpacePos(node_id, ImGui::GetMousePos());
54 nodes_.push_back(Node(node_id, 0.f));
55 }
56
57 for (Node& node : nodes_)
58 {
59 ImNodes::BeginNode(node.id);
60
61 ImNodes::BeginNodeTitleBar();
62 ImGui::TextUnformatted("node");
63 ImNodes::EndNodeTitleBar();
64
65 ImNodes::BeginInputAttribute(node.id << 8);
66 ImGui::TextUnformatted("input");
67 ImNodes::EndInputAttribute();
68
69 ImNodes::BeginStaticAttribute(node.id << 16);
70 ImGui::PushItemWidth(120.f);
71 ImGui::DragFloat("value", &node.value, 0.01f);
72 ImGui::PopItemWidth();
73 ImNodes::EndStaticAttribute();
74
75 ImNodes::BeginOutputAttribute(node.id << 24);
76 const float text_width = ImGui::CalcTextSize("output").x;
77 ImGui::Indent(120.f + ImGui::CalcTextSize("value").x - text_width);
78 ImGui::TextUnformatted("output");
79 ImNodes::EndOutputAttribute();
80
81 ImNodes::EndNode();
82 }
83
84 for (const Link& link : links_)
85 {
86 ImNodes::Link(link.id, link.start_attr, link.end_attr);
87 }
88
89 ImNodes::EndNodeEditor();
90
91 {
92 Link link;
93 if (ImNodes::IsLinkCreated(&link.start_attr, &link.end_attr))
94 {
95 link.id = ++current_id_;
96 links_.push_back(link);

Callers 1

NodeEditorShowFunction · 0.45

Calls 15

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
BeginOutputAttributeFunction · 0.85

Tested by

no test coverage detected