local RS = game:GetService("ReplicatedStorage") local G = require(RS:WaitForChild("ImGui")) local ImNodes = require(RS:WaitForChild("ImNodes"))(G) local ImGui, ImVec2 = G.ImGui, G.ImVec2 local Impl = G.ImGui_ImplRoblox ImGui.CreateContext() Impl.Init() Impl.SetRenderRate(0) ImNodes.CreateContext() local io = ImGui.GetIO() local internal = ImNodes.internal local links = {} -- id -> {start, end} local minimap = false local created local function frame(n, before) Impl.NewFrame() io.DeltaTime = 1 / 60 if before then before() end ImGui.NewFrame() ImGui.SetNextWindowPos(ImVec2(0, 0), G.ImGuiCond.Always) ImGui.SetNextWindowSize(ImVec2(800, 600), G.ImGuiCond.Always) ImGui.Begin("editor") ImNodes.BeginNodeEditor() if n == 1 then ImNodes.SetNodeGridSpacePos(1, ImVec2(50, 50)) ImNodes.SetNodeGridSpacePos(2, ImVec2(300, 100)) end ImNodes.BeginNode(1) ImNodes.BeginNodeTitleBar() ImGui.Text("node A") ImNodes.EndNodeTitleBar() ImNodes.BeginOutputAttribute(11) ImGui.Text("out") ImNodes.EndOutputAttribute() ImNodes.EndNode() ImNodes.BeginNode(2) ImNodes.BeginNodeTitleBar() ImGui.Text("node B") ImNodes.EndNodeTitleBar() ImNodes.BeginInputAttribute(21) ImGui.Text("in") ImNodes.EndInputAttribute() ImNodes.EndNode() for id, l in links do ImNodes.Link(id, l[1], l[2]) end if minimap then ImNodes.MiniMap(0.2, ImNodes.ImNodesMiniMapLocation.BottomRight, function(id) assert(id == 1 or id == 2) end) end ImNodes.EndNodeEditor() local ok, s, e, snap = ImNodes.IsLinkCreated() if ok then created = { s, e, snap } links[100] = { s, e } end ImGui.End() ImGui.Render() local dd = ImGui.GetDrawData() Impl.RenderDrawData(dd) return dd.TotalVtxCount end local function pinPos(id) local editor = internal.EditorContextGet() return editor.Pins.Pool[editor.Pins.IdMap[id]].Pos end for n = 1, 5 do frame(n) end -- drag from output pin 11 to input pin 21 local a, b = pinPos(11), pinPos(21) frame(6, function() io:AddMousePosEvent(a.x, a.y) end) frame(7, function() io:AddMouseButtonEvent(0, true) end) local started, start_id = ImNodes.IsLinkStarted() assert(started and start_id == 11, "link not started") for i = 1, 5 do frame(7 + i, function() io:AddMousePosEvent(a.x + (b.x - a.x) * i / 5, a.y + (b.y - a.y) * i / 5) end) end frame(13, function() io:AddMouseButtonEvent(0, false) end) assert(created, "IsLinkCreated never fired") assert(created[1] == 11 and created[2] == 21 and created[3] == false, `created: {created[1]},{created[2]},{created[3]}`) frame(14) assert(ImNodes.IsLinkCreated() == false) -- box select over both nodes from empty canvas local canvas = internal.GImNodes.CanvasRectScreenSpace local p0, p1 = canvas.Min + ImVec2(5, 5), canvas.Max - ImVec2(5, 5) frame(15, function() io:AddMousePosEvent(p0.x, p0.y) end) frame(16, function() io:AddMouseButtonEvent(0, true) end) frame(17, function() io:AddMousePosEvent(p1.x, p1.y) end) frame(18, function() io:AddMouseButtonEvent(0, false) end) assert(ImNodes.NumSelectedNodes() == 2, `selected nodes: {ImNodes.NumSelectedNodes()}`) assert(#ImNodes.GetSelectedNodes() == 2) assert(ImNodes.NumSelectedLinks() == 1 and ImNodes.GetSelectedLinks()[1] == 100) ImNodes.ClearNodeSelection() ImNodes.ClearLinkSelection() ImNodes.SelectNode(2) assert(ImNodes.IsNodeSelected(2) and not ImNodes.IsNodeSelected(1)) -- minimap renders minimap = true for n = 19, 28 do assert(frame(n) > 0) end assert(internal.EditorContextGet().MiniMapScaling > 0) ImNodes.DestroyContext() print("OK")