imcurveedit-luau

Curve editor widget for imgui-luau: multiple curves (discrete, linear, smooth), point dragging, box selection, double-click to add points, curve dragging, Y zoom/scroll.

Luau port of ImCurveEdit from ImGuizmo for imgui-luau (GitHub). Mirrors: git.bug.tools / GitHub. Pairs with imsequencer-luau (curves inside an expanded sequencer row).

Usage

local G = require(ReplicatedStorage.ImGui)
local ImCurveEdit = require(ReplicatedStorage.ImCurveEdit)(G)

-- Delegate (C++ ImCurveEdit::Delegate): any table with these methods, curve/point indices 1-based
local Ramp = { Pts = { { G.ImVec2(0, 0), G.ImVec2(50, 1) } }, Min = G.ImVec2(0, 0), Max = G.ImVec2(100, 1) }
function Ramp:GetCurveCount() return #self.Pts end
function Ramp:GetPointCount(c) return #self.Pts[c] end
function Ramp:GetCurveColor(c) return 0xFF0080FF end
function Ramp:GetPoints(c) return self.Pts[c] end                 -- 1-based array of ImVec2
function Ramp:EditPoint(c, p, v) self.Pts[c][p] = v; return p end -- return the point's new index (if you sort)
function Ramp:AddPoint(c, v) table.insert(self.Pts[c], v) end
function Ramp:GetMin() return self.Min end                        -- ImVec2, edited in place (zoom/scroll)
function Ramp:GetMax() return self.Max end
-- optional: IsVisible(c), GetCurveType(c) (default ImCurveEdit.CurveLinear), GetBackgroundColor(), BeginEdit(i), EndEdit()

-- each frame, inside a window:
local ret
ret, selectedPoints = ImCurveEdit.Edit(Ramp, G.ImVec2(400, 200), 137, nil, selectedPoints)

[Port] differences: indices are 1-based. clippingRect is nil or an ImRect ({ Min, Max }). selectedPoints (C++ ImVector<EditPoint>*) is returned as the second value: a 1-based array of { curveIndex, pointIndex } (filled in place when you pass a table). Curve types: ImCurveEdit.CurveNone/CurveDiscrete/CurveLinear/CurveSmooth/CurveBezier (Bezier is not drawn, as upstream). As upstream, interaction state is shared by all curve editors (C++ function statics).

Full example (upstream's RampEdit): examples/roblox/main.client.luau. The module is plain Lua 5.1 and also loads on LÖVE.

Development

git clone --recursive https://git.bug.tools/bug/imcurveedit-luau.git
bash tools/test.sh   # tests/t_*.luau in the core's Roblox mock + the Roblox example

Upstream source (pinned) is in tools/upstream/; port-specific comments are tagged [Port].

License

MIT, see LICENSE (upstream copyright kept).

S
Description
No description provided
Readme MIT
63 KiB
0 Stars 1 Watchers 0 Forks
Languages
C++ 43.7%
Lua 41.9%
Luau 8.2%
Shell 6.2%