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
use crate::MenuItem;

pub struct NavigationItem<'a, R: Copy> {
    title_text: &'a str,
    details: &'a str,
    return_value: R,
    marker: &'a str,
}

impl<'a, R: Copy> MenuItem for NavigationItem<'a, R> {
    type Data = R;

    fn interact(&mut self) -> R {
        self.return_value
    }

    fn title(&self) -> &str {
        self.title_text
    }

    fn details(&self) -> &str {
        self.details
    }

    fn value(&self) -> &str {
        self.marker
    }

    fn longest_value_str(&self) -> &str {
        self.value()
    }
}

impl<'a, R: Copy> NavigationItem<'a, R> {
    pub fn new(title: &'a str, value: R) -> Self {
        Self {
            title_text: title,
            return_value: value,
            details: "",
            marker: "",
        }
    }

    pub fn with_marker(self, marker: &'a str) -> Self {
        Self { marker, ..self }
    }

    pub fn with_detail_text(self, details: &'a str) -> Self {
        Self { details, ..self }
    }
}