Merge pull request #10406 from Lcoding15/fix/caps-lock-dialog-eyedroppers

Eyedroppers: one cursor over the image, and caps lock's precise crosshair (#9836)
This commit is contained in:
Tanish Manku authored and GitHub committed 2026-11-11 00:16:56 -07:00
commit 20ca0dd498
3 files changed
+174 -3

No files matched your search

+31 -3
View File
@@ -798,6 +798,10 @@ fn pattern_fill_canvas_drag(app: &mut PhotocraftApp, input: &DialogCanvasInput<'
owns
}
/// Pointer input on the image while a dialog or panel owns it, before the tools see it: an armed
/// eyedropper (a colour picker's, Curves, Replace Color, Color Range), Select and Mask's Refine
/// Edge Brush, Field Blur's pins, a Layer Style shadow drag, a ⌘/Ctrl-click adding a Curves point,
/// and the zoom and pan that stay available throughout. It also sets the cursor these show.
fn handle_dialog_canvas_input(app: &mut PhotocraftApp, input: DialogCanvasInput<'_>) {
let sticky_alt = app.ui.shell.sticky_alt;
let zoom_out = |alt: bool| match input.temporary {
@@ -924,7 +928,9 @@ fn handle_dialog_canvas_input(app: &mut PhotocraftApp, input: DialogCanvasInput<
input.ctx.set_cursor_icon(egui::CursorIcon::Move);
}
} else if picking && let Some(p) = crate::dialogs::free_pointer_over(input.ctx, input.rect) {
if app.session.prefs().cursors.other == photocraft_engine::prefs::OtherCursor::Precise {
// The dialogs' eyedroppers (Levels, Curves, a colour picker's) swap the pipette for the
// precise crosshair with caps lock too, as the Eyedropper tool does (#9836).
if precise_other_cursor(app) {
input.ctx.set_cursor_icon(egui::CursorIcon::Crosshair);
} else {
input.ctx.set_cursor_icon(pipette_cursor(input.ctx, p));
@@ -1590,6 +1596,9 @@ struct CanvasOverlayInput<'a> {
response: &'a egui::Response,
doc: &'a std::sync::Arc<Document>,
tool: Tool,
/// `tool` is lent by a held key or the middle button (the Hand, the Zoom, the Move with ⌘),
/// even when it is the selected tool too: it shows its own cursor.
lent: bool,
idx: usize,
output: Option<u32>,
border: photocraft_engine::prefs::CanvasBorder,
@@ -1694,7 +1703,20 @@ fn paint_primary_overlays(app: &mut PhotocraftApp, ui: &mut egui::Ui, view: &mut
draw_canvas_tool_cursor(app, ui, input, resizing);
}
/// Renders custom canvas cursor overlays, including brush silhouettes and type path placement directional arrows.
/// An eyedropper owns the image: a dialog's (Levels, Curves, Replace Color, a colour picker's)
/// or a Properties Levels/Curves one. It sets the cursor itself.
fn eyedropper_owns_image(app: &PhotocraftApp) -> bool {
crate::adjust_dialog::picker_armed(app)
|| crate::filter_dialog::color_eyedropper_armed(app)
|| crate::color_picker_ui::top(app).is_some()
|| crate::layer_picker::armed(app).is_some()
}
/// Set the cursor for the tool over the image, and paint the ones PhotoCraft draws itself (the
/// brush tip outline, the crosshair, a tool's own icon). The first case that applies wins: a pan
/// keeps the fist it set, an eyedropper that owns the image keeps the cursor it set, a stale
/// pointer position over another window paints nothing, then a guide under the pointer, then the
/// tool's own cursor.
fn draw_canvas_tool_cursor(app: &mut PhotocraftApp, ui: &mut egui::Ui, input: &CanvasOverlayInput<'_>, resizing: bool) {
let ctx = input.ctx;
let xf = input.xf;
@@ -1711,6 +1733,10 @@ fn draw_canvas_tool_cursor(app: &mut PhotocraftApp, ui: &mut egui::Ui, input: &C
});
if panning {
// The fist set with the pan above stays (#2196).
} else if !input.lent && eyedropper_owns_image(app) {
// The eyedropper set its own cursor; the tool's isn't drawn over it (#9836). A held
// Space or zoom key, or the middle button, still shows the tool it lends, even when
// that is the selected tool as well.
} else if crate::tool_cursor::pointer_elsewhere(ctx, &crate::panel_docking::native_viewports(app, ctx)) {
// The pointer is over a floating panel's own window; this window's last position of
// it is stale, so no tool cursor or brush outline is painted at it.
@@ -2121,7 +2147,8 @@ fn layer_picker_eyedropper(app: &mut PhotocraftApp, ui: &egui::Ui, ctx: &egui::C
if response.hovered()
&& let Some(p) = ui.input(|i| i.pointer.hover_pos())
{
if app.session.prefs().cursors.other == photocraft_engine::prefs::OtherCursor::Precise {
// Caps lock swaps the pipette and the precise crosshair, as everywhere (#9836).
if precise_other_cursor(app) {
ctx.set_cursor_icon(egui::CursorIcon::Crosshair);
} else {
ctx.set_cursor_icon(pipette_cursor(ctx, p));
@@ -2510,6 +2537,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
response: &response,
doc: &doc,
tool,
lent: temporary.is_some() || middle,
idx,
output,
border,
+35
View File
@@ -3386,3 +3386,38 @@ fn free_transform_redraws_only_the_moving_layer_when_the_box_opens_and_closes()
assert!(committed.contains(20, 20) && committed.contains(139, 49), "{committed:?}");
assert!(damage_since(&app, 0, (rev, key ^ dk), (rev + 2, 0), dk, (rev + 1, Some(moved))).is_none(), "a later revision isn't ours");
}
/// tanish2k09 on #10406: an armed eyedropper owns the image of the primary canvas only, the one
/// its picks come from and its pipette is drawn on. A secondary canvas (a Window › Arrange › New
/// Window view) is never left without a cursor for it.
#[test]
fn an_armed_eyedropper_hides_no_cursor_on_a_secondary_canvas() {
let ctx = egui::Context::default();
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
app.sync_views();
app.ui.tool = crate::state::Tool::Move;
let id = crate::adjust_dialog::open(&mut app, "image.adjustments.curves").unwrap();
let base = app.ui.dialog_mut(id).map(|d| crate::filter_dialog::params_of(&d.fields)).unwrap();
let dialog = app.ui.dialog_mut(id).unwrap();
dialog.fields.insert("__curvePicker".into(), json!("black"));
dialog.fields.insert("__curvePickerBase".into(), base);
assert!(crate::adjust_dialog::picker_armed(&app), "the black-point eyedropper is armed");
let view = app.ui.views[0].clone();
let rect = Rect::from_min_size(Pos2::ZERO, vec2(400.0, 300.0));
let cursor = |app: &mut PhotocraftApp, primary: bool| {
let mut icon = egui::CursorIcon::Default;
for _ in 0..3 {
let mut input = egui::RawInput::default();
input.events.push(egui::Event::PointerMoved(Pos2::new(200.0, 150.0)));
let mut out = ctx.run_ui(input, |ui| {
canvas_view(app, ui, 0, rect, view.clone(), primary);
});
out.textures_delta.clear();
icon = out.platform_output.cursor_icon;
}
icon
};
assert_eq!(cursor(&mut app, true), egui::CursorIcon::None, "the primary canvas hides the icon under the pipette it draws");
assert_ne!(cursor(&mut app, false), egui::CursorIcon::None, "a secondary canvas keeps a cursor");
}
+108
View File
@@ -186,3 +186,111 @@ fn caps_lock_swaps_the_other_cursors_between_their_icon_and_the_crosshair() {
assert_eq!(fp(&h), standard, "{tool:?}: releasing caps lock restores the icon");
}
}
/// #9836: an armed Levels or Curves eyedropper (and the dialogs' other pickers) shows its own
/// cursor alone, not with the tool's drawn over it, and takes caps lock's precise crosshair as
/// well, as in Photoshop, instead of only following the preference.
#[test]
fn caps_lock_gives_the_curves_eyedroppers_the_precise_crosshair() {
let mut h = capslock_harness();
// A tool whose own cursor ignores caps lock, so only the eyedropper can answer it.
h.state_mut().ui.tool = Tool::Move;
let id = crate::adjust_dialog::open(h.state_mut(), "image.adjustments.curves").unwrap();
let base = h.state_mut().ui.dialog_mut(id).map(|d| crate::filter_dialog::params_of(&d.fields)).unwrap();
let dialog = h.state_mut().ui.dialog_mut(id).unwrap();
dialog.fields.insert("__curvePicker".into(), json!("black"));
dialog.fields.insert("__curvePickerBase".into(), base);
assert!(crate::adjust_dialog::picker_armed(h.state()), "the black-point eyedropper is armed");
h.run_steps(3);
other(&mut h, "standard");
let standard = fp(&h);
assert_eq!(standard.icon, CursorIcon::None, "the drawn pipette, not the Move tool's arrow over it");
other(&mut h, "precise");
let precise = fp(&h);
assert_eq!(precise.icon, CursorIcon::Crosshair, "Precise: the crosshair");
// CodeRabbit on #10406: the pipette is painted, not only the icon hidden.
assert_ne!(standard.shapes, precise.shapes, "Standard paints a cursor of its own where Precise shows the crosshair");
assert_ne!(standard, precise, "Standard: the pipette");
other(&mut h, "standard");
caps(&mut h, true);
assert_eq!(fp(&h), precise, "caps lock turns the pipette into the precise crosshair");
other(&mut h, "precise");
assert_eq!(fp(&h), standard, "and the precise crosshair back into the pipette");
caps(&mut h, false);
assert_eq!(fp(&h), precise, "releasing caps lock restores the preference");
}
/// #9836: the same for a Properties Levels or Curves eyedropper (layer_picker.rs).
#[test]
fn caps_lock_gives_the_properties_eyedroppers_the_precise_crosshair() {
let mut h = capslock_harness();
h.state_mut().ui.tool = Tool::Move;
h.state_mut().run("layer.newAdjustmentLayer.curves", json!({})).unwrap();
let layer = h.state().session.active().unwrap().active_layer.unwrap();
h.state_mut().ui.layer_picker = Some(crate::layer_picker::LayerPicker { layer: layer.0, point: "black".into(), tool: Tool::Move });
assert!(crate::layer_picker::armed(h.state()).is_some(), "the Properties black-point eyedropper is armed");
h.run_steps(3);
other(&mut h, "standard");
let standard = fp(&h);
assert_eq!(standard.icon, CursorIcon::None, "the drawn pipette, not the Move tool's arrow over it");
other(&mut h, "precise");
let precise = fp(&h);
assert_eq!(precise.icon, CursorIcon::Crosshair, "Precise: the crosshair");
// CodeRabbit on #10406: the pipette is painted, not only the icon hidden.
assert_ne!(standard.shapes, precise.shapes, "Standard paints a cursor of its own where Precise shows the crosshair");
other(&mut h, "standard");
caps(&mut h, true);
assert_eq!(fp(&h), precise, "caps lock turns the pipette into the precise crosshair");
caps(&mut h, false);
assert_eq!(fp(&h), standard, "releasing caps lock restores the pipette");
}
/// #9836 review: the Color Picker's own eyedropper is the third dialog state that owns the image,
/// beside Levels/Curves and Properties, and it answers caps lock the same way.
#[test]
fn caps_lock_gives_the_color_pickers_eyedropper_the_precise_crosshair() {
let mut h = capslock_harness();
// A tool whose own cursor ignores caps lock, so only the eyedropper can answer it.
h.state_mut().ui.tool = Tool::Move;
crate::color_picker_ui::open(h.state_mut(), "foreground");
assert!(crate::color_picker_ui::top(h.state()).is_some(), "the Color Picker owns the image");
h.run_steps(3);
other(&mut h, "standard");
let standard = fp(&h);
assert_eq!(standard.icon, CursorIcon::None, "the drawn pipette, not the Move tool's arrow over it");
other(&mut h, "precise");
let precise = fp(&h);
assert_eq!(precise.icon, CursorIcon::Crosshair, "Precise: the crosshair");
// CodeRabbit on #10406: the pipette is painted, not only the icon hidden.
assert_ne!(standard.shapes, precise.shapes, "Standard paints a cursor of its own where Precise shows the crosshair");
assert_ne!(standard, precise);
other(&mut h, "standard");
caps(&mut h, true);
assert_eq!(fp(&h), precise, "caps lock turns the pipette into the precise crosshair");
other(&mut h, "precise");
assert_eq!(fp(&h), standard, "and the precise crosshair back into the pipette");
caps(&mut h, false);
assert_eq!(fp(&h), precise, "releasing caps lock restores the preference");
}
/// CodeRabbit on #10406: the middle button lends the Hand, and its cursor shows over an
/// eyedropper that owns the image even when the Hand is the selected tool as well.
#[test]
fn a_lent_hand_shows_its_cursor_over_an_eyedropper_when_it_is_also_selected() {
let mut h = capslock_harness();
h.state_mut().ui.tool = Tool::Hand;
crate::color_picker_ui::open(h.state_mut(), "foreground");
assert!(crate::color_picker_ui::top(h.state()).is_some(), "the Color Picker owns the image");
other(&mut h, "standard");
let pipette = fp(&h);
assert_eq!(pipette.icon, CursorIcon::None, "the eyedropper's drawn pipette");
let p = h.state().last_canvas_rect.center();
let middle = |pressed| egui::Event::PointerButton { pos: p, button: egui::PointerButton::Middle, pressed, modifiers: egui::Modifiers::NONE };
h.event(middle(true));
h.run_steps(2);
let lent = fp(&h);
h.event(middle(false));
h.run_steps(2);
assert_ne!(lent, pipette, "the Hand's cursor, not the pipette");
assert!(lent.icon == CursorIcon::Grab || lent.image.is_some(), "the open hand: {:?}", lent.icon);
}