tof_control/tui/
ltb_ui.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use ratatui::{
    prelude::*,
    widgets::*,
};

use crate::tui::rat_app::App;

pub fn draw_ltb_tab(f: &mut Frame, app: &mut App, area: Rect) {
    let chunks = Layout::default()
        .constraints([
            Constraint::Percentage(50),
            Constraint::Percentage(50),
        ])
        .direction(Direction::Horizontal)
        .split(area);

    // draw_ltb_info(f, chunks[0]);
    draw_ltb_temp(f, app, chunks[0]);
    draw_ltb_threshold(f, app, chunks[1]);
}

fn draw_ltb_temp(f: &mut Frame, app: &mut App, area: Rect) {
    let ltb_temp = &app.ltb_data.temp;
    let mut ltb_temp_list_items = Vec::<ListItem>::new();
    ltb_temp_list_items.push(ListItem::new(Line::from(Span::styled(format!("Trenz Temp: {:.3}[°C]", ltb_temp.trenz_temp), Style::default()))));
    ltb_temp_list_items.push(ListItem::new(Line::from(Span::styled(format!("Board Temp: {:.3}[°C]", ltb_temp.board_temp), Style::default()))));

    let ltb_temp_list = List::new(ltb_temp_list_items)
    .block(Block::default().borders(Borders::ALL).title(Span::styled("LTB Temp", 
    Style::default().fg(Color::Magenta).add_modifier(Modifier::BOLD))));

    f.render_widget(ltb_temp_list, area)
}

fn draw_ltb_threshold(f: &mut Frame, app: &mut App, area: Rect) {
    let ltb_threshold = &app.ltb_data.threshold;
    let mut ltb_threshold_list_items = Vec::<ListItem>::new();
    ltb_threshold_list_items.push(ListItem::new(Line::from(Span::styled(format!("Threshold 0: {:.3}[mV]", ltb_threshold.thresh_0), Style::default()))));
    ltb_threshold_list_items.push(ListItem::new(Line::from(Span::styled(format!("Threshold 1: {:.3}[mV]", ltb_threshold.thresh_1), Style::default()))));
    ltb_threshold_list_items.push(ListItem::new(Line::from(Span::styled(format!("Threshold 2: {:.3}[mV]", ltb_threshold.thresh_2), Style::default()))));

    let ltb_threshold_list = List::new(ltb_threshold_list_items)
        .block(Block::default().borders(Borders::ALL).title(Span::styled("LTB Threshold", 
        Style::default().fg(Color::Magenta).add_modifier(Modifier::BOLD))));

    f.render_widget(ltb_threshold_list, area)
}