mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-23 20:28:13 +08:00
Add snapping to endpoints and stops in the Gradient tool (#3732)
* snapping * Cleanup * fix * Fix snapping failing sometimes on newly drawn gradient lines * Code cleanup --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
co-authored by
Keavon Chambers
parent
691d965bcf
commit
3b91d02fff
@@ -251,15 +251,23 @@ impl SnapManager {
|
||||
pub fn update_indicator(&mut self, snapped_point: SnappedPoint) {
|
||||
self.indicator = snapped_point.is_snapped().then_some(snapped_point);
|
||||
}
|
||||
|
||||
pub fn clear_indicator(&mut self) {
|
||||
self.indicator = None;
|
||||
}
|
||||
|
||||
pub fn preview_draw(&mut self, snap_data: &SnapData, mouse: DVec2) {
|
||||
let point = SnapCandidatePoint::handle(snap_data.document.metadata().document_to_viewport.inverse().transform_point2(mouse));
|
||||
let snapped = self.free_snap(snap_data, &point, SnapTypeConfiguration::default());
|
||||
self.update_indicator(snapped);
|
||||
}
|
||||
|
||||
pub fn preview_draw_gradient(&mut self, snap_data: &SnapData, mouse: DVec2) {
|
||||
let point = SnapCandidatePoint::gradient_handle(snap_data.document.metadata().document_to_viewport.inverse().transform_point2(mouse));
|
||||
let snapped = self.free_snap(snap_data, &point, SnapTypeConfiguration::default());
|
||||
self.update_indicator(snapped);
|
||||
}
|
||||
|
||||
pub fn indicator_pos(&self) -> Option<DVec2> {
|
||||
self.indicator.as_ref().map(|point| point.snapped_point_document)
|
||||
}
|
||||
|
||||
@@ -453,6 +453,10 @@ impl SnapCandidatePoint {
|
||||
Self::new_source(document_point, SnapSource::Path(PathSnapSource::AnchorPointWithFreeHandles))
|
||||
}
|
||||
|
||||
pub fn gradient_handle(document_point: DVec2) -> Self {
|
||||
Self::new_source(document_point, SnapSource::Gradient(GradientSnapSource::Endpoint))
|
||||
}
|
||||
|
||||
pub fn handle_neighbors(document_point: DVec2, neighbors: impl Into<Vec<DVec2>>) -> Self {
|
||||
let mut point = Self::new_source(document_point, SnapSource::Path(PathSnapSource::AnchorPointWithFreeHandles));
|
||||
point.neighbors = neighbors.into();
|
||||
|
||||
Reference in New Issue
Block a user