Skip to main content

liveplot/
events.rs

1//! Generic event system for LivePlot.
2//!
3//! Callers can subscribe to a rich set of UI and data events via
4//! [`EventController`].  Each event carries a set of [`EventKind`] flags
5//! (bitflags-style) so that a single occurrence can match multiple
6//! categories (e.g. a measurement-point click is *also* a `Click` event).
7//!
8//! The caller specifies an [`EventFilter`] to receive only the events they
9//! care about.  The filter is a simple OR mask: an event is delivered when
10//! `(event.kinds & filter) != 0`.
11
12use std::sync::mpsc::{Receiver, Sender};
13use std::sync::{Arc, Mutex};
14
15use crate::data::traces::TraceRef;
16
17// ─────────────────────────────────────────────────────────────────────────────
18// EventKind – bitflags
19// ─────────────────────────────────────────────────────────────────────────────
20
21/// Bitflags describing the *categories* an event belongs to.
22///
23/// A single [`PlotEvent`] may have several bits set.  For example a
24/// "click that set a measurement point" would have both `CLICK` and
25/// `MEASUREMENT_POINT` set.
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
27pub struct EventKind(pub u64);
28
29impl EventKind {
30    // ── Pointer / interaction ────────────────────────────────────────────
31    /// A single (primary) click anywhere on a scope plot.
32    pub const CLICK: Self = Self(1 << 0);
33    /// A double-click on a scope plot (the second click is also a `CLICK`).
34    pub const DOUBLE_CLICK: Self = Self(1 << 1);
35    /// A click that landed on (or snapped to) a specific curve/trace.
36    pub const CLICK_ON_TRACE: Self = Self(1 << 2);
37
38    // ── Pause / resume ──────────────────────────────────────────────────
39    /// The scope was paused (either by click or programmatically).
40    pub const PAUSE: Self = Self(1 << 3);
41    /// The scope was resumed.
42    pub const RESUME: Self = Self(1 << 4);
43
44    // ── Measurement ─────────────────────────────────────────────────────
45    /// A measurement marker point was set (P1 or P2).
46    pub const MEASUREMENT_POINT: Self = Self(1 << 5);
47    /// A full measurement (both P1 and P2) is now available.
48    pub const MEASUREMENT_COMPLETE: Self = Self(1 << 6);
49    /// A measurement was cleared.
50    pub const MEASUREMENT_CLEARED: Self = Self(1 << 7);
51
52    // ── Trace visibility / colour ───────────────────────────────────────
53    /// A trace was shown.
54    pub const TRACE_SHOWN: Self = Self(1 << 8);
55    /// A trace was hidden.
56    pub const TRACE_HIDDEN: Self = Self(1 << 9);
57    /// A trace colour was changed.
58    pub const TRACE_COLOR_CHANGED: Self = Self(1 << 10);
59
60    // ── Math traces ─────────────────────────────────────────────────────
61    /// A math trace was added.
62    pub const MATH_TRACE_ADDED: Self = Self(1 << 11);
63    /// A math trace was removed.
64    pub const MATH_TRACE_REMOVED: Self = Self(1 << 12);
65
66    // ── Zoom / view ─────────────────────────────────────────────────────
67    /// The view was zoomed (scroll-wheel, box-zoom, or programmatic).
68    pub const ZOOM: Self = Self(1 << 13);
69    /// The view was fit-to-data (auto-fit or button).
70    pub const FIT_TO_VIEW: Self = Self(1 << 14);
71    /// The view was panned.
72    pub const PAN: Self = Self(1 << 15);
73
74    // ── Resize / window ─────────────────────────────────────────────────
75    /// The plot widget was resized.
76    pub const RESIZE: Self = Self(1 << 16);
77
78    // ── Data ────────────────────────────────────────────────────────────
79    /// New data points were received for one or more traces.
80    pub const DATA_UPDATED: Self = Self(1 << 17);
81    /// All trace data was cleared.
82    pub const DATA_CLEARED: Self = Self(1 << 18);
83
84    // ── Thresholds ──────────────────────────────────────────────────────
85    /// A threshold event was detected (threshold exceeded condition met).
86    pub const THRESHOLD_EXCEEDED: Self = Self(1 << 19);
87    /// A threshold definition was added.
88    pub const THRESHOLD_ADDED: Self = Self(1 << 20);
89    /// A threshold definition was removed.
90    pub const THRESHOLD_REMOVED: Self = Self(1 << 21);
91
92    // ── Hotkeys / keyboard ──────────────────────────────────────────────
93    /// A keyboard key was pressed inside the plot area.
94    pub const KEY_PRESSED: Self = Self(1 << 22);
95
96    // ── Export / screenshot ─────────────────────────────────────────────
97    /// An export (CSV/Parquet) was initiated.
98    pub const EXPORT: Self = Self(1 << 23);
99    /// A screenshot was taken.
100    pub const SCREENSHOT: Self = Self(1 << 24);
101
102    // ── Scope management ────────────────────────────────────────────────
103    /// A scope was added.
104    pub const SCOPE_ADDED: Self = Self(1 << 25);
105    /// A scope was removed.
106    pub const SCOPE_REMOVED: Self = Self(1 << 26);
107
108    // ── Trigger ─────────────────────────────────────────────────────────
109    /// A trigger fired.
110    pub const TRIGGER_FIRED: Self = Self(1 << 27);
111
112    // ── Trace offset / style ────────────────────────────────────────────
113    /// A trace Y-offset was changed.
114    pub const TRACE_OFFSET_CHANGED: Self = Self(1 << 28);
115
116    // ── Y axis settings ─────────────────────────────────────────────────
117    /// Y-axis log mode was toggled.
118    pub const Y_LOG_CHANGED: Self = Self(1 << 29);
119    /// Y-axis unit was changed.
120    pub const Y_UNIT_CHANGED: Self = Self(1 << 30);
121
122    // ── Markers ─────────────────────────────────────────────────────────
123    /// A marker point was set or moved.
124    pub const MARKER_SET: Self = Self(1 << 31);
125    /// A marker was added.
126    pub const MARKER_ADDED: Self = Self(1 << 32);
127    /// A marker was removed.
128    pub const MARKER_REMOVED: Self = Self(1 << 33);
129    /// All markers were cleared.
130    pub const MARKER_CLEARED: Self = Self(1 << 34);
131
132    /// Wildcard: matches *every* event kind.
133    pub const ALL: Self = Self(u64::MAX);
134
135    /// Combine two event kinds (bitwise OR).
136    #[inline]
137    pub const fn union(self, other: Self) -> Self {
138        Self(self.0 | other.0)
139    }
140
141    /// Check whether `self` contains all bits in `other`.
142    #[inline]
143    pub const fn contains(self, other: Self) -> bool {
144        (self.0 & other.0) == other.0
145    }
146
147    /// Check whether `self` intersects with `other` (at least one bit in common).
148    #[inline]
149    pub const fn intersects(self, other: Self) -> bool {
150        (self.0 & other.0) != 0
151    }
152
153    /// Returns `true` if no bits are set.
154    #[inline]
155    pub const fn is_empty(self) -> bool {
156        self.0 == 0
157    }
158}
159
160impl std::ops::BitOr for EventKind {
161    type Output = Self;
162    #[inline]
163    fn bitor(self, rhs: Self) -> Self {
164        Self(self.0 | rhs.0)
165    }
166}
167
168impl std::ops::BitOrAssign for EventKind {
169    #[inline]
170    fn bitor_assign(&mut self, rhs: Self) {
171        self.0 |= rhs.0;
172    }
173}
174
175impl std::ops::BitAnd for EventKind {
176    type Output = Self;
177    #[inline]
178    fn bitand(self, rhs: Self) -> Self {
179        Self(self.0 & rhs.0)
180    }
181}
182
183impl std::ops::Not for EventKind {
184    type Output = Self;
185    #[inline]
186    fn not(self) -> Self {
187        Self(!self.0)
188    }
189}
190
191// ─────────────────────────────────────────────────────────────────────────────
192// String conversions
193// ─────────────────────────────────────────────────────────────────────────────
194
195impl std::fmt::Display for EventKind {
196    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
197        if self.is_empty() {
198            return write!(f, "EMPTY");
199        }
200
201        // The ALL constant is a useful shorthand; print it directly instead
202        if *self == EventKind::ALL {
203            return write!(f, "ALL");
204        }
205
206        // Known kinds with their string names in declaration order.
207        let pairs: &[(EventKind, &str)] = &[
208            (EventKind::CLICK, "CLICK"),
209            (EventKind::DOUBLE_CLICK, "DOUBLE_CLICK"),
210            (EventKind::CLICK_ON_TRACE, "CLICK_ON_TRACE"),
211            (EventKind::PAUSE, "PAUSE"),
212            (EventKind::RESUME, "RESUME"),
213            (EventKind::MEASUREMENT_POINT, "MEASUREMENT_POINT"),
214            (EventKind::MEASUREMENT_COMPLETE, "MEASUREMENT_COMPLETE"),
215            (EventKind::MEASUREMENT_CLEARED, "MEASUREMENT_CLEARED"),
216            (EventKind::TRACE_SHOWN, "TRACE_SHOWN"),
217            (EventKind::TRACE_HIDDEN, "TRACE_HIDDEN"),
218            (EventKind::TRACE_COLOR_CHANGED, "TRACE_COLOR_CHANGED"),
219            (EventKind::MATH_TRACE_ADDED, "MATH_TRACE_ADDED"),
220            (EventKind::MATH_TRACE_REMOVED, "MATH_TRACE_REMOVED"),
221            (EventKind::ZOOM, "ZOOM"),
222            (EventKind::FIT_TO_VIEW, "FIT_TO_VIEW"),
223            (EventKind::PAN, "PAN"),
224            (EventKind::RESIZE, "RESIZE"),
225            (EventKind::DATA_UPDATED, "DATA_UPDATED"),
226            (EventKind::DATA_CLEARED, "DATA_CLEARED"),
227            (EventKind::THRESHOLD_EXCEEDED, "THRESHOLD_EXCEEDED"),
228            (EventKind::THRESHOLD_ADDED, "THRESHOLD_ADDED"),
229            (EventKind::THRESHOLD_REMOVED, "THRESHOLD_REMOVED"),
230            (EventKind::KEY_PRESSED, "KEY_PRESSED"),
231            (EventKind::EXPORT, "EXPORT"),
232            (EventKind::SCREENSHOT, "SCREENSHOT"),
233            (EventKind::SCOPE_ADDED, "SCOPE_ADDED"),
234            (EventKind::SCOPE_REMOVED, "SCOPE_REMOVED"),
235            (EventKind::TRIGGER_FIRED, "TRIGGER_FIRED"),
236            (EventKind::TRACE_OFFSET_CHANGED, "TRACE_OFFSET_CHANGED"),
237            (EventKind::Y_LOG_CHANGED, "Y_LOG_CHANGED"),
238            (EventKind::Y_UNIT_CHANGED, "Y_UNIT_CHANGED"),
239            (EventKind::MARKER_SET, "MARKER_SET"),
240            (EventKind::MARKER_ADDED, "MARKER_ADDED"),
241            (EventKind::MARKER_REMOVED, "MARKER_REMOVED"),
242            (EventKind::MARKER_CLEARED, "MARKER_CLEARED"),
243        ];
244
245        let mut names = Vec::new();
246        let mut known_bits: u64 = 0;
247
248        for (kind, name) in pairs {
249            known_bits |= kind.0;
250            if self.contains(*kind) {
251                names.push((*name).to_string());
252            }
253        }
254
255        // Bits that weren't covered by the known list
256        let extra = self.0 & !known_bits;
257        if extra != 0 {
258            names.push(format!("0x{:x}", extra));
259        }
260
261        if names.is_empty() {
262            // No named bits and not ALL (handled above) -> just show hex
263            write!(f, "0x{:x}", self.0)
264        } else {
265            write!(f, "{}", names.join("|"))
266        }
267    }
268}
269
270// ─────────────────────────────────────────────────────────────────────────────
271// Metadata – per-event-type payloads
272// ─────────────────────────────────────────────────────────────────────────────
273
274/// Screen (pixel) coordinates.
275#[derive(Debug, Clone, Copy, PartialEq)]
276pub struct ScreenPos {
277    pub x: f32,
278    pub y: f32,
279}
280
281/// Plot-space coordinates.
282#[derive(Debug, Clone, Copy, PartialEq)]
283pub struct PlotPos {
284    pub x: f64,
285    pub y: f64,
286}
287
288/// Metadata attached to click / pointer events.
289#[derive(Debug, Clone)]
290pub struct ClickMeta {
291    /// Screen coordinates of the click (pixels within the window).
292    pub screen_pos: Option<ScreenPos>,
293    /// Plot-space coordinates of the click.
294    pub plot_pos: Option<PlotPos>,
295    /// If the click snapped to a trace, name of that trace.
296    pub trace: Option<TraceRef>,
297    /// Scope that was clicked (by id).
298    pub scope_id: Option<usize>,
299}
300
301/// Metadata for measurement-point events.
302#[derive(Debug, Clone)]
303pub struct MeasurementMeta {
304    /// Which point index was set (0 = P1, 1 = P2).
305    pub point_index: usize,
306    /// Coordinates of the point that was set.
307    pub point: [f64; 2],
308    /// If a full measurement is available, the two points.
309    pub p1: Option<[f64; 2]>,
310    pub p2: Option<[f64; 2]>,
311    /// Delta X between P1 and P2 (only valid when both points exist).
312    pub delta_x: Option<f64>,
313    /// Delta Y between P1 and P2.
314    pub delta_y: Option<f64>,
315    /// Slope (dy/dx) between the two points.
316    pub slope: Option<f64>,
317    /// Euclidean distance between the two points.
318    pub distance: Option<f64>,
319    /// Name of the measurement.
320    pub measurement_name: Option<String>,
321    /// Trace that the measurement is snapping to (if any).
322    pub trace: Option<TraceRef>,
323}
324
325/// Metadata for zoom / pan / fit events.
326#[derive(Debug, Clone)]
327pub struct ViewChangeMeta {
328    /// New visible X range after the change.
329    pub x_range: Option<(f64, f64)>,
330    /// New visible Y range after the change.
331    pub y_range: Option<(f64, f64)>,
332    /// Scope id that was zoomed/panned.
333    pub scope_id: Option<usize>,
334    /// The scope type (TimeScope or XYScope) at the time of the change.
335    pub scope_type: Option<crate::data::scope::ScopeType>,
336}
337
338/// Metadata for trace visibility / colour events.
339#[derive(Debug, Clone)]
340pub struct TraceMeta {
341    /// Name of the trace that changed.
342    pub trace: TraceRef,
343    /// New visibility state (for show/hide events).
344    pub visible: Option<bool>,
345    /// New colour (for colour change events).
346    pub color_rgb: Option<[u8; 3]>,
347    /// New Y-offset (for offset change events).
348    pub offset: Option<f64>,
349}
350
351/// Metadata for math trace events.
352#[derive(Debug, Clone)]
353pub struct MathTraceMeta {
354    /// Name of the math trace.
355    pub name: String,
356    /// Formula / expression string (if available).
357    pub formula: Option<String>,
358}
359
360/// Metadata for resize events.
361#[derive(Debug, Clone, Copy)]
362pub struct ResizeMeta {
363    /// New size in logical pixels.
364    pub width: f32,
365    pub height: f32,
366}
367
368/// Metadata for data-update events.
369#[derive(Debug, Clone)]
370pub struct DataUpdateMeta {
371    /// Traces that received new data.
372    pub traces: Vec<TraceRef>,
373    /// Total number of new points across all traces (approximate).
374    pub new_point_count: usize,
375}
376
377/// Metadata for threshold events.
378#[derive(Debug, Clone)]
379pub struct ThresholdMeta {
380    /// Name of the threshold.
381    pub threshold_name: String,
382    /// Trace being monitored.
383    pub trace: Option<TraceRef>,
384    /// Start time of the threshold event (seconds).
385    pub start_t: Option<f64>,
386    /// End time (seconds).
387    pub end_t: Option<f64>,
388    /// Duration (seconds).
389    pub duration: Option<f64>,
390    /// Integrated area.
391    pub area: Option<f64>,
392}
393
394/// Metadata for key-press events.
395#[derive(Debug, Clone)]
396pub struct KeyPressMeta {
397    /// The key that was pressed (as egui key name or char).
398    pub key: String,
399    /// Modifier state.
400    pub modifiers: KeyModifiers,
401}
402
403/// Keyboard modifier state.
404#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
405pub struct KeyModifiers {
406    pub ctrl: bool,
407    pub alt: bool,
408    pub shift: bool,
409    pub command: bool,
410}
411
412/// Metadata for export events.
413#[derive(Debug, Clone)]
414pub struct ExportMeta {
415    /// Format of the export ("csv", "parquet", "png").
416    pub format: String,
417    /// Path where the export was saved (if known).
418    pub path: Option<String>,
419}
420
421/// Metadata for scope management events.
422#[derive(Debug, Clone)]
423pub struct ScopeManageMeta {
424    /// Scope id.
425    pub scope_id: usize,
426    /// Scope name.
427    pub scope_name: Option<String>,
428}
429
430/// Metadata for trigger events.
431#[derive(Debug, Clone)]
432pub struct TriggerMeta {
433    /// Trigger name.
434    pub trigger_name: String,
435    /// Trace being monitored.
436    pub trace: Option<TraceRef>,
437    /// Timestamp at which the trigger fired.
438    pub timestamp: Option<f64>,
439}
440
441/// Metadata for Y-axis setting changes.
442#[derive(Debug, Clone)]
443pub struct YAxisMeta {
444    /// New Y-log state (if changed).
445    pub y_log: Option<bool>,
446    /// New Y-unit (if changed).
447    pub y_unit: Option<Option<String>>,
448}
449
450/// Metadata for pause/resume events.
451#[derive(Debug, Clone)]
452pub struct PauseMeta {
453    /// Scope id that was paused/resumed.
454    pub scope_id: Option<usize>,
455}
456
457/// Metadata for marker events.
458#[derive(Debug, Clone)]
459pub struct MarkerMeta {
460    /// Name of the marker.
461    pub name: String,
462    /// Marker position in plot coordinates (None when cleared/unplaced).
463    pub point: Option<[f64; 2]>,
464    /// Scope the marker was placed on (if any).
465    pub scope_id: Option<usize>,
466    /// Trace the marker snaps to (if any).
467    pub trace: Option<TraceRef>,
468    /// Marker color (RGBA) for add/set events.
469    pub color_rgba: Option<[u8; 4]>,
470    /// Marker visibility (for visibility-toggle events).
471    pub visible: Option<bool>,
472}
473
474// ─────────────────────────────────────────────────────────────────────────────
475// PlotEvent – the top-level event type
476// ─────────────────────────────────────────────────────────────────────────────
477
478/// A rich event emitted by the LivePlot UI.
479///
480/// `kinds` is a bitflag set of [`EventKind`] categories.  The various
481/// `Option<…Meta>` fields carry metadata relevant to the kinds that are set.
482#[derive(Debug, Clone)]
483pub struct PlotEvent {
484    /// Bitflag set of categories this event belongs to.
485    pub kinds: EventKind,
486    /// Monotonic timestamp (seconds since app start, from `std::time::Instant`).
487    pub timestamp: f64,
488
489    // ── Optional metadata ────────────────────────────────────────────────
490    pub click: Option<ClickMeta>,
491    pub measurement: Option<MeasurementMeta>,
492    pub view_change: Option<ViewChangeMeta>,
493    pub trace: Option<TraceMeta>,
494    pub math_trace: Option<MathTraceMeta>,
495    pub resize: Option<ResizeMeta>,
496    pub data_update: Option<DataUpdateMeta>,
497    pub threshold: Option<ThresholdMeta>,
498    pub key_press: Option<KeyPressMeta>,
499    pub export: Option<ExportMeta>,
500    pub scope_manage: Option<ScopeManageMeta>,
501    pub trigger: Option<TriggerMeta>,
502    pub y_axis: Option<YAxisMeta>,
503    pub pause: Option<PauseMeta>,
504    pub marker: Option<MarkerMeta>,
505}
506
507impl PlotEvent {
508    /// Create a new event with the given kinds and current timestamp.
509    pub fn new(kinds: EventKind) -> Self {
510        Self {
511            kinds,
512            timestamp: 0.0, // will be set by controller
513            click: None,
514            measurement: None,
515            view_change: None,
516            trace: None,
517            math_trace: None,
518            resize: None,
519            data_update: None,
520            threshold: None,
521            key_press: None,
522            export: None,
523            scope_manage: None,
524            trigger: None,
525            y_axis: None,
526            pause: None,
527            marker: None,
528        }
529    }
530}
531
532// ─────────────────────────────────────────────────────────────────────────────
533// EventFilter
534// ─────────────────────────────────────────────────────────────────────────────
535
536/// A filter that selects which event categories a subscriber receives.
537///
538/// The filter is an OR-mask: an event is delivered when
539/// `event.kinds.intersects(filter.mask)`.
540#[derive(Debug, Clone, Copy)]
541pub struct EventFilter {
542    pub mask: EventKind,
543}
544
545impl EventFilter {
546    /// Accept all events.
547    pub const fn all() -> Self {
548        Self {
549            mask: EventKind::ALL,
550        }
551    }
552
553    /// Accept only the specified event kinds.
554    pub const fn only(mask: EventKind) -> Self {
555        Self { mask }
556    }
557
558    /// Check whether an event passes this filter.
559    #[inline]
560    pub fn matches(&self, event: &PlotEvent) -> bool {
561        event.kinds.intersects(self.mask)
562    }
563}
564
565impl Default for EventFilter {
566    fn default() -> Self {
567        Self::all()
568    }
569}
570
571// ─────────────────────────────────────────────────────────────────────────────
572// EventController
573// ─────────────────────────────────────────────────────────────────────────────
574
575pub(crate) struct Subscriber {
576    filter: EventFilter,
577    sender: Sender<PlotEvent>,
578}
579
580/// Controller that collects and distributes UI events to subscribers.
581///
582/// Attach it to [`LivePlotConfig`](crate::config::LivePlotConfig) before
583/// launching the UI.  Then call [`subscribe`](Self::subscribe) (with an
584/// optional filter) to receive events on an `mpsc` channel.
585#[derive(Clone)]
586pub struct EventController {
587    pub(crate) inner: Arc<Mutex<EventCtrlInner>>,
588}
589
590pub(crate) struct EventCtrlInner {
591    pub(crate) subscribers: Vec<Subscriber>,
592    pub(crate) start_instant: std::time::Instant,
593    /// Last known plot size, used to detect resize events.
594    pub(crate) last_size: Option<[f32; 2]>,
595}
596
597impl EventController {
598    /// Create a new event controller.
599    pub fn new() -> Self {
600        Self {
601            inner: Arc::new(Mutex::new(EventCtrlInner {
602                subscribers: Vec::new(),
603                start_instant: std::time::Instant::now(),
604                last_size: None,
605            })),
606        }
607    }
608
609    /// Subscribe to events matching the given filter.
610    ///
611    /// Returns a receiver that will receive [`PlotEvent`]s whenever the UI
612    /// emits an event whose `kinds` intersect with the filter mask.
613    pub fn subscribe(&self, filter: EventFilter) -> Receiver<PlotEvent> {
614        let (tx, rx) = std::sync::mpsc::channel();
615        let mut inner = self.inner.lock().unwrap();
616        inner.subscribers.push(Subscriber { filter, sender: tx });
617        rx
618    }
619
620    /// Subscribe to *all* events (no filtering).
621    pub fn subscribe_all(&self) -> Receiver<PlotEvent> {
622        self.subscribe(EventFilter::all())
623    }
624
625    /// Emit an event to all matching subscribers.
626    ///
627    /// This is called internally by the LivePlot UI.  External code normally
628    /// does *not* need to call this, but it is public so that custom panels or
629    /// embedding code can inject synthetic events.
630    pub fn emit(&self, mut event: PlotEvent) {
631        let mut inner = self.inner.lock().unwrap();
632        event.timestamp = inner.start_instant.elapsed().as_secs_f64();
633        // Retain only subscribers whose channel is still open.
634        inner.subscribers.retain(|sub| {
635            if sub.filter.matches(&event) {
636                sub.sender.send(event.clone()).is_ok()
637            } else {
638                // Check if channel is still alive by checking the sender.
639                // We keep subscribers even if this particular event doesn't match.
640                !sub.sender.send(event.clone()).is_err() || true
641            }
642        });
643    }
644
645    /// Internal: emit only to subscribers whose filter matches (avoids sending
646    /// non-matching events that would just be discarded).
647    pub fn emit_filtered(&self, mut event: PlotEvent) {
648        let mut inner = self.inner.lock().unwrap();
649        event.timestamp = inner.start_instant.elapsed().as_secs_f64();
650        inner.subscribers.retain(|sub| {
651            if sub.filter.matches(&event) {
652                sub.sender.send(event.clone()).is_ok()
653            } else {
654                // Channel open check: try a zero-cost probe.
655                // We can't easily probe without sending, so we just keep the subscriber.
656                true
657            }
658        });
659    }
660}
661
662impl Default for EventController {
663    fn default() -> Self {
664        Self::new()
665    }
666}
667
668// ─────────────────────────────────────────────────────────────────────────────