ImGradient: port of ImGuizmo's ImGradient (@105e4fd), tests, Roblox example
This commit is contained in:
commit
5ae035ad42
15 files changed
+543
No files matched your search
@@ -0,0 +1,45 @@
|
||||
# imgradient-luau
|
||||
|
||||
Gradient editor widget for imgui-luau: drag color points along a bar, click to select, double-click to add.
|
||||
|
||||
Luau port of ImGradient 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/imgradient-luau) / [GitHub](https://github.com/4DBug/imgradient-luau).
|
||||
|
||||
## Usage
|
||||
|
||||
```lua
|
||||
local G = require(ReplicatedStorage.ImGui)
|
||||
local ImGradient = require(ReplicatedStorage.ImGradient)(G)
|
||||
|
||||
-- Delegate (C++ ImGradient::Delegate): any table with these methods
|
||||
local Gradient = { Points = { G.ImVec4(1, 0, 0, 0), G.ImVec4(0, 0, 1, 1) } } -- rgb + position (w)
|
||||
function Gradient:GetPointCount() return #self.Points end
|
||||
function Gradient:GetPoints() return self.Points end -- 1-based array of ImVec4
|
||||
function Gradient:EditPoint(i, v) self.Points[i] = v; return i end
|
||||
function Gradient:GetPoint(t) ... end -- color at t, for double-click insertion
|
||||
function Gradient:AddPoint(v) table.insert(self.Points, v) end
|
||||
|
||||
-- each frame, inside a window:
|
||||
local changed
|
||||
changed, selection = ImGradient.Edit(Gradient, G.ImVec2(400, 24), selection)
|
||||
```
|
||||
|
||||
`[Port]` differences: point indices and `selection` are 1-based (`-1` = none); `Edit` returns `changed, selection`
|
||||
instead of writing `int& selection`. As upstream, the widget draws only the points (draw the gradient behind it), and
|
||||
selection/drag state is shared by all gradient editors (C++ function statics).
|
||||
|
||||
Full example (gradient drawn behind the widget, color editing, conversion to a Roblox `ColorSequence`):
|
||||
`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/imgradient-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).
|
||||
Reference in new issue
Block a user