mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Merge pull request #10251 from storytold/fix/vectorcraft-0251-outline-and-selection
Restore Outline and Selection tool feedback and keep large PDF imports responsive
This commit is contained in:
10 files changed
+106
-28
No files matched your search
@@ -235,7 +235,7 @@ fn shift_click_direct_selection_and_hover_on_a_drop_shadow_pass_through_it() {
|
||||
run(&mut s, "select.set", json!({"ids": [a.0]}));
|
||||
let v = ViewInfo::default();
|
||||
s.select_tool("selection", v).unwrap();
|
||||
assert_eq!(s.cursor(Point::new(50.0, 50.0), Mods::default(), v), Cursor::Move);
|
||||
assert_eq!(s.cursor(Point::new(50.0, 50.0), Mods::default(), v), Cursor::SelectionMove);
|
||||
assert_eq!(s.cursor(Point::new(110.0, 50.0), Mods::default(), v), Cursor::Arrow);
|
||||
assert_eq!(s.cursor(Point::new(92.0, 50.0), Mods::default(), v), Cursor::Arrow);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ pub enum Cursor {
|
||||
GroupSelection,
|
||||
/// Alt-dragging a copy with the Selection or Direct Selection tool: a double arrowhead.
|
||||
SelectionCopy,
|
||||
/// The Selection arrow over movable artwork.
|
||||
SelectionMove,
|
||||
Move,
|
||||
Crosshair,
|
||||
ResizeH,
|
||||
|
||||
@@ -129,11 +129,20 @@ shown_when = [
|
||||
hotspot = "The arrow's tip."
|
||||
look = "Arrow with a small x badge (nothing to select)."
|
||||
|
||||
[[cursor]]
|
||||
id = "SelectionMove"
|
||||
group = "Selection"
|
||||
shown_when = [
|
||||
"The Selection tool over a selected object or its movable source artwork, or over its visible centre point without Cmd/Ctrl held.",
|
||||
"The Selection tool over artwork while Alt is held, before the copy drag begins.",
|
||||
]
|
||||
hotspot = "The arrow's tip."
|
||||
look = "The Selection arrow with a small move badge."
|
||||
|
||||
[[cursor]]
|
||||
id = "Move"
|
||||
group = "Selection"
|
||||
shown_when = [
|
||||
"The Selection tool over a selected object, or over any object with Alt held (once an Alt-drag starts, SelectionCopy shows).",
|
||||
"The shape tools over a selected object's centre point (Attributes › Show Center), before a press there moves it (while the drag runs the arrow is plain, SelectionCopy with Alt, ArrowHollow while it snaps).",
|
||||
"Reshape over a path or while dragging.",
|
||||
"Inside the Free Transform and Crop Image boxes.",
|
||||
|
||||
@@ -1552,7 +1552,7 @@ impl Tool for SelectionTool {
|
||||
// take the pointer too (on a thin box the centre lies within a handle's reach), and with
|
||||
// Cmd/Ctrl held the press selects the object behind instead.
|
||||
if near_selected && !m.cmd && hit_center(cx, p, cx.point_tol()).is_some() {
|
||||
return Cursor::Move;
|
||||
return Cursor::SelectionMove;
|
||||
}
|
||||
// View → Snap to Point: over an anchor a press would grab the object by, the arrow turns
|
||||
// hollow.
|
||||
@@ -1560,11 +1560,11 @@ impl Tool for SelectionTool {
|
||||
return Cursor::ArrowHollow;
|
||||
}
|
||||
if selected_source_hit(cx, p).is_some() {
|
||||
return Cursor::Move;
|
||||
return Cursor::SelectionMove;
|
||||
}
|
||||
if let Some(h) = hit_test(cx.doc, p, cx.selection_hit_options()) {
|
||||
if selected_under(cx, &h, h.top_object(cx.isolation)).is_some() || m.alt {
|
||||
return Cursor::Move;
|
||||
return Cursor::SelectionMove;
|
||||
}
|
||||
return Cursor::Arrow;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ fn a_press_on_a_selected_shaper_source_moves_it_while_a_mask_is_edited() {
|
||||
let c = ToolContext { isolation: Some(layer), ..cx(&d, &s, &p) };
|
||||
for x in [75.0, 125.0] {
|
||||
let mut t = SelectionTool::default();
|
||||
assert_eq!(t.cursor(&c, Point::new(x, 350.0), Mods::default()), Cursor::Move, "at {x}");
|
||||
assert_eq!(t.cursor(&c, Point::new(x, 350.0), Mods::default()), Cursor::SelectionMove, "at {x}");
|
||||
let down = t.pointer(&c, &ev(PointerKind::Down, x, 350.0));
|
||||
assert!(!down.iter().any(|a| matches!(a, Action::Exec(c, _) if c == "select.set")), "at {x}: {down:?}");
|
||||
let drag = t.pointer(&c, &ev(PointerKind::Drag, x + 20.0, 350.0));
|
||||
@@ -45,7 +45,7 @@ fn a_selected_shaper_source_moves_after_other_objects_and_behind_front_art() {
|
||||
s.set([rect, ids[1]]);
|
||||
let c = ToolContext { isolation: Some(layer), ..cx(&d, &s, &p) };
|
||||
let mut t = SelectionTool::default();
|
||||
assert_eq!(t.cursor(&c, Point::new(125.0, 350.0), Mods::default()), Cursor::Move);
|
||||
assert_eq!(t.cursor(&c, Point::new(125.0, 350.0), Mods::default()), Cursor::SelectionMove);
|
||||
let down = t.pointer(&c, &ev(PointerKind::Down, 125.0, 350.0));
|
||||
assert!(!down.iter().any(|a| matches!(a, Action::Exec(c, _) if c == "select.set")), "{down:?}");
|
||||
let drag = t.pointer(&c, &ev(PointerKind::Drag, 145.0, 350.0));
|
||||
@@ -55,7 +55,7 @@ fn a_selected_shaper_source_moves_after_other_objects_and_behind_front_art() {
|
||||
d.insert(Some(layer), 2, Node::path(front, square, Appearance::default_art())).unwrap();
|
||||
s.set([ids[1]]);
|
||||
let c = ToolContext { isolation: Some(layer), ..cx(&d, &s, &p) };
|
||||
assert_ne!(SelectionTool::default().cursor(&c, Point::new(125.0, 350.0), Mods::default()), Cursor::Move);
|
||||
assert_ne!(SelectionTool::default().cursor(&c, Point::new(125.0, 350.0), Mods::default()), Cursor::SelectionMove);
|
||||
let down = SelectionTool::default().pointer(&c, &ev(PointerKind::Down, 125.0, 350.0));
|
||||
assert!(down.iter().any(|a| matches!(a, Action::Exec(c, v) if c == "select.set" && v["ids"] == json!([front.0]))), "{down:?}");
|
||||
}
|
||||
@@ -1042,7 +1042,7 @@ fn hidden_box_handles_take_no_press_while_anchors_are_selected() {
|
||||
s.anchors.entry(id).or_default().insert((0, 1));
|
||||
let c = cx(&d, &s, &p);
|
||||
let mut t = SelectionTool::default();
|
||||
assert_eq!(t.cursor(&c, top_middle, Mods::default()), Cursor::Move);
|
||||
assert_eq!(t.cursor(&c, top_middle, Mods::default()), Cursor::SelectionMove);
|
||||
let down = t.pointer(&c, &ev(PointerKind::Down, 150.0, 100.0));
|
||||
assert!(!down.contains(&Action::Begin("Scale".into())), "{down:?}");
|
||||
assert!(!crate::select::bbox_handle_at(&c, top_middle));
|
||||
@@ -3006,9 +3006,9 @@ fn a_press_on_the_centre_point_moves_an_unfilled_shape() {
|
||||
let c = ToolContext { path_only: true, ..cx(&d, &s, &p) };
|
||||
let centre = Point::new(150.0, 150.0);
|
||||
let mut t = SelectionTool::default();
|
||||
assert_eq!(t.cursor(&c, centre, Mods::default()), Cursor::Move);
|
||||
assert_eq!(t.cursor(&c, centre, Mods::default()), Cursor::SelectionMove);
|
||||
// Cmd/Ctrl selects the object behind, not the centre point, so the pointer says neither.
|
||||
assert_ne!(t.cursor(&c, centre, Mods { cmd: true, ..Mods::default() }), Cursor::Move);
|
||||
assert_ne!(t.cursor(&c, centre, Mods { cmd: true, ..Mods::default() }), Cursor::SelectionMove);
|
||||
assert!(t.pointer(&c, &ev(PointerKind::Down, centre.x, centre.y)).is_empty());
|
||||
let a = t.pointer(&c, &ev(PointerKind::Drag, 170.0, 160.0));
|
||||
assert_eq!(a.first(), Some(&Action::Begin("Move".into())), "{a:?}");
|
||||
@@ -3102,7 +3102,7 @@ fn a_ruler_guide_under_the_centre_point_keeps_the_pointer() {
|
||||
assert!(hit_center(&c, centre, c.point_tol()).is_some());
|
||||
let mut t = SelectionTool::default();
|
||||
let cursor = t.cursor(&c, centre, Mods::default());
|
||||
assert_ne!(cursor, Cursor::Move, "the guide's cursor, not the move arrow");
|
||||
assert_ne!(cursor, Cursor::SelectionMove, "the guide's cursor, not the move arrow");
|
||||
let down = t.pointer(&c, &ev(PointerKind::Down, centre.x, centre.y));
|
||||
let drag = t.pointer(&c, &ev(PointerKind::Drag, 170.0, 150.0));
|
||||
assert!(drag.iter().any(|a| matches!(a, Action::Preview(cmd, _) if cmd == "guide.move")), "the guide drags: {down:?} {drag:?}");
|
||||
@@ -3177,7 +3177,7 @@ fn a_press_on_a_selected_member_of_a_group_moves_the_selected_members() {
|
||||
s.set(picked.iter().copied());
|
||||
let c = cx(&d, &s, &p);
|
||||
let mut t = SelectionTool::default();
|
||||
assert_eq!(t.cursor(&c, Point::new(125.0, 125.0), Mods::default()), Cursor::Move, "{picked:?}");
|
||||
assert_eq!(t.cursor(&c, Point::new(125.0, 125.0), Mods::default()), Cursor::SelectionMove, "{picked:?}");
|
||||
let down = t.pointer(&c, &ev(PointerKind::Down, 125.0, 125.0));
|
||||
assert!(!is_select(&down), "{picked:?}: {down:?}");
|
||||
let drag = t.pointer(&c, &ev(PointerKind::Drag, 145.0, 125.0));
|
||||
@@ -3218,7 +3218,7 @@ fn a_press_on_a_selected_member_of_a_group_moves_the_selected_members() {
|
||||
s.anchors.insert(a, [(0, 0), (0, 1), (0, 2), (0, 3)].into_iter().collect());
|
||||
let c = cx(&d, &s, &p);
|
||||
let mut t = SelectionTool::default();
|
||||
assert_eq!(t.cursor(&c, Point::new(125.0, 125.0), Mods::default()), Cursor::Move, "every anchor");
|
||||
assert_eq!(t.cursor(&c, Point::new(125.0, 125.0), Mods::default()), Cursor::SelectionMove, "every anchor");
|
||||
let down = t.pointer(&c, &ev(PointerKind::Down, 125.0, 125.0));
|
||||
assert!(!is_select(&down), "every anchor: {down:?}");
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ pub(super) fn checker_of(setup: &vectorcraft_doc::DocSetup) -> Checker {
|
||||
}
|
||||
|
||||
/// The page frames of document `st` seen through `view`: one per artboard, named "01 - name" with the
|
||||
/// Artboard tool or several boards, filled with its paper or the transparency grid (nothing in Outline).
|
||||
/// Artboard tool or several boards, filled with its paper or the transparency grid (white in Outline).
|
||||
/// Empty while the artboards are hidden.
|
||||
pub(super) fn frames(app: &VectorcraftApp, st: &vectorcraft_engine::DocState, view: &View, outline: bool) -> Vec<PageFrame> {
|
||||
if !shows_artboards(app) {
|
||||
@@ -51,7 +51,7 @@ pub(super) fn frames(app: &VectorcraftApp, st: &vectorcraft_engine::DocState, vi
|
||||
frame = frame.name(format!("{:02} - {}", i + 1, ab.name));
|
||||
}
|
||||
if outline {
|
||||
frame
|
||||
frame.fill(DataColor::new(Color32::WHITE))
|
||||
} else if grid {
|
||||
frame.checker(checker_of(setup))
|
||||
} else {
|
||||
|
||||
@@ -47,13 +47,13 @@ fn shift_clicking_a_name_toggles_selection_and_a_plain_click_activates() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outline_has_a_white_canvas_line_edges_and_no_paper() {
|
||||
fn outline_has_white_artboards_on_a_white_canvas_with_line_edges() {
|
||||
let _view = crate::testing::DefaultProofView::new();
|
||||
let app = app_with(2);
|
||||
let st = app.session.active().unwrap();
|
||||
assert_eq!(pasteboard_color(&app, st, true), PasteboardColor::Custom(DataColor::new(Color32::WHITE)));
|
||||
assert_eq!(border(true), PageBorder::Line);
|
||||
assert!(frames_of(&app, true).iter().all(|f| f.fill.is_none()));
|
||||
assert!(frames_of(&app, true).iter().all(|f| f.fill == Some(PageFill::Color(DataColor::new(Color32::WHITE)))));
|
||||
assert_eq!(pasteboard_color(&app, st, false), PasteboardColor::Default);
|
||||
assert_eq!(border(false), PageBorder::DropShadow);
|
||||
assert!(frames_of(&app, false).iter().all(|f| f.fill.is_some()));
|
||||
|
||||
@@ -89,6 +89,7 @@ pub fn tool_cursor(c: Cursor) -> cb::Cursor {
|
||||
Cursor::DirectAnchorSelected => tool("cursor-direct-anchor-selected", TIP, None),
|
||||
Cursor::ReshapeSegment => tool("cursor-reshape-segment", TIP, None),
|
||||
Cursor::GroupSelection => badged(CursorBadge::Add),
|
||||
Cursor::SelectionMove => badged(CursorBadge::Move),
|
||||
Cursor::SelectionCopy => badged(CursorBadge::Copy),
|
||||
Cursor::Move => system(CursorIcon::Move),
|
||||
Cursor::Crosshair => PaintedCursor::Crosshair.into(),
|
||||
@@ -195,7 +196,7 @@ pub(crate) fn request_busy(app: &crate::VectorcraftApp, ctx: &egui::Context) {
|
||||
|
||||
/// Every cursor with a look: its own, or the one it borrows.
|
||||
#[cfg(test)]
|
||||
const GLYPHS: [Cursor; 99] = [
|
||||
const GLYPHS: [Cursor; 100] = [
|
||||
Cursor::Hand,
|
||||
Cursor::HandGrab,
|
||||
Cursor::ZoomIn,
|
||||
@@ -207,6 +208,7 @@ const GLYPHS: [Cursor; 99] = [
|
||||
Cursor::ReshapeSegment,
|
||||
Cursor::GroupSelection,
|
||||
Cursor::SelectionCopy,
|
||||
Cursor::SelectionMove,
|
||||
Cursor::Move,
|
||||
Cursor::Crosshair,
|
||||
Cursor::ResizeH,
|
||||
|
||||
@@ -114,11 +114,19 @@ pub(super) fn render_preview(
|
||||
app: &mut VectorcraftApp,
|
||||
ctx: &egui::Context,
|
||||
doc: &vectorcraft_engine::doc::Document,
|
||||
) -> Option<Arc<egui::ColorImage>> {
|
||||
render_page_preview(&mut app.canvas.renderer, ctx.pixels_per_point(), doc)
|
||||
}
|
||||
|
||||
fn render_page_preview(
|
||||
renderer: &mut vectorcraft_render::Renderer,
|
||||
pixels_per_point: f32,
|
||||
doc: &vectorcraft_engine::doc::Document,
|
||||
) -> Option<Arc<egui::ColorImage>> {
|
||||
let region = doc.artboards.first()?.rect;
|
||||
let px = PREVIEW_PX * ctx.pixels_per_point() as f64;
|
||||
let px = PREVIEW_PX * pixels_per_point as f64;
|
||||
let scale = px / region.width().max(region.height()).max(1.0);
|
||||
let img = app.canvas.renderer.render_region(doc, region, scale, true);
|
||||
let img = renderer.render_region(doc, region, scale, true);
|
||||
Some(Arc::new(crate::canvas::color_image(&img)))
|
||||
}
|
||||
|
||||
@@ -286,6 +294,8 @@ pub(super) struct ImportPdfDialog {
|
||||
/// The preview shown for a (page, crop, text) revision; `None` for a page that could not be read, which is
|
||||
/// not asked for again.
|
||||
preview: Option<(Revision, Option<Arc<egui::ColorImage>>)>,
|
||||
/// One preview at a time. Page changes coalesce while the worker finishes.
|
||||
pending_preview: Option<(Revision, std::sync::mpsc::Receiver<Option<Arc<egui::ColorImage>>>)>,
|
||||
/// Why the last password did not open the file.
|
||||
password_error: Option<String>,
|
||||
/// The OK the pump has not answered.
|
||||
@@ -294,7 +304,7 @@ pub(super) struct ImportPdfDialog {
|
||||
|
||||
impl ImportPdfDialog {
|
||||
fn new(s: State) -> Self {
|
||||
ImportPdfDialog { id: dialog_id(KIND), s, preview: None, password_error: None, held: HeldAnswer::new() }
|
||||
ImportPdfDialog { id: dialog_id(KIND), s, preview: None, pending_preview: None, password_error: None, held: HeldAnswer::new() }
|
||||
}
|
||||
|
||||
/// The preview to render next: the revision of the shown page, crop and text, when the stored one differs.
|
||||
@@ -700,7 +710,14 @@ fn confirm(app: &mut VectorcraftApp, s: &State) -> Result<(), String> {
|
||||
if s.links_on() {
|
||||
p["linkPages"] = json!(true);
|
||||
}
|
||||
io::open_document(app, &s.name, &s.file.bytes, s.path.clone(), &p).map(|_| ())
|
||||
if crate::opening::available()
|
||||
&& let Some(path) = s.path.as_deref()
|
||||
{
|
||||
crate::opening::start_with(app, path, s.file.bytes.clone(), p);
|
||||
Ok(())
|
||||
} else {
|
||||
io::open_document(app, &s.name, &s.file.bytes, s.path.clone(), &p).map(|_| ())
|
||||
}
|
||||
};
|
||||
// Asked only for the password, the dialog showed no Text choice to keep; the choice for a `.ai`
|
||||
// or `.ait` file is not kept for PDFs.
|
||||
@@ -711,10 +728,10 @@ fn confirm(app: &mut VectorcraftApp, s: &State) -> Result<(), String> {
|
||||
}
|
||||
|
||||
/// The preview of the page and boxes `s` shows; `None` for a page that can't be read.
|
||||
fn preview_image(app: &mut VectorcraftApp, ctx: &egui::Context, s: &State) -> Option<Arc<egui::ColorImage>> {
|
||||
fn preview_image(renderer: &mut vectorcraft_render::Renderer, pixels_per_point: f32, s: &State) -> Option<Arc<egui::ColorImage>> {
|
||||
let opts = fileio::LoadOptions { crop: s.crop, password: s.password(), text_as: s.preview_text_as(), ..Default::default() };
|
||||
let (doc, _) = fileio::page_document(&s.file.bytes, s.page().saturating_sub(1), &opts).ok()?;
|
||||
render_preview(app, ctx, &doc)
|
||||
render_page_preview(renderer, pixels_per_point, &doc)
|
||||
}
|
||||
|
||||
/// The host pump: judges the OK the dialog holds (opening or placing the file; a refusal keeps the dialog open with
|
||||
@@ -730,10 +747,44 @@ pub(crate) fn pump(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
dialog.answer_ok(answer);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
let wanted = dialogs.with(|host| host.get::<ImportPdfDialog>().and_then(|d| Some((d.wanted_preview()?, d.s.clone()))));
|
||||
if let Some((revision, s)) = wanted {
|
||||
let image = preview_image(app, ctx, &s);
|
||||
let wanted = dialogs.with(|host| {
|
||||
let dialog = host.get_mut::<ImportPdfDialog>()?;
|
||||
if let Some((revision, pending)) = &dialog.pending_preview {
|
||||
let image = match pending.try_recv() {
|
||||
Ok(image) => image,
|
||||
Err(std::sync::mpsc::TryRecvError::Disconnected) => None,
|
||||
Err(std::sync::mpsc::TryRecvError::Empty) => return None,
|
||||
};
|
||||
if dialog.wanted_preview() == Some(*revision) {
|
||||
dialog.set_preview(*revision, image);
|
||||
}
|
||||
dialog.pending_preview = None;
|
||||
}
|
||||
Some((dialog.wanted_preview()?, dialog.s.clone()))
|
||||
});
|
||||
let Some((revision, state)) = wanted else { return };
|
||||
let pixels_per_point = ctx.pixels_per_point();
|
||||
if crate::opening::available() {
|
||||
let (sender, pending) = std::sync::mpsc::channel();
|
||||
dialogs.with(|host| {
|
||||
if let Some(dialog) = host.get_mut::<ImportPdfDialog>() {
|
||||
dialog.pending_preview = Some((revision, pending));
|
||||
}
|
||||
});
|
||||
let wake = ctx.clone();
|
||||
let scope = vectorcraft_engine::file_access::ScopeHandle::capture();
|
||||
app.jobs().spawn(
|
||||
"vectorcraft-pdf-preview",
|
||||
Box::new(move || {
|
||||
let image = scope.run(|| preview_image(&mut vectorcraft_render::Renderer::new(), pixels_per_point, &state));
|
||||
let _ = sender.send(image);
|
||||
wake.request_repaint();
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
let image = preview_image(&mut app.canvas.renderer, pixels_per_point, &state);
|
||||
dialogs.with(|host| {
|
||||
if let Some(dialog) = host.get_mut::<ImportPdfDialog>() {
|
||||
dialog.set_preview(revision, image);
|
||||
|
||||
@@ -117,6 +117,20 @@ fn pdf_page_footer_ok_opens_the_chosen_range() {
|
||||
assert_eq!(artboard_widths(h.state()), [200.0, 300.0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn confirming_a_desktop_pdf_import_queues_the_read_and_closes_the_dialog() {
|
||||
crate::opening::tests::with_threads(|| {
|
||||
let mut app = app();
|
||||
io::open_bytes(&mut app, "three.pdf", &three_pages(), Some("three.pdf".into())).unwrap();
|
||||
set(&mut app, "allPages", json!(false));
|
||||
set(&mut app, "range", json!("2-3"));
|
||||
confirm(&mut app).unwrap();
|
||||
assert!(!is_open(&app));
|
||||
assert_eq!(app.opening.pending.len(), 1);
|
||||
assert_eq!(app.opening.pending[0].path, "three.pdf");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opening_a_multi_page_pdf_asks_for_the_pages() {
|
||||
let mut app = app();
|
||||
|
||||
Reference in new issue
Block a user