rsnaker/graphics/menus/retro_parameter_table/
customized_with_speed.rs

1use crate::controls::speed::Speed;
2use crate::graphics::menus::retro_parameter_table::generic_logic::{
3    get_default_action_input, CellValue, FooterData, GenericMenu, RowData,
4};
5use clap::ValueEnum;
6use ratatui::DefaultTerminal;
7
8/// Sets up and runs the speed table parameters menu
9pub fn setup_and_run_speed_table_parameters(terminal: &mut DefaultTerminal) {
10    GenericMenu::new(
11        load_speed_info_in_table(),
12        &speed_get_headers(),
13        speed_get_footer_data(),
14        None,
15    )
16    .run(get_default_action_input(), terminal);
17}
18
19/// Loads speed information into table rows for display
20/// Each row contains: Speed name, delay value, score modifier, and symbol
21#[must_use]
22fn load_speed_info_in_table() -> Vec<RowData> {
23    let mut rows = vec![];
24
25    // For each speed variant, extract its configuration and add to rows
26    for speed in Speed::value_variants() {
27        let config = speed.config();
28        rows.push(RowData::new(vec![
29            CellValue::new(config.name.to_string()),
30            CellValue::new(format!("{}ms", config.ms_value)),
31            CellValue::new(format!("x{}", config.score_modifier)),
32            CellValue::new(config.symbol.to_string()),
33        ]));
34    }
35
36    rows
37}
38
39/// Returns the header labels for the speed information table
40#[must_use]
41fn speed_get_headers() -> Vec<String> {
42    vec![
43        "🏁 Speed Level".to_string(),
44        "⏱️ Delay Value".to_string(),
45        "🎯 Score Modifier".to_string(),
46        "🔣 Symbol".to_string(),
47    ]
48}
49
50/// Returns footer data for the speed parameters table
51#[must_use]
52fn speed_get_footer_data() -> Vec<FooterData> {
53    vec![
54        FooterData {
55            symbol: "Esc".into(),
56            text: "Return to home".into(),
57            value: None,
58        },
59        FooterData {
60            symbol: "↕".into(),
61            text: "Move".into(),
62            value: None,
63        },
64    ]
65}