fm/modes/menu/
picker.rs

1use crate::io::DrawMenu;
2use crate::{impl_content, impl_selectable};
3
4/// Which part of fm asked a picker ?
5/// Only cloud uses a picker atm.
6pub enum PickerCaller {
7    Cloud,
8    Unknown,
9}
10
11/// A basic picker, allowing to display some text and pick one element.
12/// It records a [`PickerCaller`], used to call it back.
13#[derive(Default)]
14pub struct Picker {
15    pub caller: Option<PickerCaller>,
16    pub desc: Option<String>,
17    pub index: usize,
18    pub content: Vec<String>,
19}
20
21impl Picker {
22    pub fn clear(&mut self) {
23        self.caller = None;
24        self.index = 0;
25        self.content = vec![];
26    }
27
28    pub fn set(
29        &mut self,
30        caller: Option<PickerCaller>,
31        desc: Option<String>,
32        content: Vec<String>,
33    ) {
34        self.clear();
35        self.caller = caller;
36        self.desc = desc;
37        self.content = content;
38    }
39}
40
41impl_selectable!(Picker);
42impl_content!(Picker, String);
43
44impl DrawMenu<String> for Picker {}