mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-19 09:36:36 +00:00
panels-w4: review fixes (review-1)
This commit is contained in:
@@ -362,6 +362,14 @@ impl<T> Default for EditEvents<T> {
|
||||
}
|
||||
|
||||
impl<T> EditEvents<T> {
|
||||
/// 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<V> {
|
||||
/// 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<V> Default for Gesture<V> {
|
||||
@@ -539,6 +550,7 @@ impl<V> Default for Gesture<V> {
|
||||
dead: false,
|
||||
cancel_seen: 0,
|
||||
watched: false,
|
||||
wheel: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<C: Component> Cx<'_, C> {
|
||||
fn gesture_slot(&mut self) -> &mut Gesture<ValueOf<C>> {
|
||||
@@ -355,8 +350,7 @@ impl<C: Component> 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::<Option<GestureId>>(wheel_run_key(self.core.id)) = Some(began);
|
||||
slot.wheel = true;
|
||||
}
|
||||
}
|
||||
if phase == WheelPhase::End && self.in_wheel_run() {
|
||||
@@ -367,6 +361,6 @@ impl<C: Component> Cx<'_, C> {
|
||||
/// Whether the running gesture is a wheel run.
|
||||
pub fn in_wheel_run(&self) -> bool {
|
||||
let slot = self.core.memory.recall::<Gesture<ValueOf<C>>>(gesture_key(self.core.id));
|
||||
slot.is_running() && self.core.memory.recall::<Option<GestureId>>(wheel_run_key(self.core.id)) == Some(slot.id)
|
||||
slot.is_running() && slot.wheel
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user