pub struct LivePlotApp {
pub main_panel: LivePlotPanel,
pub window_ctrl: Option<WindowController>,
pub ui_ctrl: Option<UiActionController>,
pub traces_ctrl: Option<TracesController>,
pub scopes_ctrl: Option<ScopesController>,
pub liveplot_ctrl: Option<LiveplotController>,
pub fft_ctrl: Option<FFTController>,
pub threshold_ctrl: Option<ThresholdController>,
pub headline: Option<String>,
pub subheadline: Option<String>,
pub color_scheme: Option<ColorScheme>,
/* private fields */
}Expand description
Standalone LivePlot application that implements eframe::App.
LivePlotApp is the top-level container used when LivePlot runs in its own
native window (via run_liveplot). It:
- Owns a
LivePlotPanelthat does the actual rendering. - Holds optional controller handles for programmatic interaction.
- Processes controller requests each frame in
apply_controllers. - Applies initial configuration from
LivePlotConfig.
Fields§
§main_panel: LivePlotPanelThe inner panel widget that owns all data and UI state.
window_ctrl: Option<WindowController>Controls the host window (size, position).
ui_ctrl: Option<UiActionController>Programmatic UI actions (pause, screenshot, export).
traces_ctrl: Option<TracesController>Programmatic trace manipulation (colour, visibility, offset, etc.).
scopes_ctrl: Option<ScopesController>Programmatic scope management (add/remove/configure scopes).
liveplot_ctrl: Option<LiveplotController>High-level liveplot control (pause all, clear all, save/load state).
fft_ctrl: Option<FFTController>FFT panel control (show/hide, resize).
threshold_ctrl: Option<ThresholdController>Threshold management (add/remove thresholds, listen for threshold events).
headline: Option<String>Optional heading text shown at the top of the window.
subheadline: Option<String>Optional sub-heading text shown below the headline.
color_scheme: Option<ColorScheme>Color scheme to apply to the egui context. Applied once on the first frame.
Implementations§
Source§impl LivePlotApp
impl LivePlotApp
Sourcepub fn new(rx: Receiver<PlotCommand>) -> Self
pub fn new(rx: Receiver<PlotCommand>) -> Self
Create a new LivePlotApp without any controllers.
Examples found in repository?
37 fn new() -> Self {
38 let (sink, rx) = channel_plot();
39 let trace_sine = sink.create_trace("sine", None);
40 let trace_cos = sink.create_trace("cosine", None);
41 let mut plot = LivePlotApp::new(rx);
42 // Configure the embedded main panel's data
43 for scope in plot.main_panel.liveplot_panel.get_data_mut() {
44 scope.time_window = 10.0;
45 }
46 plot.main_panel.traces_data.max_points = 10_000;
47 Self {
48 kind: WaveKind::Sine,
49 sink,
50 trace_sine,
51 trace_cos,
52 plot,
53 show_plot_window: false,
54 }
55 }More examples
81fn main() -> eframe::Result<()> {
82 let scheme = std::env::args()
83 .nth(1)
84 .map(|a| parse_scheme(&a))
85 .unwrap_or(ColorScheme::Dark);
86
87 let (sink, rx) = channel_plot();
88 let tr_sine = sink.create_trace("sine", None);
89 let tr_cos = sink.create_trace("cosine", None);
90
91 // Producer: 1 kHz, 3 Hz sine + cosine
92 std::thread::spawn(move || {
93 const FS_HZ: f64 = 1000.0;
94 const F_HZ: f64 = 3.0;
95 let dt = Duration::from_millis(1);
96 let mut n: u64 = 0;
97 loop {
98 let t = n as f64 / FS_HZ;
99 let s_val = (2.0 * std::f64::consts::PI * F_HZ * t).sin();
100 let c_val = (2.0 * std::f64::consts::PI * F_HZ * t).cos();
101 let t_s = SystemTime::now()
102 .duration_since(UNIX_EPOCH)
103 .map(|d| d.as_secs_f64())
104 .unwrap_or(0.0);
105 let _ = sink.send_point(&tr_sine, PlotPoint { x: t_s, y: s_val });
106 let _ = sink.send_point(&tr_cos, PlotPoint { x: t_s, y: c_val });
107 n = n.wrapping_add(1);
108 std::thread::sleep(dt);
109 }
110 });
111
112 let plot = LivePlotApp::new(rx);
113 let app = ColorSchemePickerApp { scheme, plot };
114
115 eframe::run_native(
116 "Color Scheme Demo",
117 eframe::NativeOptions::default(),
118 Box::new(|_cc| Ok(Box::new(app))),
119 )
120}37 fn new() -> Self {
38 // create shared sink/receiver pair and register traces
39 let (sink, rx) = channel_plot();
40 let tr_sine = sink.create_trace("sine", None);
41 let tr_cos = sink.create_trace("cosine", None);
42
43 // spawn the producer thread (1 kHz sample rate as in sine_cosine.rs)
44 let sink_clone = sink.clone();
45 let sine_clone = tr_sine.clone();
46 let cos_clone = tr_cos.clone();
47 std::thread::spawn(move || {
48 const FS_HZ: f64 = 1000.0;
49 const F_HZ: f64 = 3.0;
50 let dt = Duration::from_millis(1);
51 let mut n: u64 = 0;
52 loop {
53 let t = n as f64 / FS_HZ;
54 let s_val = (2.0 * std::f64::consts::PI * F_HZ * t).sin();
55 let c_val = (2.0 * std::f64::consts::PI * F_HZ * t).cos();
56 let t_s = SystemTime::now()
57 .duration_since(UNIX_EPOCH)
58 .map(|d| d.as_secs_f64())
59 .unwrap_or(0.0);
60 let _ = sink_clone.send_point(&sine_clone, PlotPoint { x: t_s, y: s_val });
61 let _ = sink_clone.send_point(&cos_clone, PlotPoint { x: t_s, y: c_val });
62 n = n.wrapping_add(1);
63 std::thread::sleep(dt);
64 }
65 });
66
67 let plot = LivePlotApp::new(rx);
68 let features = FeatureFlags::default();
69
70 Self {
71 plot,
72 features,
73 _sink: sink,
74 _tr_sine: tr_sine,
75 _tr_cos: tr_cos,
76 }
77 }Sourcepub fn with_controllers(
rx: Receiver<PlotCommand>,
window_ctrl: Option<WindowController>,
ui_ctrl: Option<UiActionController>,
traces_ctrl: Option<TracesController>,
scopes_ctrl: Option<ScopesController>,
liveplot_ctrl: Option<LiveplotController>,
fft_ctrl: Option<FFTController>,
threshold_ctrl: Option<ThresholdController>,
) -> Self
pub fn with_controllers( rx: Receiver<PlotCommand>, window_ctrl: Option<WindowController>, ui_ctrl: Option<UiActionController>, traces_ctrl: Option<TracesController>, scopes_ctrl: Option<ScopesController>, liveplot_ctrl: Option<LiveplotController>, fft_ctrl: Option<FFTController>, threshold_ctrl: Option<ThresholdController>, ) -> Self
Create a new LivePlotApp with the given controller handles already wired.
Trait Implementations§
Source§impl App for LivePlotApp
impl App for LivePlotApp
Source§fn update(&mut self, ctx: &Context, frame: &mut Frame)
fn update(&mut self, ctx: &Context, frame: &mut Frame)
Source§fn save(&mut self, _storage: &mut dyn Storage)
fn save(&mut self, _storage: &mut dyn Storage)
Source§fn on_exit(&mut self, _gl: Option<&Context>)
fn on_exit(&mut self, _gl: Option<&Context>)
Self::save. Read moreSource§fn auto_save_interval(&self) -> Duration
fn auto_save_interval(&self) -> Duration
Self::saveSource§fn clear_color(&self, _visuals: &Visuals) -> [f32; 4]
fn clear_color(&self, _visuals: &Visuals) -> [f32; 4]
gl.clearColor. Read moreSource§fn persist_egui_memory(&self) -> bool
fn persist_egui_memory(&self) -> bool
Source§fn raw_input_hook(&mut self, _ctx: &Context, _raw_input: &mut RawInput)
fn raw_input_hook(&mut self, _ctx: &Context, _raw_input: &mut RawInput)
Self::update. Read moreAuto Trait Implementations§
impl Freeze for LivePlotApp
impl !RefUnwindSafe for LivePlotApp
impl !Send for LivePlotApp
impl !Sync for LivePlotApp
impl Unpin for LivePlotApp
impl UnsafeUnpin for LivePlotApp
impl !UnwindSafe for LivePlotApp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more