Add snapping to ends of the gradient line#3732
Add snapping to ends of the gradient line#3732jsjgdh wants to merge 1 commit intoGraphiteEditor:masterfrom
Conversation
editor/src/messages/portfolio/document/overlays/utility_types_native.rs
Outdated
Show resolved
Hide resolved
editor/src/messages/portfolio/document/overlays/utility_types_native.rs
Outdated
Show resolved
Hide resolved
| let projection = ((end - start).angle_to(mouse - start)).cos() * start.distance(mouse) / start.distance(end); | ||
|
|
||
| if distance.abs() < SEGMENT_INSERTION_DISTANCE && (0. ..=1.).contains(&projection) { | ||
| if let Some(index) = gradient.clone().insert_stop(mouse, transform) { |
There was a problem hiding this comment.
gradient.clone() is called twice and insert_stop is called twice. This can be simplified:
let mut new_gradient = gradient.clone();
if let Some(index) = new_gradient.insert_stop(mouse, transform) {
responses.add(DocumentMessage::StartTransaction);
transaction_started = true;
let mut selected_gradient = SelectedGradient::new(new_gradient, layer, document);
selected_gradient.dragging = GradientDragTarget::Step(index);
// No offset when inserting a new stop, it should be exactly under the mouse
selected_gradient.render_gradient(responses);
tool_data.selected_gradient = Some(selected_gradient);
dragging = true;
}
|
This kind of snapping doesn't actually snap: capture_10_.mp4It would need to calculate the color stop position where the gradient line intersects the snapping target line and snap it to that position when the snap is active, since the whole point of a snap is to take the precise mouse movements surrounding a target and jump them all to the exact value. This also occurs when dragging an endpoint when Shift is held to snap to a 15° angle increment. Note that the Line tool's implementation of this same behavior does work as expected when you're dragging a line's endpoint and holding Shift or Ctrl to lock the angle: capture_11_.mp4The snapping tolerance for this scenario is more sane in the Line tool (smaller tolerance area) than it is for the Gradient tool (too large of a tolerance area, should match Line tool's behavior). This is something I'm willing to wait on for a followup PR, if you prefer. |
Closes #3261