52 lines
2.7 KiB
Markdown
52 lines
2.7 KiB
Markdown
# 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](https://github.com/CedricGuillemet/ImGuizmo) for [imgui-luau](https://git.bug.tools/bug/imgui-luau) ([GitHub](https://github.com/4DBug/imgui-luau)).
|
|
Mirrors: [git.bug.tools](https://git.bug.tools/bug/imcurveedit-luau) / [GitHub](https://github.com/4DBug/imcurveedit-luau).
|
|
Pairs with [imsequencer-luau](https://git.bug.tools/bug/imsequencer-luau) (curves inside an expanded sequencer row).
|
|
|
|
## Usage
|
|
|
|
```lua
|
|
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
|
|
|
|
```sh
|
|
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).
|