ui/hexview.rs#
Source: lib/ui/hexview.rs
hexview -- bytes as hex and ASCII side by side, with marked ranges (a packet inspector)
hex_view(id, &mut st, data, marks) -> HexEv
rows "0010 45 00 00 54 ... |E..T....|" in the system's monospace font (else the
UI font, a character per cell), virtualized in a vertical scroll view that fills
its parent unless next_size says otherwise; st.cols bytes per row (0: 16 when they
fit, else 8), offsets with 4 hex digits (8 beyond 64 KiB). marks are translucent
fills behind their bytes in both columns (colour 0 = the chart palette colour of
the mark's index; an opaque colour gets a highlight's alpha), smaller ranges over
larger ones. The selection (st.sel: start, length), the byte under the pointer and,
while the view has the focus, the caret show in the hex and the ASCII column
together; zero bytes and the dots of other bytes are dimmed.
Mouse: a click selects a byte (HexEv::clicked_key: the key of the smallest mark
holding it), a drag a range (the view scrolls at its edges), Shift+click extends
it, a double click selects the mark's range, a click on an offset its row; the byte
under the pointer is HexEv::hover, its offset a tooltip. Keys (focused): arrows,
PgUp / PgDn, Home / End (of the row; with Ctrl of the data) 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 in one line ("45 00 00 54"). When the app changes
st.sel the view scrolls to it.
HexEv::ev: EV_ACT the user changed the selection, EV_DOUBLE, EV_RCLICK (the byte is
selected first: open a context menu), EV_HOVER, EV_FOCUS.
Ids: id (the scroll view; focus; its bar part(id, 1)), part(id, 3) the rows. Records:
K_LIST id (value: the caret, max: the number of bytes), K_BOX part(id, 3) (value: the byte
under the pointer or -1), per visible row K_TEXT with its offset ("0010", value: the
offset), its hex bytes ("45 00 00 54 ...") and its characters ("E..T...."); the hover
tooltip is a K_TEXT too. The rows keep their left-to-right order in mirrored windows
(ltr_begin).
struct HexMarka marked byte range of a hex view (a protocol field)start: u32len: u32color: u32-- 0xAARRGGBB (an opaque colour is drawn translucent); 0 = the chart palette colour of the mark's indexkey: u64-- the app's key of the range (HexEv::clicked_key)
struct HexStatethe app-owned state of a hex view: selection, bytes per row, caretsel: Option<(u32, u32)>-- the selected bytes: (start, length >= 1); when the app changes it, the view scrolls to itcols: u8-- bytes per row; 0 = 16 when they fit, else 8
impl HexState
fn caret(&self) -> u32the keyboard caret (a byte offset)fn reveal(&mut self, off: u32)scroll byteoffinto viewstruct HexEvwhat happened in a hex view during the passhover: Option<u32>-- the byte under the pointerclicked_key: Option<u64>-- a byte was clicked or the caret moved onto it: the key of the smallest mark holding itev: u32-- EV_ACT the selection changed, EV_DOUBLE, EV_RCLICK, EV_HOVER, EV_FOCUS
impl Ui
fn hex_view(&mut self, id: u32, st: &mut HexState, data: &[u8], marks: &[HexMark]) -> HexEvui_hex_view(id, &mut st, data, marks) -> HexEv: bytes as hex and ASCII rows with marked ranges, a selection and a caret (see the module header of hexview.rs)