From c01024c542e581702da50dd98b60b540f3dffa3c Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Mon, 23 Nov 2026 19:14:09 +0100 Subject: [PATCH] Host targets report a drag's end from the press; curve and colour-wheel drags close their Undo step with it --- crates/ui-egui/src/panels/detail/host.rs | 12 +++++++++++- crates/ui-egui/src/panels/edit/curve.rs | 4 +++- crates/ui-egui/src/panels/edit/grading.rs | 6 ++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/panels/detail/host.rs b/crates/ui-egui/src/panels/detail/host.rs index 3f6cd16399..1729464a66 100644 --- a/crates/ui-egui/src/panels/detail/host.rs +++ b/crates/ui-egui/src/panels/detail/host.rs @@ -62,7 +62,10 @@ impl Component for HostTarget { 0 }; let by_key = cx.activation().is_some_and(|activation| activation.by_key); - HostOutput { response: cx.response.clone(), clicks, by_key } + // egui's drag_stopped is only set while the press is still down, so the pass of the release is read from the + // press itself (as mask_controls' HitOutput does) + let drag_ended = matches!(cx.press().phase, PressPhase::Release { click: false, .. } | PressPhase::Cancel { .. }); + HostOutput { response: cx.response.clone(), clicks, by_key, drag_ended } } } @@ -72,6 +75,7 @@ pub(crate) struct HostOutput { pub response: Response, clicks: u32, by_key: bool, + drag_ended: bool, } impl HostOutput { @@ -90,6 +94,12 @@ impl HostOutput { pub fn double_clicked(&self) -> bool { self.clicked() && self.clicks >= 2 } + + /// A press that moved past the click slop ended this pass: released, or cancelled. This stands in for egui's + /// `drag_stopped`, which the framework's response does not report on the pass of the release. + pub fn drag_ended(&self) -> bool { + self.drag_ended + } } impl Deref for HostOutput { diff --git a/crates/ui-egui/src/panels/edit/curve.rs b/crates/ui-egui/src/panels/edit/curve.rs index dc0c007098..5efd9b8212 100644 --- a/crates/ui-egui/src/panels/edit/curve.rs +++ b/crates/ui-egui/src/panels/edit/curve.rs @@ -235,6 +235,8 @@ pub(super) fn curve_editor(app: &mut LightcraftApp, ui: &mut egui::Ui, id: Photo let out = live.then(|| host::target(ui, ("curve", &ch), r, host::Target::new(crate::i18n::tr("Tone Curve")).drag())); let resp = out.as_ref().map_or_else(|| ui.response(), |out| out.response.clone()); let double_clicked = out.as_ref().is_some_and(host::HostOutput::double_clicked); + // the release of a drag (the framework's response reports no drag_stopped on that pass) + let drag_ended = resp.drag_stopped() || out.as_ref().is_some_and(host::HostOutput::drag_ended); if let Some(out) = &out { crate::widgets::register_response("curve", r, &out.response); host::context_menu(ui, &out.response, crate::i18n::tr("Tone Curve"), |ui| curve_reset_menu(app, ui, &ch)); @@ -406,7 +408,7 @@ pub(super) fn curve_editor(app: &mut LightcraftApp, ui: &mut egui::Ui, id: Photo // the drag is over when egui says so, or when the pointer comes up without it saying so (a // release outside the window would otherwise leave the interaction open, and every later edit a // silent preview that Undo cannot take back) - if commit_interaction(app, ui, dragging.is_some(), resp.drag_stopped()) { + if commit_interaction(app, ui, dragging.is_some(), drag_ended) { dragging = None; } ui.data_mut(|dd| dd.insert_temp(drag_id, dragging)); diff --git a/crates/ui-egui/src/panels/edit/grading.rs b/crates/ui-egui/src/panels/edit/grading.rs index 41c7abfa3b..1dba49baf0 100644 --- a/crates/ui-egui/src/panels/edit/grading.rs +++ b/crates/ui-egui/src/panels/edit/grading.rs @@ -163,6 +163,8 @@ fn grading_wheel(app: &mut LightcraftApp, ui: &mut egui::Ui, d: &DevelopSettings }); let resp = target.as_ref().map_or_else(|| ui.response(), |target| target.response.clone()); let double_clicked = target.as_ref().is_some_and(crate::panels::detail::host::HostOutput::double_clicked); + // the release of a drag (the framework's response reports no drag_stopped on that pass) + let drag_ended = resp.drag_stopped() || target.as_ref().is_some_and(crate::panels::detail::host::HostOutput::drag_ended); if let Some(target) = &target { crate::widgets::register_response(format!("wheel:{key}"), r, &target.response); } @@ -231,11 +233,11 @@ fn grading_wheel(app: &mut LightcraftApp, ui: &mut egui::Ui, d: &DevelopSettings let (hue, sat) = grab.map_or_else(|| wheel_pick(q - c, rad, None), |g| g.pick(q - c, rad)); let _ = app.run("develop.set", json!({"values": {format!("grading.{key}.hue"): hue.round(), format!("grading.{key}.sat"): sat.round()}})); } - if wheel_input && (resp.drag_stopped() || resp.clicked()) { + if wheel_input && (drag_ended || resp.clicked()) { let _ = app.run("develop.endInteraction", json!({})); } // released, or Esc (egui ends a drag on it) - if resp.drag_stopped() + if drag_ended && let Some(held) = ui.ctx().data_mut(|m| m.remove_temp::(egui::Id::unique(WHEEL_CAPTURE))) && !held.dropped {