Paint: keep stylus pressure on quick taps (#1967)

A release that egui reports as both a drag stop and a click no longer replays the click over a live
stroke (which painted a second full-pressure dab), and the click fallback now uses the pen's pressure.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Nigel Ihza FirdausyandClaude Opus 5.5 authored and GitHub committed 2026-10-09 15:34:21 -04:00
1 parent f885991184
commit cc4a13b58d
1 file changed
+22 -1
+22 -1
View File
@@ -2626,6 +2626,12 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
crate::magnetic_lasso_ui::flush(app);
}
if buttons.stopped {
// The live painting press already created the stroke and this release commits it.
// egui may also report clicked on the same release; replaying that click paints a
// second full-pressure dab over the real (possibly light-pressure) pen dab.
if press_stroke {
buttons.clicked = false;
}
let p = response.interact_pointer_pos().map(|p| xf.to_doc(p)).or_else(|| app.drag.as_ref().and_then(|d| d.points.last().map(|q| [q[0], q[1]])));
if let Some(d) = p {
tool_event(app, ToolEvent::Up { x: d[0], y: d[1] }, mods);
@@ -2669,7 +2675,9 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
if tool == Tool::Move && app.ui.transform.is_none() {
begin_transform_controls_at(app, &ctx, &xf, p);
}
tool_event(app, ToolEvent::Down { x: d[0], y: d[1], pressure: 1.0 }, click_mods);
// If this tool was not handled on pointer-down, fall back to a
// click-sized gesture while preserving pen pressure (mouse stays at 1).
tool_event(app, ToolEvent::Down { x: d[0], y: d[1], pressure: app.stylus.pressure() }, click_mods);
tool_event(app, ToolEvent::Up { x: d[0], y: d[1] }, click_mods);
}
}
@@ -4054,6 +4062,19 @@ pub fn paint_target(app: &PhotocraftApp) -> serde_json::Value {
json!(if (app.ui.mask_target || viewing) && has_mask { "mask" } else { "pixels" })
}
#[cfg(test)]
mod tap_pressure_tests {
#[test]
fn fallback_click_pressure_matches_pen_or_mouse() {
let mut s = crate::stylus::Stylus::default();
assert_eq!(s.pressure(), 1.0, "mouse clicks paint at full pressure");
s.feed.set(Some(crate::stylus::PenSample { pressure: 0.18, ..Default::default() }));
assert_eq!(s.pressure(), 0.18, "a tap without a canvas drag still has pen pressure");
s.use_pressure = false;
assert_eq!(s.pressure(), 1.0, "Use Tablet Pressure off stays full pressure");
}
}
#[cfg(test)]
mod tabs_tests;