ui/timeline.rs#
Source: lib/ui/timeline.rs
timeline -- a scrubber for recorded events: a time axis, one lane of event ticks per track
and a playhead (the event timeline of a simulation)
timeline(id, &mut st, span, tracks) -> EV_*
span: the recorded time range in seconds (span.1 is the live end); a track is a
label and its ticks (time, 0xAARRGGBB; colour 0 = the chart palette colour of the
track), sorted by time. Natural size 480 DIP x (the axis + 22 DIP per track);
next_size sets another (the lanes share the height). The axis has 1 / 2 / 5 steps
with labels in seconds (the UI's decimal separator), down to nanoseconds (nine
decimals; the narrowest view is 10 ns: simulated networks). Each pixel column of a lane
draws the ticks that fall into it as one bar (taller for more ticks, their colours
stacked by share; a column alone is two wide), so many thousands of ticks stay
cheap. The playhead (st.t) is an accent line with its time on the axis.
Mouse: a press in the lanes seeks and drags the playhead, so does its time on the
axis; dragging the axis elsewhere pans the view, a click there seeks, a double
click shows the whole span; Shift+drag in the lanes selects a range (st.sel,
Shift+click clears it); Ctrl+wheel zooms around the pointer, Shift+wheel and the
horizontal wheel pan (the plain wheel is left to scroll views around it). Keys
(focused): Left / Right the previous / next tick of any track, Home / End the
start / the live end (End follows it again), PgUp / PgDn a view width, + / - zoom
at the playhead, Esc clears the range.
EV_ACT: the user moved st.t; EV_COMMIT: a drag of the playhead ended (a key or a
click gives both). st.follow keeps the playhead at the live end and the view
with it; moving the playhead by hand ends that. st.view is the visible range
(empty: the whole span; zoomed out fully it grows with the span). Seeks by the
pointer are rounded to the decimal resolution of a pixel.
Ids: id (the lanes; focus), part(id, 1) the axis, part(id, 2) the playhead's time.
Records: K_SLIDER id (value, min, max: t and the span in ms), K_TEXT per track label
(value: its number of ticks), K_TEXT part(id, 2) with the playhead's time ("1,250 s").
Everything keeps its left-to-right order in mirrored windows (ltr_begin).
struct TlTrack<'a>one lane of a timeline: a label and its event tickslabel: &'a strticks: &'a [(f64, u32)]-- (time in s, 0xAARRGGBB; 0 = the chart palette colour of the track), sorted by time
struct TimelineStatethe app-owned state of a timeline: playhead, visible range, selected range, followingt: f64-- the playhead (s)view: (f64, f64)-- the visible time range (s); empty (the default) = the whole spansel: Option<(f64, f64)>-- a selected time range (Shift+drag), start <= endfollow: bool-- keep the playhead at the live end of the span (moving it by hand ends this)test_mods: u32-- modifier keys (MOD_*) treated as held: scripts cannot hold Ctrl or Shift during awheel(an app maps a test command to it)
impl TimelineState
fn fit(&mut self)show the whole span again
impl Ui
fn timeline(&mut self, id: u32, st: &mut TimelineState, span: (f64, f64), tracks: &[TlTrack]) -> u32ui_timeline(id, &mut st, span, tracks) -> EV_*: a time axis, a lane of event ticks per track and a playhead (st.t) to seek with (see the module header of timeline.rs)