diff --git a/crates/behavior/src/value.rs b/crates/behavior/src/value.rs index 10acc1542..3b6f0adf4 100644 --- a/crates/behavior/src/value.rs +++ b/crates/behavior/src/value.rs @@ -362,6 +362,14 @@ impl Default for EditEvents { } impl EditEvents { + /// The value of the last `Commit` or `Set` in the events; `None` if there is none. + pub fn committed(&self) -> Option<&T> { + self.0.iter().rev().find_map(|event| match event { + EditEvent::Commit { after, .. } | EditEvent::Set { after, .. } => Some(after), + _ => None, + }) + } + /// No events. pub fn new() -> Self { Self::default() @@ -525,6 +533,9 @@ pub struct Gesture { /// The runtime's removal watch holds this gesture's id. #[doc(hidden)] pub watched: bool, + /// The running gesture is a wheel run (`Cx::wheel_run`); cleared when the gesture ends. + #[doc(hidden)] + pub wheel: bool, } impl Default for Gesture { @@ -539,6 +550,7 @@ impl Default for Gesture { dead: false, cancel_seen: 0, watched: false, + wheel: false, } } } diff --git a/crates/ui-contract/src/contract/cx/edit.rs b/crates/ui-contract/src/contract/cx/edit.rs index 01917c994..a01b1950e 100644 --- a/crates/ui-contract/src/contract/cx/edit.rs +++ b/crates/ui-contract/src/contract/cx/edit.rs @@ -4,7 +4,7 @@ use super::context::{Cx, CxCore}; use crate::contract::{Component, EditResponse, Pointer as _, Validity, ValueOf}; use crate::primitives::Adopted; use craft_behavior::{ - CancelReason, EditEvent, Gesture, GestureId, GesturePhase, Mixed, PartRef, PointerButton, PressCancel, PressPhase, Sense, Value, WheelPhase, + CancelReason, EditEvent, Gesture, GesturePhase, Mixed, PartRef, PointerButton, PressCancel, PressPhase, Sense, Value, WheelPhase, }; use egui::{Id, Pos2}; use std::sync::Arc; @@ -77,11 +77,6 @@ pub(crate) fn gesture_key(id: Id) -> Id { crate::runtime::memory::sub(id, "edit") } -/// The key of the slot naming the gesture a wheel began. It holds a gesture id, not a flag, so a run that ended -/// some other way (a host change, a removal) and a later gesture of another kind never read as a wheel run. -fn wheel_run_key(id: Id) -> Id { - crate::runtime::memory::sub(id, "wheel-run") -} impl Cx<'_, C> { fn gesture_slot(&mut self) -> &mut Gesture> { @@ -355,8 +350,7 @@ impl Cx<'_, C> { let slot = self.gesture_slot(); // Only a run the wheel began is a wheel run: a notch inside a press-carried gesture joins that gesture. if !running && slot.is_running() { - let began = slot.id; - *self.core.memory.shown::>(wheel_run_key(self.core.id)) = Some(began); + slot.wheel = true; } } if phase == WheelPhase::End && self.in_wheel_run() { @@ -367,6 +361,6 @@ impl Cx<'_, C> { /// Whether the running gesture is a wheel run. pub fn in_wheel_run(&self) -> bool { let slot = self.core.memory.recall::>>(gesture_key(self.core.id)); - slot.is_running() && self.core.memory.recall::>(wheel_run_key(self.core.id)) == Some(slot.id) + slot.is_running() && slot.wheel } }