Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I just wanted to implement snapping in the Gradient Editor. But when I pulled on that thread, the whole ball of yarn unraveled.
Refactoring
Previously, we had two sets of files (
gradient_editor
andgradient_editor_plugin
).gradient_editor
had the GradientEditor class. This was for the colorful rectangle that lets you edit a gradient, having all the logic around GUI input on it and also the color selector.gradient_editor_plugin
had the EditorInspectorPluginGradient class, which included the GradientEditor and a small button for reversing the gradient. It also had the GradientReverseButton class, because... yeah, needed a hack just to add that button. This wasn't scalable.I renamed GradientEditor to GradientEditorRect. The stuff inside EditorInspectorPluginGradient are essentially moved to the new GradientEditor, which includes a GradientEditorRect and regular buttons. These were all moved to one file like other editor plugins.
Snap Button
Looks like this:
The slider and the vertical lines are only shown when snap is toggled.
I removed
Ctrl+Drag
(which snaps with 10 partitions) andCtrl+Shift+Drag
(which snaps with 40 partitions) as the snap button makes these tricks completely obsolete.Shift+Drag
still works and is quite useful to get two points near each other when snapping. I gave it a smaller threshold by default.Improved Undo/Redo system
The undo/redo system wasn't functional. The single manager in
_ramp_changed()
left thousands of vague "Gradient Changed" messages in the output and would usually only lead you one step back before breaking, and that step back would usually not be where you wanted to get.I didn't want to leave this system even more broken than before, so I modernized it. Now it has more descriptive messages and is more predictable. Code was simplified a lot too, removing some unused or unnecessary things.
Testing/Review on this would be appreciated because it might corrupt gradients if not done right!
Misc enhancements
gradient.h
(ponit -> point 🎠)(dw you're not having deja vu. I screwed up my old PR with a bad rebase)