fn build_tab_airplanes<A: tui::backend::Backend>(
    f: &mut tui::Frame<A>,
    chunks: Vec<Rect>,
    adsb_airplanes: &Airplanes,
    airplanes_state: &mut TableState,
) {
    let mut rows = vec![];
    // make a vec of all strings to get a total amount of airplanes with
    // position information
    let empty = "".to_string();
    for key in adsb_airplanes.0.keys() {
        let state = adsb_airplanes.0.get(key).unwrap();
        let pos = adsb_airplanes.aircraft_details(*key);
        let mut lat = empty.clone();
        let mut lon = empty.clone();
        let mut alt = empty.clone();
        let mut s_kilo_distance = empty.clone();
        if let Some((position, altitude, kilo_distance)) = pos {
            lat = format!("{:.3}", position.latitude);
            lon = format!("{:.3}", position.longitude);
            s_kilo_distance = format!("{}", kilo_distance);
            alt = format!("{altitude}");
        }
        rows.push(Row::new(vec![
            format!("{key}"),
            state.callsign.as_ref().unwrap_or(&empty).clone(),
            lat,
            lon,
            format!("{alt:>8}"),
            state
                .vert_speed
                .map_or_else(|| "".into(), |v| format!("{v:>6}")),
            state
                .speed
                .map_or_else(|| "".into(), |v| format!("{v:>5.0}")),
            format!("{:>8}", s_kilo_distance),
            format!("{:>8}", state.num_messages),
        ]));
    }

    let rows_len = rows.len();

    // check the length of selected airplanes
    if let Some(selected) = airplanes_state.selected() {
        if selected > rows_len - 1 {
            airplanes_state.select(Some(rows_len - 1));
        }
    }

    // draw table
    let table = Table::new(rows)
        .style(Style::default().fg(Color::White))
        .header(
            Row::new(vec![
                "ICAO",
                "Call sign",
                "Lat",
                "Long",
                "Altitude",
                "   FPM",
                "Speed",
                "Distance",
                "    Msgs",
            ])
            .bottom_margin(1),
        )
        .block(
            Block::default()
                .title(format!("Airplanes({rows_len})"))
                .borders(Borders::ALL),
        )
        .widths(&[
            Constraint::Length(6),
            Constraint::Length(9),
            Constraint::Length(8),
            Constraint::Length(8),
            Constraint::Length(8),
            Constraint::Length(6),
            Constraint::Length(5),
            Constraint::Length(6),
            Constraint::Length(7),
        ])
        .column_spacing(1)
        .highlight_style(Style::default().add_modifier(Modifier::BOLD))
        .highlight_symbol(">> ");
    f.render_stateful_widget(table, chunks[1], &mut airplanes_state.clone());
}
/// Render Airplanes tab for tui display
Render Airplanes tab for tui display
Render Airplanes tab for tui display
fn build_tab_airplanes<A: tui::backend::Backend>(
    f: &mut tui::Frame<A>,
    chunks: Vec<Rect>,
    adsb_airplanes: &Airplanes,
    airplanes_state: &mut TableState,
) {
    let mut rows = vec![];
    // make a vec of all strings to get a total amount of airplanes with
    // position information
    let empty = "".to_string();
    for key in adsb_airplanes.0.keys() {
        let state = adsb_airplanes.0.get(key).unwrap();
        let pos = adsb_airplanes.aircraft_details(*key);
        let mut lat = empty.clone();
        let mut lon = empty.clone();
        let mut alt = empty.clone();
        let mut s_kilo_distance = empty.clone();
        if let Some((position, altitude, kilo_distance)) = pos {
            lat = format!("{:.3}", position.latitude);
            lon = format!("{:.3}", position.longitude);
            s_kilo_distance = format!("{}", kilo_distance);
            alt = format!("{altitude}");
        }
        rows.push(Row::new(vec![
            format!("{key}"),
            state.callsign.as_ref().unwrap_or(&empty).clone(),
            lat,
            lon,
            format!("{alt:>8}"),
            state
                .vert_speed
                .map_or_else(|| "".into(), |v| format!("{v:>6}")),
            state
                .speed
                .map_or_else(|| "".into(), |v| format!("{v:>5.0}")),
            format!("{:>8}", s_kilo_distance),
            format!("{:>8}", state.num_messages),
        ]));
    }
    let rows_len = rows.len();
    // check the length of selected airplanes
    if let Some(selected) = airplanes_state.selected() {
        if selected > rows_len - 1 {
            airplanes_state.select(Some(rows_len - 1));
        }
    }
    // draw table
    let table = Table::new(rows)
        .style(Style::default().fg(Color::White))
        .header(
            Row::new(vec![
                "ICAO",
                "Call sign",
                "Lat",
                "Long",
                "Altitude",
                "   FPM",
                "Speed",
                "Distance",
                "    Msgs",
            ])
            .bottom_margin(1),
        )
        .block(
            Block::default()
                .title(format!("Airplanes({rows_len})"))
                .borders(Borders::ALL),
        )
        .widths(&[
            Constraint::Length(6),
            Constraint::Length(9),
            Constraint::Length(8),
            Constraint::Length(8),
            Constraint::Length(8),
            Constraint::Length(6),
            Constraint::Length(5),
            Constraint::Length(6),
            Constraint::Length(7),
        ])
        .column_spacing(1)
        .highlight_style(Style::default().add_modifier(Modifier::BOLD))
        .highlight_symbol(">> ");
    f.render_stateful_widget(table, chunks[1], &mut airplanes_state.clone());
}
fn build_tab_airplanes < A : tui :: backend :: Backend > ( f : & mut tui :: Frame < A > , chunks : Vec < Rect > , adsb_airplanes : & Airplanes , airplanes_state : & mut TableState , ) { let mut rows = vec ! [ ] ; // make a vec of all strings to get a total amount of airplanes with // position information let empty = " " . to_string ( ) ; for key in adsb_airplanes . 0 . keys ( ) { let state = adsb_airplanes . 0 . get ( key ) . unwrap ( ) ; let pos = adsb_airplanes . aircraft_details ( * key ) ; let mut lat = empty . clone ( ) ; let mut lon = empty . clone ( ) ; let mut alt = empty . clone ( ) ; let mut s_kilo_distance = empty . clone ( ) ; if let Some ( ( position , altitude , kilo_distance ) ) = pos { lat = format ! ( " " position latitude ) ; lon = format ! ( " " position longitude ) ; s_kilo_distance = format ! ( " " kilo_distance ) ; alt = format ! ( " " ) ; } rows . push ( Row :: new ( vec ! [ format ( " " ) state callsign as_ref ( ) unwrap_or ( empty ) clone ( ) lat lon format ( " " ) state vert_speed map_or_else ( " " into ( ) v format ( " " ) ) state speed map_or_else ( " " into ( ) v format ( " " ) ) format ( " " s_kilo_distance ) format ( " " state num_messages ) ] ) ) ; } let rows_len = rows . len ( ) ; // check the length of selected airplanes if let Some ( selected ) = airplanes_state . selected ( ) { if selected > rows_len - 1 { airplanes_state . select ( Some ( rows_len - 1 ) ) ; } } // draw table let table = Table :: new ( rows ) . style ( Style :: default ( ) . fg ( Color :: White ) ) . header ( Row :: new ( vec ! [ " " " " " " " " " " " " " " " " " " ] ) . bottom_margin ( 1 ) , ) . block ( Block :: default ( ) . title ( format ! ( " " ) ) . borders ( Borders :: ALL ) , ) . widths ( & [ Constraint :: Length ( 6 ) , Constraint :: Length ( 9 ) , Constraint :: Length ( 8 ) , Constraint :: Length ( 8 ) , Constraint :: Length ( 8 ) , Constraint :: Length ( 6 ) , Constraint :: Length ( 5 ) , Constraint :: Length ( 6 ) , Constraint :: Length ( 7 ) , ] ) . column_spacing ( 1 ) . highlight_style ( Style :: default ( ) . add_modifier ( Modifier :: BOLD ) ) . highlight_symbol ( " " ) ; f . render_stateful_widget ( table , chunks [ 1 ] , & mut airplanes_state . clone ( ) ) ; }
Render Airplanes tab for tui display
Render Airplanes tab for tui display
f
&mut tui::Frame<A>
chunks
Vec<Rect>
adsb_airplanes
&Airplanes
airplanes_state
&mut TableState
f
&mut tui::Frame<A>
chunks
Vec<Rect>
adsb_airplanes
&Airplanes
airplanes_state
&mut TableState