Skip to main content

Module clock

Module clock 

Source
Expand description

The one clock.

§The rule

Instant never enters a recognizer. Every deadline the input layer owns — a long press, a double-tap window, a fling’s decay, a press-feedback delay — is an EventTime read from the tree’s InputClock. A recognizer that calls Instant::now() cannot be driven by a test, and a recognizer that cannot be driven by a test is one whose timing is only ever exercised by sleeping.

§Why the epoch is shared

A WidgetTree already has a simulated clock: the sim_clock that advance_time moves and that the animation scheduler is ticked against. Its epoch is the Instant captured when the tree was built. MonotonicClock is seeded from that same instant, so EventTime::ZERO and simulated_now() name the same moment and the two timelines are one axis rather than two.

Without that, a test would have to advance two clocks in step to move a long press and the animation it kicks off, and the two would drift by however long the test itself took — the exact failure mode the animation clock already had to be rescued from (see WidgetTree::animation_clock).

§Choosing an implementation

MonotonicClock reads the wall clock and is what a real window uses. ManualClock is set by the caller and never moves on its own, which is what a headless test wants when it drives time explicitly. Both are held as Rc<dyn InputClock>, so a tree’s clock can be swapped at any point with WidgetTree::set_input_clock.

Structs§

ManualClock
A clock the caller moves by hand. Never advances on its own.
MonotonicClock
A clock that reads the wall clock, measured from a fixed epoch.

Traits§

InputClock
The source of EventTimes for one tree.