mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge #16251 into the merge queue batch
Magic Eraser: its own icon cursor
This commit is contained in:
commit
bb45da908d
2 files changed
+58
-3
No files matched your search
@@ -50,17 +50,22 @@ pub(crate) fn sample_target() -> Cursor {
|
||||
|
||||
/// The pointer of a painting tool that acts on a click and has no brush tip: the Paint Bucket's
|
||||
/// arrow with the bucket below right of it, the hotspot on the arrow's tip, so a click fills the
|
||||
/// pixel under the tip (#12539), and the Magic Eraser's crosshair. Precise Other Cursors (or Caps
|
||||
/// Lock, `precise`) gives the Paint Bucket the crosshair too (#3968). `None` for a tool that
|
||||
/// strokes with the brush.
|
||||
/// pixel under the tip (#12539), and the Magic Eraser's own icon with the hotspot on the eraser's
|
||||
/// end at the lower left (#12001). Precise Other Cursors (or Caps Lock, `precise`) gives both the
|
||||
/// crosshair (#3968). `None` for a tool that strokes with the brush.
|
||||
pub(crate) fn click_tool_cursor(tool: Tool, precise: bool) -> Option<Cursor> {
|
||||
match tool {
|
||||
Tool::PaintBucket if !precise => Some(Cursor::Painted(PaintedCursor::pointer_tool(PointerGlyph::Arrow, crate::icons::tool_icon(tool)))),
|
||||
Tool::MagicEraser if !precise => Some(Cursor::Painted(PaintedCursor::tool(crate::icons::tool_icon(tool), MAGIC_ERASER_HOTSPOT, None))),
|
||||
Tool::PaintBucket | Tool::MagicEraser => Some(Cursor::Painted(PaintedCursor::Crosshair)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The Magic Eraser icon's point that sits on the pointer, in its 24-unit box: the middle of the eraser's end, which
|
||||
/// lies at the lower left of the `eraser_magic` glyph (#12001).
|
||||
pub(crate) const MAGIC_ERASER_HOTSPOT: egui::Vec2 = egui::vec2(4.6, 18.4);
|
||||
|
||||
/// Path Selection's own pointer (#13295): the light arrow, and the solid one with ⌥ (without ⌘)
|
||||
/// where a press would land on a component (`path_components::over_component`). ⌘ keeps the light
|
||||
/// one; Precise Other Cursors (or Caps Lock, `precise`) the crosshair. `mods` and `at` are the
|
||||
@@ -161,3 +166,7 @@ mod triangle_alt_eyedropper_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "custom_shape_alt_eyedropper_tests.rs"]
|
||||
mod custom_shape_alt_eyedropper_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "magic_eraser_cursor_tests.rs"]
|
||||
mod magic_eraser_cursor_tests;
|
||||
@@ -0,0 +1,46 @@
|
||||
//! #12001: the Magic Eraser's cursor is its own toolbar icon with the hotspot on the eraser's end at the lower left,
|
||||
//! also with Shift held; Precise Other Cursors and Caps Lock give the crosshair. Driven through real egui input on
|
||||
//! the real canvas; the assertions read the cursor the tool asked the tool host for.
|
||||
|
||||
use craft::behavior::{Cursor, PaintedCursor};
|
||||
use craft::ui::runtime::windows::WindowHost;
|
||||
use egui::Modifiers;
|
||||
use egui_kittest::Harness;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::guide_cursor_tests::{harness, hover};
|
||||
use crate::state::Tool;
|
||||
|
||||
/// A point away from the harness's guide at x = 200.
|
||||
const AT: [f32; 2] = [100.0, 150.0];
|
||||
|
||||
fn cursor_with(h: &mut Harness<'static, Box<PhotocraftApp>>, mods: Modifiers) -> Option<Cursor> {
|
||||
hover(h, AT[0], AT[1], mods);
|
||||
h.state().canvas_tools.last_response.as_ref().and_then(|r| r.cursor.clone())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_standard_cursor_is_the_magic_eraser_icon_with_its_tip_at_the_lower_left() {
|
||||
let mut h = harness(Tool::MagicEraser);
|
||||
let Some(Cursor::Painted(PaintedCursor::Tool { icon, hotspot, badge, .. })) = cursor_with(&mut h, Modifiers::NONE) else {
|
||||
panic!("an icon cursor, not the crosshair");
|
||||
};
|
||||
assert_eq!(icon, crate::icons::tool_icon(Tool::MagicEraser), "the toolbar's own icon");
|
||||
// The eraser end of the glyph, at the lower left of its 24-unit box: pinned by value so a moved constant fails.
|
||||
assert_eq!(hotspot, egui::vec2(4.6, 18.4), "the eraser tip");
|
||||
assert!(badge.is_none());
|
||||
assert_eq!(cursor_with(&mut h, Modifiers::SHIFT), cursor_with(&mut h, Modifiers::NONE), "Shift keeps it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn precise_other_cursors_and_caps_lock_give_the_crosshair() {
|
||||
let mut h = harness(Tool::MagicEraser);
|
||||
let crosshair = Some(Cursor::Painted(PaintedCursor::Crosshair));
|
||||
h.state_mut().run("prefs.set", json!({"path": "cursors.other", "value": "precise"})).unwrap();
|
||||
assert_eq!(cursor_with(&mut h, Modifiers::NONE), crosshair, "Precise: the crosshair");
|
||||
h.state_mut().run("prefs.set", json!({"path": "cursors.other", "value": "standard"})).unwrap();
|
||||
assert_ne!(cursor_with(&mut h, Modifiers::NONE), crosshair, "Standard again: the icon");
|
||||
WindowHost::of(&h.ctx).set_caps_lock(Some(true));
|
||||
assert_eq!(cursor_with(&mut h, Modifiers::NONE), crosshair, "Caps Lock: the crosshair");
|
||||
}
|
||||
Reference in new issue
Block a user