tof_control/tui/
rat_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use ratatui::{
    prelude::*,
    widgets::*,
};

use crate::tui::rat_app::App;
use crate::tui::rb_ui::*;
use crate::tui::ltb_ui::*;
use crate::tui::pb_ui::*;
use crate::tui::pa_ui::*;

pub fn draw(f: &mut Frame, app: &mut App) {
    let chunks = Layout::default()
        .direction(Direction::Vertical)
        .constraints([
            Constraint::Length(3),
            Constraint::Min(0),
            Constraint::Length(4)
        ])
        .split(f.size());

    let titles = app
        .tabs
        .titles
        .iter()
        .map(|t| text::Line::from(Span::styled(*t, Style::default().fg(Color::Green))))
        .collect();
    
    let tabs = Tabs::new(titles)
        .block(Block::default().borders(Borders::ALL).title(app.title))
        .highlight_style(Style::default().fg(Color::Yellow))
        .select(app.tabs.index);

    f.render_widget(tabs, chunks[0]);

    match app.tabs.titles.len() {
        1 => {
            draw_rb_tab(f, app, chunks[1])
        }
        2 => {
            match app.tabs.index {
                0 => draw_rb_tab(f, app, chunks[1]),
                1 => draw_ltb_tab(f, app, chunks[1]),
                _ => {},
            }
        }
        3 => {
            match app.tabs.index {
                0 => draw_rb_tab(f, app, chunks[1]),
                1 => draw_pb_tab(f, app, chunks[1]),
                2 => draw_pa_tab(f, app, chunks[1]),
                _ => {},
            }
        }
        _ => {}
    }

    let footer = Paragraph::new(format!(
        "Press `q` to stop running.\n\
        Press `r` to reload the sensor values."
    ))
    .block(
        Block::default()
            .title("Operation")
            .title_alignment(Alignment::Left)
            .borders(Borders::ALL)
    );

    f.render_widget(footer, chunks[2]);

}