+54
-36
src/app.rs
+54
-36
src/app.rs
···
97
Oscilloscope,
98
Vectorscope,
99
Spectroscope,
100
}
101
102
pub struct App {
···
316
let mut datasets = Vec::new();
317
let graph = self.graph.clone(); // TODO cheap fix...
318
if self.graph.references {
319
-
datasets.append(&mut self.current_display_mut().references(&graph));
320
}
321
-
datasets.append(&mut self.current_display_mut().process(&graph, &channels));
322
terminal
323
.draw(|f| {
324
let mut size = f.size();
325
render_frame(new_state.clone(), f);
326
-
if self.graph.show_ui {
327
-
f.render_widget(
328
-
make_header(
329
-
&self.graph,
330
-
&self.current_display().header(&self.graph),
331
-
self.current_display().mode_str(),
332
-
framerate,
333
-
self.graph.pause,
334
-
),
335
-
Rect {
336
-
x: size.x,
337
-
y: size.y + 6,
338
-
width: size.width,
339
-
height: 1,
340
-
},
341
-
);
342
-
size.height -= 7;
343
-
size.y += 7;
344
}
345
-
let chart = Chart::new(datasets.iter().map(|x| x.into()).collect())
346
-
.x_axis(self.current_display().axis(&self.graph, Dimension::X)) // TODO allow to have axis sometimes?
347
-
.y_axis(self.current_display().axis(&self.graph, Dimension::Y));
348
-
f.render_widget(chart, size)
349
})
350
.unwrap();
351
}
···
360
{
361
return;
362
}
363
-
self.current_display_mut().handle(event);
364
}
365
}
366
}
367
368
-
fn current_display_mut(&mut self) -> &mut dyn DisplayMode {
369
match self.mode {
370
-
CurrentDisplayMode::Oscilloscope => &mut self.oscilloscope as &mut dyn DisplayMode,
371
-
CurrentDisplayMode::Vectorscope => &mut self.vectorscope as &mut dyn DisplayMode,
372
-
CurrentDisplayMode::Spectroscope => &mut self.spectroscope as &mut dyn DisplayMode,
373
}
374
}
375
376
-
fn current_display(&self) -> &dyn DisplayMode {
377
match self.mode {
378
-
CurrentDisplayMode::Oscilloscope => &self.oscilloscope as &dyn DisplayMode,
379
-
CurrentDisplayMode::Vectorscope => &self.vectorscope as &dyn DisplayMode,
380
-
CurrentDisplayMode::Spectroscope => &self.spectroscope as &dyn DisplayMode,
381
}
382
}
383
···
477
// switch modes
478
match self.mode {
479
CurrentDisplayMode::Oscilloscope => {
480
-
self.mode = CurrentDisplayMode::Vectorscope
481
}
482
CurrentDisplayMode::Vectorscope => {
483
-
self.mode = CurrentDisplayMode::Spectroscope
484
}
485
CurrentDisplayMode::Spectroscope => {
486
-
self.mode = CurrentDisplayMode::Oscilloscope
487
}
488
}
489
}
···
97
Oscilloscope,
98
Vectorscope,
99
Spectroscope,
100
+
None,
101
}
102
103
pub struct App {
···
317
let mut datasets = Vec::new();
318
let graph = self.graph.clone(); // TODO cheap fix...
319
if self.graph.references {
320
+
if let Some(current_display) = self.current_display() {
321
+
datasets.append(&mut current_display.references(&graph));
322
+
}
323
}
324
+
if let Some(current_display) = self.current_display_mut() {
325
+
datasets.append(&mut current_display.process(&graph, &channels));
326
+
}
327
terminal
328
.draw(|f| {
329
let mut size = f.size();
330
render_frame(new_state.clone(), f);
331
+
if let Some(current_display) = self.current_display() {
332
+
if self.graph.show_ui {
333
+
f.render_widget(
334
+
make_header(
335
+
&self.graph,
336
+
¤t_display.header(&self.graph),
337
+
current_display.mode_str(),
338
+
framerate,
339
+
self.graph.pause,
340
+
),
341
+
Rect {
342
+
x: size.x,
343
+
y: size.y + 7,
344
+
width: size.width,
345
+
height: 1,
346
+
},
347
+
);
348
+
size.height -= 8;
349
+
size.y += 8;
350
+
}
351
+
let chart = Chart::new(datasets.iter().map(|x| x.into()).collect())
352
+
.x_axis(current_display.axis(&self.graph, Dimension::X)) // TODO allow to have axis sometimes?
353
+
.y_axis(current_display.axis(&self.graph, Dimension::Y));
354
+
f.render_widget(chart, size)
355
}
356
})
357
.unwrap();
358
}
···
367
{
368
return;
369
}
370
+
if let Some(current_display) = self.current_display_mut() {
371
+
current_display.handle(event);
372
+
}
373
}
374
}
375
}
376
377
+
fn current_display_mut(&mut self) -> Option<&mut dyn DisplayMode> {
378
match self.mode {
379
+
CurrentDisplayMode::Oscilloscope => {
380
+
Some(&mut self.oscilloscope as &mut dyn DisplayMode)
381
+
}
382
+
CurrentDisplayMode::Vectorscope => Some(&mut self.vectorscope as &mut dyn DisplayMode),
383
+
CurrentDisplayMode::Spectroscope => {
384
+
Some(&mut self.spectroscope as &mut dyn DisplayMode)
385
+
}
386
+
CurrentDisplayMode::None => None,
387
}
388
}
389
390
+
fn current_display(&self) -> Option<&dyn DisplayMode> {
391
match self.mode {
392
+
CurrentDisplayMode::Oscilloscope => Some(&self.oscilloscope as &dyn DisplayMode),
393
+
CurrentDisplayMode::Vectorscope => Some(&self.vectorscope as &dyn DisplayMode),
394
+
CurrentDisplayMode::Spectroscope => Some(&self.spectroscope as &dyn DisplayMode),
395
+
CurrentDisplayMode::None => None,
396
}
397
}
398
···
492
// switch modes
493
match self.mode {
494
CurrentDisplayMode::Oscilloscope => {
495
+
self.mode = CurrentDisplayMode::Vectorscope;
496
}
497
CurrentDisplayMode::Vectorscope => {
498
+
self.mode = CurrentDisplayMode::Spectroscope;
499
}
500
CurrentDisplayMode::Spectroscope => {
501
+
self.mode = CurrentDisplayMode::None;
502
+
}
503
+
CurrentDisplayMode::None => {
504
+
self.mode = CurrentDisplayMode::Oscilloscope;
505
}
506
}
507
}