mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-12 11:13:24 +00:00
Merge main into feat/scripts-folder
This commit is contained in:
@@ -89,6 +89,37 @@ fn a_pen_anchor_lines_up_with_another_objects_centre() {
|
||||
assert!((pts[2] - Point::new(100.0, 381.0)).hypot() < 1e-9, "{pts:?}");
|
||||
}
|
||||
|
||||
/// View › Pixel Preview turns Smart Guides off in the tools: a moved square no longer lines up with
|
||||
/// the other square's top and shows no guide, and a Rectangle tool corner no longer lands on its
|
||||
/// anchor.
|
||||
#[test]
|
||||
fn pixel_preview_turns_smart_guides_off() {
|
||||
for pixel in [false, true] {
|
||||
let view = ViewInfo { pixel_preview: pixel, ..ViewInfo::default() };
|
||||
let mut s = session();
|
||||
let b = s.execute("shape.rectangle", &json!({"x": 400, "y": 300, "width": 50, "height": 50})).unwrap()["id"].as_u64().unwrap();
|
||||
s.select_tool("selection", view).unwrap();
|
||||
s.execute("select.set", &json!({"ids": [b]})).unwrap();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Down, 425.0, 325.0), view).unwrap();
|
||||
for y in [300.0, 250.0, 200.0, 150.0, 128.0] {
|
||||
s.pointer(&PointerEvent::new(PointerKind::Drag, 425.0, y), view).unwrap();
|
||||
}
|
||||
let guides = s.overlays(view).into_iter().filter(|o| matches!(o, Overlay::Line { .. } | Overlay::Label { .. })).count();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Up, 425.0, 128.0), view).unwrap();
|
||||
let top = s.doc().unwrap().doc.node(NodeId(b)).unwrap().geometric_bounds().unwrap().y0;
|
||||
assert_eq!((top, guides > 0), if pixel { (103.0, false) } else { (100.0, true) }, "Pixel Preview {pixel}");
|
||||
|
||||
s.select_tool("rectangle", view).unwrap();
|
||||
for (kind, x, y) in
|
||||
[(PointerKind::Down, 302.0, 297.0), (PointerKind::Drag, 250.0, 250.0), (PointerKind::Drag, 202.0, 203.0), (PointerKind::Up, 202.0, 203.0)]
|
||||
{
|
||||
s.pointer(&PointerEvent::new(kind, x, y), view).unwrap();
|
||||
}
|
||||
let r = made(&s);
|
||||
assert_eq!((r.x0, r.y0), if pixel { (202.0, 203.0) } else { (200.0, 200.0) }, "Pixel Preview {pixel}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Preferences › Smart Guides › Construction Guides: on (the default), a Pen anchor near the
|
||||
/// 45° guide through the last one lands on it; off, it stays where it was clicked.
|
||||
#[test]
|
||||
|
||||
@@ -22,6 +22,8 @@ pub struct ViewInfo {
|
||||
/// View → Show Guides: the ruler guides show (and, unlocked, can be picked).
|
||||
pub guides: bool,
|
||||
pub snap_to_grid: bool,
|
||||
/// View → Pixel Preview: while it is on, the tools use no Smart Guides.
|
||||
pub pixel_preview: bool,
|
||||
pub show_bbox: bool,
|
||||
/// View → Snap to Pixel: drawing and moving land on whole pixels (points at 72 ppi).
|
||||
pub snap_to_pixel: bool,
|
||||
@@ -46,6 +48,7 @@ impl Default for ViewInfo {
|
||||
smart_guides: true,
|
||||
guides: true,
|
||||
snap_to_grid: false,
|
||||
pixel_preview: false,
|
||||
show_bbox: true,
|
||||
snap_to_pixel: false,
|
||||
snap_to_point: true,
|
||||
@@ -335,6 +338,7 @@ impl Session {
|
||||
{
|
||||
let Some(st) = self.active.and_then(|i| self.docs.get(i)) else { return R::default() };
|
||||
let (unit, stroke_unit) = (self.general_unit(), self.stroke_unit());
|
||||
let smart_guides = view.smart_guides && !view.pixel_preview;
|
||||
let cx = ToolContext {
|
||||
doc: &st.doc,
|
||||
ruler_origin: st.doc.ruler_origin_for(view.artboard),
|
||||
@@ -344,7 +348,7 @@ impl Session {
|
||||
isolation: st.isolation,
|
||||
paint: &self.paint,
|
||||
outline: view.outline,
|
||||
smart_guides: view.smart_guides,
|
||||
smart_guides,
|
||||
guides: view.guides && !self.menu.guides_locked,
|
||||
snap_to_grid: view.snap_to_grid,
|
||||
show_bbox: view.show_bbox,
|
||||
@@ -354,7 +358,7 @@ impl Session {
|
||||
snap_to_point: view.snap_to_point,
|
||||
snap_tangent: self.prefs.snap_tangent,
|
||||
snap_perpendicular: self.prefs.snap_perpendicular,
|
||||
snap_to_glyph: view.snap_to_glyph && view.smart_guides && !view.snap_to_grid,
|
||||
snap_to_glyph: view.snap_to_glyph && smart_guides && !view.snap_to_grid,
|
||||
glyph_snap: self.prefs.glyph_snap,
|
||||
corner_widgets: view.corner_widgets,
|
||||
fill_active: self.fill_active,
|
||||
|
||||
Reference in New Issue
Block a user