mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Show the Freeform Pen nib over the canvas
Use the Freeform Pen icon for ordinary hover and switch to the crosshair for Caps Lock or Precise Other Cursors. Keep the existing Continue badge on selected path ends. Signed-off-by: Deepak Jain <[email protected]>
This commit is contained in:
2 files changed
+42
-2
No files matched your search
@@ -278,11 +278,17 @@ impl CanvasTool for FreeformPenTool {
|
||||
}
|
||||
|
||||
fn cursor(&self, cx: &ToolContext<'_>) -> Cursor {
|
||||
if cx.precise() {
|
||||
return Cursor::Painted(PaintedCursor::Crosshair);
|
||||
}
|
||||
if cx.pointer.as_ref().and_then(|pointer| self.end_at(pointer, cx)).is_some_and(|end| end.selected) {
|
||||
// The nib is at the lower left of the same 24-point icon box the Pen uses.
|
||||
return Cursor::Painted(PaintedCursor::tool(crate::icons::tool_icon(Tool::FreeformPen), Vec2::Y * 24.0, Some(CursorBadge::Continue)));
|
||||
}
|
||||
Cursor::System(CursorIcon::Default)
|
||||
if cx.pointer.is_none() || cx.mods.alt || cx.mods.cmd {
|
||||
return Cursor::System(CursorIcon::Default);
|
||||
}
|
||||
const FREEFORM_NIB: Vec2 = Vec2::new(3.0, 5.0);
|
||||
Cursor::Painted(PaintedCursor::tool(crate::icons::tool_icon(Tool::FreeformPen), FREEFORM_NIB, None))
|
||||
}
|
||||
|
||||
fn command_form(&self) -> ToolPath {
|
||||
@@ -297,3 +303,7 @@ mod freeform_pen_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "freeform_continue_endpoint_tests.rs"]
|
||||
mod freeform_continue_endpoint_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "freeform_cursor_tests.rs"]
|
||||
mod freeform_cursor_tests;
|
||||
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
|
||||
fn canvas_cursor(app: &mut Harness<'static, Box<PhotocraftApp>>) -> Option<Cursor> {
|
||||
hover(app, 100.0, 150.0, Modifiers::NONE);
|
||||
app.state().canvas_tools.last_response.as_ref()?.cursor.clone()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn freeform_hover_switches_between_its_nib_and_the_precise_crosshair() {
|
||||
let mut app = harness(Tool::FreeformPen);
|
||||
let nib = Some(Cursor::Painted(PaintedCursor::tool(crate::icons::tool_icon(Tool::FreeformPen), egui::vec2(3.0, 5.0), None)));
|
||||
let crosshair = Some(Cursor::Painted(PaintedCursor::Crosshair));
|
||||
assert_eq!(canvas_cursor(&mut app), nib);
|
||||
|
||||
WindowHost::of(&app.ctx).set_caps_lock(Some(true));
|
||||
assert_eq!(canvas_cursor(&mut app), crosshair);
|
||||
WindowHost::of(&app.ctx).set_caps_lock(Some(false));
|
||||
assert_eq!(canvas_cursor(&mut app), nib);
|
||||
|
||||
app.state_mut().run("prefs.set", json!({"path": "cursors.other", "value": "precise"})).unwrap();
|
||||
assert_eq!(canvas_cursor(&mut app), crosshair);
|
||||
}
|
||||
Reference in new issue
Block a user