Files

54 lines
1.6 KiB
Luau

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()
ImNodes.CreateContext()
local function frame()
Impl.NewFrame()
ImGui.GetIO().DeltaTime = 1 / 60
ImGui.NewFrame()
ImGui.Begin("editor")
ImNodes.BeginNodeEditor()
for id = 1, 2 do
ImNodes.BeginNode(id)
ImGui.Text("node")
ImNodes.EndNode()
end
ImNodes.EndNodeEditor()
ImGui.End()
ImGui.Render()
Impl.RenderDrawData(ImGui.GetDrawData())
end
frame()
ImNodes.SetNodeGridSpacePos(1, ImVec2(123, 45))
ImNodes.SetNodeGridSpacePos(2, ImVec2(-67, 89))
ImNodes.EditorContextResetPanning(ImVec2(10, -20))
frame()
local ini = ImNodes.SaveCurrentEditorStateToIniString()
assert(string.find(ini, "[node.1]", 1, true) and string.find(ini, "origin=-67,89", 1, true), ini)
ImNodes.SetNodeGridSpacePos(1, ImVec2(0, 0))
ImNodes.SetNodeGridSpacePos(2, ImVec2(0, 0))
ImNodes.EditorContextResetPanning(ImVec2(0, 0))
ImNodes.LoadCurrentEditorStateFromIniString(ini)
frame()
local p1, p2, pan = ImNodes.GetNodeGridSpacePos(1), ImNodes.GetNodeGridSpacePos(2), ImNodes.EditorContextGetPanning()
assert(p1.x == 123 and p1.y == 45, `node1 {p1.x},{p1.y}`)
assert(p2.x == -67 and p2.y == 89, `node2 {p2.x},{p2.y}`)
assert(pan.x == 10 and pan.y == -20, `pan {pan.x},{pan.y}`)
-- explicit editor context, round trip
local ed = ImNodes.EditorContextCreate()
ImNodes.LoadEditorStateFromIniString(ed, ini)
assert(ImNodes.SaveEditorStateToIniString(ed) == ini)
ImNodes.DestroyContext()
print("OK")