red round 2 (fw-core): fixes for fw-run-3 (runs/fw-run-3/fw-core.md); L-198 applied in fw-lists; committed by the lead

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-18 09:04:07 -05:00
co-authored by Claude Opus 5.5
parent 6187b8cea3
commit f49ad550fe
7 changed files with 121 additions and 64 deletions
+2 -2
View File
@@ -101,8 +101,8 @@ pub use part::{PartKey, PartRef};
pub use pixel_size::PixelSize;
pub use press::{
Buttons, MultiTouch, PassInput, PointerButton, PointerEvent, PointerKind, PointerSample, PressCancel, PressMachine, PressPhase, PressStart,
PressState, PressStep, count_clicks,
Buttons, MultiTouch, PassInput, PointerButton, PointerEvent, PointerKind, PointerSample, PressCancel, PressMachine, PressPhase, PressPick,
PressStart, PressState, PressStep, count_clicks,
};
pub use quantity::Reader;
pub use role_rule::{GridFacts, RoleRule, is_checkable, is_selectable, role_violations};
+74 -29
View File
@@ -466,6 +466,32 @@ impl<T> Default for PressStep<T> {
}
}
/// The press winner a root picks at a press position, as [`PressMachine::step`]'s `pick` returns it.
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct PressPick<T> {
/// The press winner.
pub target: T,
/// What it senses of the press.
pub sense: Sense,
/// The press's click went to a shape above that passes its drag to this target (`Sense::PASSES_DRAG`): the press
/// opens silent and is the target's only once its drag starts.
pub passed: bool,
}
impl<T> PressPick<T> {
/// `target`, sensing `sense`, takes the press.
pub fn new(target: T, sense: Sense) -> Self {
PressPick { target, sense, passed: false }
}
/// The press's click went to a shape above that passes its drag to this target.
pub fn passed(mut self) -> Self {
self.passed = true;
self
}
}
#[derive(Clone, Copy, Debug)]
struct Open<T> {
target: T,
@@ -477,8 +503,10 @@ struct Open<T> {
/// Moved past slop in this pass on a target that clicks and passes its drag (`Sense::PASSES_DRAG`), with the
/// pointer at the pass's end: no click and no drag until [`PressMachine::hand_over`] gives the press its new
/// target. The next pass abandons a press no shape took.
passing: Option<Pos2>,
/// A press passed to this target ([`PressPick::passed`]) whose drag has not started: it reports nothing, and a
/// release or cancel ends it unreported. Its move past slop starts the drag with `DragStart`, as a hand-over does.
silent: bool,
/// A pass reported the press: later passes within slop report `Held`, not `Down`.
reported: bool,
/// A pass reported the drag's start: later passes report `Drag`.
@@ -542,10 +570,11 @@ impl<T: Copy> PressMachine<T> {
/// Runs one pass. `pick` chooses the press winner and what it senses at a press position; it returns `None`
/// when no shape of this root takes the press.
pub fn step(&mut self, input: PassInput<'_>, mut pick: impl FnMut(Pos2) -> Option<(T, Sense)>) -> PressStep<T> {
pub fn step(&mut self, input: PassInput<'_>, mut pick: impl FnMut(Pos2) -> Option<PressPick<T>>) -> PressStep<T> {
let mut pos = input.pos;
let mut released: Option<(T, PressStart, Pos2, bool, bool)> = None;
let mut cancelled: Option<(T, PressStart, PressCancel)> = None;
// The press released or cancelled in this pass, and whether it was silent: one that ends silent reports nothing.
let mut released: Option<(T, PressStart, Pos2, bool, bool, bool)> = None;
let mut cancelled: Option<(T, PressStart, PressCancel, bool)> = None;
// A press passed in the last pass that no shape took is abandoned; that pass reported its `Down`.
if let Some(open) = &mut self.open
&& open.passing.is_some()
@@ -558,11 +587,11 @@ impl<T: Copy> PressMachine<T> {
&& let Some((at, click)) = open.released_at
&& !open.owes_phase()
{
released = Some((open.target, open.start, at, open.dragging, click));
released = Some((open.target, open.start, at, open.dragging, click, open.silent));
self.open = None;
}
if let (Some(reason), Some(open)) = (input.cancel, self.open) {
cancelled = Some((open.target, open.start, reason));
cancelled = Some((open.target, open.start, reason, open.silent));
self.open = None;
}
for event in input.events {
@@ -578,6 +607,7 @@ impl<T: Copy> PressMachine<T> {
{
if open.sense.contains(Sense::DRAG) {
open.dragging = true;
open.silent = false;
} else if open.sense.contains(Sense::CLICK | Sense::PASSES_DRAG) {
open.passing = Some(at);
} else {
@@ -596,7 +626,7 @@ impl<T: Copy> PressMachine<T> {
if let Some(open) = self.open
&& let Some((up, click)) = open.released_at
{
released = Some((open.target, open.start, up, open.dragging, click));
released = Some((open.target, open.start, up, open.dragging, click, open.silent));
self.open = None;
}
// An open press keeps the pointer until its button comes up: no press starts over it, of its own
@@ -610,26 +640,31 @@ impl<T: Copy> PressMachine<T> {
continue;
}
self.open = pick(at)
.map(|(target, sense)| {
.map(|pick| {
let clicks = match button {
PointerButton::Middle => sense.contains(Sense::MIDDLE_CLICK),
PointerButton::Secondary => sense.contains(Sense::CONTEXT_CLICK),
PointerButton::Middle => pick.sense.contains(Sense::MIDDLE_CLICK),
PointerButton::Secondary => pick.sense.contains(Sense::CONTEXT_CLICK),
_ => false,
};
(target, if capture_only && !clicks { sense - Sense::CLICK } else { sense }, clicks)
let sense = if capture_only && !clicks { pick.sense - Sense::CLICK } else { pick.sense };
(pick, sense, clicks)
})
.filter(|(_, sense, clicks)| !capture_only || *clicks || sense.contains(Sense::DRAG))
.map(|(target, sense, _)| (target, sense))
.map(|(target, sense)| Open {
target,
sense,
start: PressStart::new(at, button, time, clicks),
dragging: false,
abandoned: false,
passing: None,
reported: false,
drag_reported: false,
released_at: None,
.map(|(pick, sense, _)| {
// A silent press owes no `Down`: its first phase is its `DragStart`.
let silent = pick.passed && sense.contains(Sense::DRAG);
Open {
target: pick.target,
sense,
start: PressStart::new(at, button, time, clicks),
dragging: false,
abandoned: false,
passing: None,
silent,
reported: silent,
drag_reported: false,
released_at: None,
}
});
}
PointerEvent::Released { button, pos: at } => {
@@ -642,7 +677,7 @@ impl<T: Copy> PressMachine<T> {
{
open.released_at = Some((at, open.clicks()));
} else if let Some(open) = self.open.take() {
released = Some((open.target, open.start, at, open.dragging, open.clicks()));
released = Some((open.target, open.start, at, open.dragging, open.clicks(), open.silent));
}
}
}
@@ -651,11 +686,17 @@ impl<T: Copy> PressMachine<T> {
if self.open.is_some_and(|open| open.released_at.is_none()) && !input.held && released.is_none() {
self.open = None;
}
if let Some((target, start, reason)) = cancelled {
if let Some((target, start, reason, silent)) = cancelled {
if silent {
return PressStep::default();
}
let phase = PressPhase::Cancel { start, reason };
return PressStep { target: Some(target), phase: Some(phase), dragging: false, activated: None, passes: None };
}
if let Some((target, start, at, was_dragging, click)) = released {
if let Some((target, start, at, was_dragging, click, silent)) = released {
if silent {
return PressStep::default();
}
let phase = PressPhase::Release { start, pos: at, click };
return PressStep {
target: Some(target),
@@ -666,6 +707,9 @@ impl<T: Copy> PressMachine<T> {
};
}
let Some(open) = self.open.as_mut() else { return PressStep::default() };
if open.silent {
return PressStep::default();
}
if let Some(at) = &mut open.passing {
*at = pos;
}
@@ -717,7 +761,7 @@ mod tests {
fn pass(machine: &mut PressMachine<u8>, events: &[PointerEvent], sense: Sense) -> PressStep<u8> {
let held = machine.open.is_some() || matches!(events.last(), Some(PointerEvent::Pressed { .. }));
machine.step(PassInput::new(events, SLOP, pos2(0.0, 0.0), held), |_| Some((1, sense)))
machine.step(PassInput::new(events, SLOP, pos2(0.0, 0.0), held), |_| Some(PressPick::new(1, sense)))
}
fn press(x: f32, time: f64) -> PointerEvent {
@@ -769,8 +813,9 @@ mod tests {
fn a_press_of_the_held_button_leaves_the_open_drag_its_moves_and_release() {
let first = pos2(0.0, 0.0);
let mut machine = PressMachine::new();
let mut step =
|events: &[PointerEvent]| machine.step(PassInput::new(events, SLOP, first, true), |at| (at == first).then_some((1u8, Sense::DRAG)));
let mut step = |events: &[PointerEvent]| {
machine.step(PassInput::new(events, SLOP, first, true), |at| (at == first).then_some(PressPick::new(1u8, Sense::DRAG)))
};
step(&[press(0.0, 1.0)]);
step(&[PointerEvent::Moved { at: pos2(40.0, 0.0), sample: None }]);
let repeated = step(&[press(50.0, 1.2)]);
@@ -811,7 +856,7 @@ mod tests {
/// One pass with the button held at its end, over a root whose press winner is target 1 and passes its drag.
fn passing_pass(machine: &mut PressMachine<u8>, events: &[PointerEvent]) -> PressStep<u8> {
machine.step(PassInput::new(events, SLOP, pos2(0.0, 0.0), true), |_| Some((1, PASSES)))
machine.step(PassInput::new(events, SLOP, pos2(0.0, 0.0), true), |_| Some(PressPick::new(1, PASSES)))
}
fn moved(x: f32) -> PointerEvent {
+4 -4
View File
@@ -486,7 +486,11 @@ impl<'a> Canvas<'a> {
let middle = press.phase.start().is_some_and(|start| start.button == PointerButton::Middle);
let latching = middle && !on_region && self.navigation.middle_button == MiddleButton::AutoScroll;
let held = latching && press.phase.button_down();
// Any press that begins while a latch runs ends it and reaches nothing else, so it is asked before the press
// that latches: asked after, the latching press would end its own latch.
let swallowed = motion.middle.swallows(press.phase);
match press.phase {
_ if swallowed => {}
// The latch lives while the canvas holds the focus, and the focus service moves focus on primary presses
// only: the middle press that latches it takes the focus itself.
PressPhase::Down { start, .. } if latching => {
@@ -495,12 +499,8 @@ impl<'a> Canvas<'a> {
}
PressPhase::Release { .. } if latching => motion.middle.release(),
PressPhase::Cancel { .. } if latching => motion.middle.cancel(),
// Any other press on the background ends a latch.
PressPhase::Down { .. } if motion.middle.active() => motion.middle.cancel(),
_ => {}
}
// PLAN: assumed MiddleScroll::swallows(&mut self, PressPhase) -> bool (pdf-canvas-w2)
let swallowed = motion.middle.swallows(press.phase);
// A latch with the button up ends on Escape, claimed only while it runs, and when the canvas loses focus.
if motion.middle.active() && !held {
if cx.take_claimed(LATCH_ESCAPE) || !cx.is_focused() {
+4 -8
View File
@@ -19,8 +19,9 @@ use egui::{Key, Modifiers, Pos2, TouchPhase, Vec2};
use std::cell::{Cell, RefCell};
use std::rc::Rc;
/// A canvas over a large document with Touchpad Glide set to `touchpad_glide`, whose view starts 60 points short of
/// the document's right edge with the pointer over it: the fixture and the view it shows.
/// A canvas over a large document with Touchpad Glide set to `touchpad_glide`, whose view starts 210 points short of
/// the document's right edge with the pointer over it, so a fast [`swipe`] (150 points) lifts 60 points short of it:
/// the fixture and the view it shows.
fn glide_rig(touchpad_glide: bool) -> (Fixture, Rc<Cell<CanvasView>>) {
let view = Rc::new(Cell::new(CanvasView::new(egui::Rect::ZERO, Point::new(2000.0, 2000.0), 1.0)));
let shown = Rc::clone(&view);
@@ -34,7 +35,7 @@ fn glide_rig(touchpad_glide: bool) -> (Fixture, Rc<Cell<CanvasView>>) {
});
fixture.settle();
let mut near = view.get();
near.center.x = 4000.0 - f64::from(near.rect.width()) / 2.0 - 60.0;
near.center.x = 4000.0 - f64::from(near.rect.width()) / 2.0 - 210.0;
view.set(near);
fixture.frame(vec![pointer::moved(near.rect.center())]);
(fixture, view)
@@ -404,11 +405,6 @@ fn a_latched_middle_scroll_ends_on_escape_a_second_press_or_the_wheel_and_a_held
};
latch(&mut fixture);
eprintln!(
"DIAG a_latched_middle_scroll_ends_on_escape_a_second_press_or_the_wheel_and_a_held_press_scrolls_until_its_release: focused {:?}, canvas {:?}",
fixture.focused_stop(),
canvas.get()
);
assert!(
fixture.focused_stop().is_some_and(|(id, _)| Some(id) == canvas.get()),
"the middle press focuses the canvas, which its Escape claim needs"
+7 -3
View File
@@ -16,7 +16,8 @@ use crate::runtime::memory::{MemoryStage, sub};
use crate::runtime::pointer;
use crate::runtime::pointer::PassPointer;
use craft_behavior::{
Cursor, HitLevel, HitPriority, HitShape, PartKey, PartRef, PassInput, PointerSample, PressMachine, PressPhase, PressState, Sense, Shape, Winner,
Cursor, HitLevel, HitPriority, HitShape, PartKey, PartRef, PassInput, PointerSample, PressMachine, PressPhase, PressPick, PressState, Sense,
Shape, Winner,
};
use craft_keymap::Mods;
use craft_theme::Flags;
@@ -129,7 +130,6 @@ pub(crate) struct PartDecl {
/// The component holds a press on the part (`PartBuilder::held`).
pub held: bool,
/// The named stacking order among parts of one priority (default 0).
pub stacking: u32,
}
@@ -892,9 +892,13 @@ fn outcome_in(ctx: &Context, read: &PassRead, arena: ArenaId, layer: Layer, enab
let won = root.and_then(|own| winners.hit_of(own)).map(Hit::from);
// The kinds of press another root won are not this one's.
let lost = (Sense::CLICK | Sense::DRAG).difference(won_kinds);
// A click that another root's shape took and passes its drag on (L-19) leaves this root only the drag: a
// click there gives this root no press at all.
let passed = lost.contains(Sense::CLICK) && winners.click.is_some_and(|(click, _)| click.sense.contains(Sense::PASSES_DRAG));
won.map(|hit| {
let sense = hit.sense.difference(lost);
(hit, if drag_elsewhere { sense.difference(Sense::DRAG) } else { sense })
let pick = PressPick::new(hit, if drag_elsewhere { sense.difference(Sense::DRAG) } else { sense });
if passed { pick.passed() } else { pick }
})
});
// A press on a shape that passes its drag (`Sense::PASSES_DRAG`) moved past slop: the drag goes to the shape the
+30 -17
View File
@@ -72,16 +72,19 @@ const ON: f32 = 1.0;
#[derive(Default)]
struct Seen {
own_on: Cell<f32>,
travel: Cell<f32>,
presence: Cell<Option<(f32, bool, bool)>>,
phase: Cell<Option<Option<f32>>>,
}
/// Animates `on` itself (a name the pipeline's state mix also uses), a presence and a loop phase.
/// Animates `on` itself (a name the pipeline's state mix also uses), a travel toward `arrived`, a presence and a loop
/// phase.
#[derive(Component)]
struct Animator<'a> {
#[common]
common: Common,
open: bool,
arrived: bool,
seen: &'a Seen,
}
@@ -100,6 +103,7 @@ impl Component for Animator<'_> {
fn update(&mut self, cx: &mut Cx<'_, Self>) {
self.seen.own_on.set(cx.anim_bool("on", true, spec::HOVER));
self.seen.travel.set(cx.anim_bool("travel", self.arrived, spec::MOVE));
let presence = cx.presence("panel", self.open, spec::OPEN_FADE);
self.seen.presence.set(Some((presence.t, presence.visible, presence.exiting)));
self.seen.phase.set(Some(cx.phase(1.0, None)));
@@ -117,7 +121,7 @@ fn a_component_animating_on_does_not_fight_the_state_mix() {
let seen = Seen::default();
let mut frames = Frames::new();
let mut show = |ui: &mut egui::Ui| {
Animator { common: Common::new(), open: true, seen: &seen }.show(ui);
Animator { common: Common::new(), open: true, arrived: false, seen: &seen }.show(ui);
};
frames.idle(60, &mut show);
assert_eq!(seen.own_on.get(), ON, "the component's own value stays at its target");
@@ -129,34 +133,43 @@ fn a_component_animating_on_does_not_fight_the_state_mix() {
assert_eq!(frames.repaint_delay(), None, "with no loop under reduced motion, nothing is left to animate");
}
/// Under reduced motion nothing eases: the hover state mix, a component's own tween and a presence that opens are at
/// their end in the frames their target changes in, and ask for no pass after them. Full motion would still be easing
/// there and asking for the next pass.
/// Under reduced motion the motion table's rows hold: a travel is at its end in the frame its target changes and a
/// loop paints its still frame, while the fades (the hover state mix, a presence that opens) still ease, then settle
/// and ask for no further pass.
#[trial]
fn reduced_motion_settles_every_animation_at_once() {
fn reduced_motion_snaps_travel_and_loops_and_runs_fades() {
let hover = Cell::new(0.0);
let seen = Seen::default();
let open = Cell::new(false);
let (open, arrived) = (Cell::new(false), Cell::new(false));
let mut frames = Frames::new();
frames.root(RootEnv::default().motion(MotionMode::Reduced));
let mut show = |ui: &mut egui::Ui| {
Hovered { common: Common::new(), seen: &hover }.show(ui);
Animator { common: Common::new(), open: open.get(), seen: &seen }.show(ui);
Animator { common: Common::new(), open: open.get(), arrived: arrived.get(), seen: &seen }.show(ui);
};
frames.idle(3, &mut show);
assert_eq!(seen.own_on.get(), ON, "the component's own tween is at its target from its first frames");
assert_eq!(seen.phase.get(), Some(None), "a loop paints its still frame");
let rest = hover.get();
// The pointer arrives over the hovered component and the panel opens in one frame; the hover reads a pass later.
// The travel's target, the pointer over the hovered component and the panel change in one frame; the hover reads
// a pass later.
open.set(true);
arrived.set(true);
frames.frame(vec![moved(Pos2::new(10.0, 10.0))], &mut show);
assert_eq!(seen.travel.get(), ON, "the travel is at its end in the frame its target changed");
frames.frame(Vec::new(), &mut show);
let (hovered, presence) = (hover.get(), seen.presence.get());
assert_eq!(frames.repaint_delay(), None, "nothing is left easing: {hovered} {presence:?}");
assert!(matches!(presence, Some((_, true, false))), "the panel shows and is not leaving: {presence:?}");
let presence = seen.presence.get();
assert!(matches!(presence, Some((t, true, false)) if t < ON), "the panel fades in, shown and not leaving: {presence:?}");
assert!(frames.repaint_delay().is_some(), "the fades are still easing and ask for the next pass");
frames.idle(30, &mut show);
assert!(hovered > rest, "the hover rose from {rest}");
assert_eq!(hover.get(), hovered, "the hover was already at its end");
assert_eq!(seen.presence.get(), presence, "the presence was already at its end");
let mut passes = 0;
while frames.repaint_delay().is_some() && passes < 120 {
frames.frame(Vec::new(), &mut show);
passes += 1;
}
assert_eq!(frames.repaint_delay(), None, "the fades settle and stop asking for passes");
assert!(hover.get() > rest, "the hover rose from {rest}");
let shown = seen.presence.get();
assert!(matches!(shown, Some((t, true, false)) if t >= ON), "the panel is fully shown: {shown:?}");
assert_eq!(seen.travel.get(), ON, "the travel stayed at its end");
}
@@ -162,7 +162,6 @@ fn a_finished_render_asks_for_a_repaint() {
let runs = Arc::new(AtomicUsize::new(0));
// egui's own first frames ask for follow-up passes; the job is asked for once they are over.
frames.idle(QUIET_FRAMES, |_| {});
eprintln!("DIAG a_finished_render_asks_for_a_repaint: before the request, repaint requested {}", frames.repaint_requested());
frame(&mut frames, || {
loader.request(&ctx, &1, Revision::new(1), Priority::VISIBLE, || counted(&runs, SMALL));
});