example: demo window only

This commit is contained in:
4DBug committed 2026-10-17 06:05:39 -05:00
1 parent 051c4fec8f
commit 9d22a447cc
2 files changed
+3 -48

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@ ImGui.End()
ImPlot.ShowDemoWindow(true)
```
Full LocalScript: `examples/roblox/main.client.luau` (live scrolling sine wave + demo windows).
Full LocalScript: `examples/roblox/main.client.luau` (ImPlot demo window).
## API differences from C++
+2 -47
View File
@@ -1,4 +1,4 @@
-- Live sine wave (scrolling buffer) + ImPlot / ImGui demo windows.
-- ImPlot demo window.
local RS = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local G = require(RS:WaitForChild("ImGui"))
@@ -6,58 +6,13 @@ local ImPlot = require(RS:WaitForChild("ImPlot"))(G)
require(RS:WaitForChild("ImPlotDemo"))(G, ImPlot)
local ImGui = G.ImGui
local MaxPoints = 500
local Xs, Ys = table.create(MaxPoints, 0), table.create(MaxPoints, 0)
local Count, Offset, Time = 0, 0, 0
local Frequency = 1
local ShowImPlotDemo, ShowImGuiDemo = true, false
local function AddPoint(X, Y)
if Count < MaxPoints then
Count += 1
Xs[Count], Ys[Count] = X, Y
else
Xs[Offset + 1], Ys[Offset + 1] = X, Y
Offset = (Offset + 1) % MaxPoints
end
end
local StartClock = os.clock()
local function RenderDemo()
Time = os.clock() - StartClock
AddPoint(Time, math.sin(Time * Frequency * 2 * math.pi))
ImGui.SetNextWindowSize(G.ImVec2(600, 400), G.ImGuiCond.FirstUseEver)
ImGui.Begin("Live Sine")
_, ShowImPlotDemo = ImGui.Checkbox("ImPlot Demo", ShowImPlotDemo)
ImGui.SameLine()
_, ShowImGuiDemo = ImGui.Checkbox("ImGui Demo", ShowImGuiDemo)
Frequency = ImGui.SliderFloat("Frequency", Frequency, 0.1, 5)
if ImPlot.BeginPlot("##Sine", G.ImVec2(-1, -1)) then
ImPlot.SetupAxisLimits(ImPlot.ImAxis.X1, Time - 10, Time, G.ImGuiCond.Always)
ImPlot.SetupAxisLimits(ImPlot.ImAxis.Y1, -1.1, 1.1)
-- ring buffer: Offset (0-based, in elements) via spec, as in the C++ ScrollingBuffer demo
ImPlot.PlotLine("sin", Xs, Ys, Count, { Offset = Offset })
ImPlot.EndPlot()
end
ImGui.End()
if ShowImPlotDemo then
ShowImPlotDemo = ImPlot.ShowDemoWindow(ShowImPlotDemo)
end
if ShowImGuiDemo then
ShowImGuiDemo = ImGui.ShowDemoWindow(ShowImGuiDemo)
end
end
ImGui.CreateContext()
ImPlot.CreateContext()
G.ImGui_ImplRoblox.Init() -- defaults to LocalPlayer.PlayerGui
RunService.RenderStepped:Connect(function()
G.ImGui_ImplRoblox.NewFrame()
ImGui.NewFrame()
RenderDemo()
ImPlot.ShowDemoWindow()
ImGui.Render()
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
end)