1+ #include " NodeEditorPanel.h"
2+ #include < imgui.h>
3+
4+ NodeEditorPanel::NodeEditorPanel (const std::string& name, bool isVisible)
5+ : Panel(name), m_EditorContext(nullptr )
6+ {
7+ SetVisible (isVisible);
8+ m_EditorContext = ed::CreateEditor (); // Create the node editor context
9+ ed::Config config;
10+ config.SettingsFile = nullptr ; // Prevent saving settings
11+ m_EditorContext = ed::CreateEditor (&config);
12+ ed::SetCurrentEditor (m_EditorContext);
13+
14+ // Set background color
15+ ed::Style& style = ed::GetStyle ();
16+ style.Colors [ed::StyleColor_Bg] = ImColor (20 , 20 , 20 , 255 ); // Dark Gray
17+ style.Colors [ed::StyleColor_Grid] = ImColor (30 , 30 , 30 , 255 ); // Grid color
18+ style.Colors [ed::StyleColor_NodeBg] = ImColor (40 , 40 , 40 , 255 ); // Node bg
19+ style.Colors [ed::StyleColor_NodeBorder] = ImColor (80 , 80 , 80 , 255 ); // Node border
20+ style.Colors [ed::StyleColor_HovNodeBorder] = ImColor (155 , 194 , 130 , 255 ); // Hovered node border
21+ }
22+
23+ NodeEditorPanel::~NodeEditorPanel ()
24+ {
25+ ed::DestroyEditor (m_EditorContext); // Cleanup the node editor
26+ }
27+
28+ void NodeEditorPanel::Render ()
29+ {
30+ if (IsVisible ())
31+ {
32+ ImGui::Begin (GetName ().c_str (), &m_Visible);
33+
34+ ImGui::Text (GetName ().c_str ()); // Debug
35+
36+ ed::SetCurrentEditor (m_EditorContext);
37+ ed::Begin (" Node Editor" );
38+
39+ // Example Node
40+ ed::BeginNode (1 );
41+ ImGui::Text (" Node 1" );
42+
43+ ed::BeginPin (2 , ed::PinKind::Input);
44+ ImGui::Text (" -> Input" );
45+ ed::EndPin ();
46+
47+ ed::BeginPin (3 , ed::PinKind::Output);
48+ ImGui::Text (" Output ->" );
49+ ed::EndPin ();
50+
51+ ed::EndNode ();
52+ // ed::SetNodePosition(1, ImVec2(100, 100)); // Ensure visible position
53+
54+ // Example Node
55+ ed::BeginNode (4 );
56+ ImGui::Text (" Node 2" );
57+
58+ ed::BeginPin (5 , ed::PinKind::Input);
59+ ImGui::Text (" -> Input" );
60+ ed::EndPin ();
61+
62+ ed::BeginPin (6 , ed::PinKind::Output);
63+ ImGui::Text (" Output ->" );
64+ ed::EndPin ();
65+
66+ ed::EndNode ();
67+
68+ ed::End ();
69+ ed::SetCurrentEditor (nullptr );
70+
71+ ImGui::End ();
72+ }
73+ }
0 commit comments