Host targets report a drag's end from the press; curve and colour-wheel drags close their Undo step with it

This commit is contained in:
skylartaylor
2026-11-23 19:14:09 +01:00
parent 21d42f75f8
commit c01024c542
3 changed files with 18 additions and 4 deletions
+11 -1
View File
@@ -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 {
+3 -1
View File
@@ -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));
+4 -2
View File
@@ -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::<WheelCapture>(egui::Id::unique(WHEEL_CAPTURE)))
&& !held.dropped
{