mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 14:27:34 +00:00
merge-fwh: pen: PenTool::deletes, Delete and Backspace left to the app for a draft the selected tool does not own (a864229579)
This commit is contained in:
@@ -17,7 +17,8 @@ const CONVERT_TIP: Vec2 = Vec2::new(ICON_BOX / 2.0, 5.5);
|
||||
/// overlay does nothing, so it never starts a path.
|
||||
///
|
||||
/// - The open pen draft ([`draft`](Self::draft)), when the host passes it, is drawn and keeps its keys (Enter,
|
||||
/// Escape, Delete) as [`PathMode`](super::PathMode) describes; it takes no press.
|
||||
/// Escape, and Delete unless [`PenTool::deletes`] leaves it to the app) as [`PathMode`](super::PathMode)
|
||||
/// describes; it takes no press.
|
||||
/// - Cursor off the overlay's parts: the crosshair under the canvas's precise cursor
|
||||
/// ([`CanvasSpace::precise`](craft_ui::canvas::CanvasSpace::precise)); with ⌘ Direct Selection's arrow; else Add
|
||||
/// Anchor the arrow (a click there adds nothing; with ⌥, Delete Anchor, the pen with "-"), Delete Anchor the pen
|
||||
|
||||
@@ -132,8 +132,8 @@ struct Run {
|
||||
/// [`PenEvent::Resumed`].
|
||||
/// - Keys while a draft is open: Enter and Escape end it open and keep it (a draft of one anchor is discarded, as no
|
||||
/// path has fewer than two anchors); Backspace and Delete remove the last anchor, the only one discarding the
|
||||
/// draft; the host's Undo does the same through [`remove_last`](Self::remove_last). Each ending is
|
||||
/// [`PenEvent::Finished`].
|
||||
/// draft, unless the host gives them to another tool ([`deletes`](Self::deletes)); the host's Undo does the same
|
||||
/// through [`remove_last`](Self::remove_last). Each ending is [`PenEvent::Finished`].
|
||||
/// - Look: the path so far, a dashed rubber band from the last anchor to where a click would land (with Path
|
||||
/// Options' Rubber Band), the last anchor's handles, the anchors with the last one filled, and over the first
|
||||
/// anchor the close cue.
|
||||
@@ -156,6 +156,7 @@ struct Run {
|
||||
pub struct PenTool {
|
||||
pub(super) mode: PenMode,
|
||||
pub(super) sensing: bool,
|
||||
deletes: bool,
|
||||
pub(super) auto_add_delete: bool,
|
||||
options: PathOptionsSettings,
|
||||
pub(super) ends: Vec<(u64, KnotRef, Point)>,
|
||||
@@ -186,6 +187,7 @@ impl PenTool {
|
||||
Self {
|
||||
mode: PenMode::default(),
|
||||
sensing: true,
|
||||
deletes: true,
|
||||
auto_add_delete: false,
|
||||
options: PathOptionsSettings::default(),
|
||||
ends: Vec::new(),
|
||||
@@ -268,6 +270,13 @@ impl PenTool {
|
||||
self
|
||||
}
|
||||
|
||||
/// Whether Backspace and Delete remove the draft's last anchor; true by default. False leaves them to the app, for
|
||||
/// a draft whose anchors are not the selected tool's to take back (a refused draft kept after a tool switch).
|
||||
pub fn deletes(&mut self, on: bool) -> &mut Self {
|
||||
self.deletes = on;
|
||||
self
|
||||
}
|
||||
|
||||
/// The Pen's Auto Add/Delete on the open draft; false by default. No effect in Curvature mode.
|
||||
pub fn auto_add_delete(&mut self, on: bool) -> &mut Self {
|
||||
self.auto_add_delete = on;
|
||||
@@ -617,7 +626,7 @@ impl CanvasTool for PenTool {
|
||||
self.end(CancelReason::Escape, PenEnd::Escape);
|
||||
true
|
||||
}
|
||||
ToolKey::Delete { .. } => {
|
||||
ToolKey::Delete { .. } if self.deletes => {
|
||||
self.remove_last_anchor(CancelReason::UndoDuringGesture);
|
||||
true
|
||||
}
|
||||
@@ -626,7 +635,7 @@ impl CanvasTool for PenTool {
|
||||
}
|
||||
|
||||
fn claims(&self) -> ToolClaims {
|
||||
if !self.shown.knots.is_empty() && self.drag.is_none() { ToolClaims::NONE.deletes() } else { ToolClaims::NONE }
|
||||
if self.deletes && !self.shown.knots.is_empty() && self.drag.is_none() { ToolClaims::NONE.deletes() } else { ToolClaims::NONE }
|
||||
}
|
||||
|
||||
fn takes(&self, button: PointerButton, mods: Mods) -> bool {
|
||||
|
||||
@@ -173,6 +173,20 @@ fn remove_last_waits_for_a_press_that_is_still_down() {
|
||||
assert_eq!(pen.draft().knots.len(), 3, "one request removes one anchor");
|
||||
}
|
||||
|
||||
// Delete takes back the draft's last anchor; with `deletes` off (the anchors are not the selected tool's to take back)
|
||||
// the key is left to the app and the draft stays.
|
||||
#[trial]
|
||||
fn delete_removes_the_last_anchor_unless_the_host_keeps_the_key() {
|
||||
let mut pen = Pen::three();
|
||||
pen.fixture.fixture().key(egui::Key::Delete, Modifiers::NONE);
|
||||
pen.sync();
|
||||
assert_eq!(pen.draft().knots.len(), 2);
|
||||
pen.fixture.tool_mut().deletes(false);
|
||||
pen.fixture.fixture().key(egui::Key::Delete, Modifiers::NONE);
|
||||
pen.sync();
|
||||
assert_eq!(pen.draft().knots.len(), 2, "the key is the app's");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_quick_drag_in_one_frame_pulls_the_handles() {
|
||||
let mut pen = pen();
|
||||
|
||||
Reference in New Issue
Block a user