JFLib

25. Event timeline and hex view#

Two data widgets for the simulation mode of a network simulator (and any recorded events): ui/timeline.rs and ui/hexview.rs, both on the page "Simulation" of apps/datagallery.

Timeline: a time axis, one lane of event ticks per track and a playhead. The app keeps a TimelineState and passes the recorded span and its tracks every frame:

// state: tl: TimelineState; tcp, arp: Vec<(f64, u32)> -- (time in s, 0xAARRGGBB), sorted by time
let tracks = [TlTrack { label: "TCP", ticks: &self.tcp }, TlTrack { label: "ARP", ticks: &self.arp }];
ui.next_size(-1, 0); // natural height: the axis + 22 DIP per track
let ev = ui.timeline(ID_TL, &mut self.tl, (0.0, self.sim_end), &tracks);
if ev & EV_ACT != 0 {
    self.show_state_at(self.tl.t); // the user moved the playhead
}
  • tl.t is the playhead (s), tl.view the visible range (empty: the whole span; zoomed out fully it grows with the span), tl.sel a range selected with Shift+drag; tl.follow keeps the playhead at the live end span.1 (moving it by hand ends that, End starts it again); tl.fit() shows everything again. EV_COMMIT comes when a drag of the playhead ends.
  • Every pixel column of a lane draws its ticks as one bar: taller for more, the colours stacked by share (colour 0: the chart palette colour of the track). Tens of thousands of ticks stay cheap; the bars are one cached draw object.
  • Mouse: a press in the lanes seeks and drags the playhead, so does its time on the axis; dragging the axis pans, a click there seeks, a double click shows the whole span; Ctrl+wheel zooms around the pointer, Shift+wheel and the horizontal wheel pan (the plain wheel stays with the scroll views around it). Keys: Left / Right the previous / next tick of any track, Home / End, PgUp / PgDn, + / -, Esc clears the range. Pointer seeks are rounded to the decimal resolution of a pixel. The axis goes down to nanoseconds (labels with up to nine decimals, the narrowest view 10 ns), so the frames of a simulated LAN, which are microseconds apart, get lanes of their own.
  • Scripts cannot hold Ctrl during wheel: tl.test_mods = MOD_CTRL treats it as held (datagallery maps cmd 9100 2 to it).

Hex view: bytes as hex and ASCII side by side, with marked ranges (the fields of a decoded packet) and a selection that the app and the user share:

// state: hex: HexState; fields: (offset, length, id) of the decoded layers
let marks: Vec<HexMark> = fields.iter().map(|f| HexMark { start: f.0, len: f.1, color: 0, key: f.2 }).collect();
ui.next_size(-1, 240); // without next_size it fills its parent
let ev = ui.hex_view(ID_HEX, &mut self.hex, &self.pdu, &marks);
if let Some(key) = ev.clicked_key {
    self.select_field(key); // a byte was clicked: the smallest mark holding it
}
// the other way round: a field chosen elsewhere selects its bytes, the view scrolls to them
self.hex.sel = Some((off, len));
  • Rows 0010 45 00 00 54 ... |E..T....| in the system's monospace font (else the UI font cell by cell), virtualized in a scroll view; hex.cols bytes per row (0: 16 when they fit, else 8). Marks are translucent fills behind both columns (colour 0: the chart palette; an opaque colour gets a highlight's alpha), smaller ranges over larger ones.
  • A click selects a byte, a drag a range (the view scrolls at its edges), Shift+click extends, a double click selects the mark, a click on an offset its row; arrows, PgUp / PgDn and Home / End move the caret (Shift extends, a move reports the caret's mark like a click), Ctrl+A selects all, Ctrl+C copies the selection as hex (45 00 00 54). ev.hover is the byte under the pointer (its offset is also a tooltip); ev.ev has EV_ACT (the selection changed), EV_DOUBLE and EV_RCLICK (open a context menu).
  • Records: each visible row has K_TEXT records for its offset (text:"0010"), its hex and its characters; the view is a K_LIST (value: the caret, max: the number of bytes).

Both keep their left-to-right order in mirrored windows. Testing: apps/datagallery/tests/timeline.uis, hexview.uis, simulation.uis (light, dark, 150 %).

Source: docs/GUIDE.md in the JFLib repository.