DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge #309: Snap: smart guides beat the baseline grid; a box centres between two others
aionggf08899832bbe
diff --cc crates/tools/src/snap.rsindex 142525dec,c96deed79..d2462ec7d--- a/crates/tools/src/snap.rs+++ b/crates/tools/src/snap.rs@@@ -374,24 -372,17 +374,28 @@@ fn format_angle(deg: f64) -> Stringif nearest.is_finite() && (deg - nearest).abs() < 1e-6 { format!("{nearest:.0}") } else { format!("{deg:.1}") }}+ /// The baseline grid comes last: its lines are dense and it snaps while hidden, so ahead of-/// smart guides it would take nearly every vertical move and draw nothing (#188).++/// smart guides it would take nearly every vertical move and draw nothing (#188). Only when a++/// guide or margin is in reach does the nearer of it and the baseline grid win.fn first_on_axis(cx: &ToolContext, req: &SnapRequest<'_>, axis: Axis, tol: f64) -> Option<AxisHit> {pass_grid(cx, req, axis, tol)- .or_else(|| nearer(pass_baseline(cx, req, axis, tol), pass_guides(cx, req, axis, tol)))- .or_else(|| pass_guides(cx, req, axis, tol))++ .or_else(|| pass_guides(cx, req, axis, tol).and_then(|g| nearer(pass_baseline(cx, req, axis, tol), Some(g)))).or_else(|| pass_align(cx, req, axis, tol)).or_else(|| pass_spacing(cx, req, axis, tol)).or_else(|| pass_dimensions(cx, req, axis, tol))+ .or_else(|| pass_baseline(cx, req, axis, tol))}+/// The baseline grid and the guides (ruler guides, margins, columns) compete by distance, so a+/// margin is reachable between the lines of a fine baseline grid at any zoom. A tie goes to the+/// guide.+fn nearer(baseline: Option<AxisHit>, guide: Option<AxisHit>) -> Option<AxisHit> {+ match (baseline, guide) {+ (Some(b), Some(g)) => Some(if b.delta.abs() < g.delta.abs() { b } else { g }),+ (b, g) => g.or(b),+ }+}+/// Document grid. No overlay.////// The interval is the major spacing divided by the subdivision count. A count below 1 counts