liftof_tui/tabs/
tab_settings.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
use ratatui::prelude::*;

use ratatui::widgets::{
//    Axis,
    Block,
    BorderType,
//    GraphType,
//    Dataset,
//    Chart,
    Borders,
//    Cell,
    List,
    ListState,
    ListItem,
    //ListDirection,
//    ListState,
    Paragraph,
//    Row,
//    Table,
//    Tabs,
};

use tui_popup::Popup;

use crate::colors::{
    ColorTheme,
    ColorSet,
    COLORSETOMILU,
    COLORSETBW,
    COLORSETDUNE,
    COLORSETLD,
    COLORSETNIUHI,
    COLORSETMATRIX,
    COLORSETSTARFIELD,
    COLORSETGAPS,
    COLORSETPRINCESSPEACH
};


#[derive(Debug, Clone)]
pub struct SettingsTab<'a> {
  pub theme      : ColorTheme,
  pub colortheme_popup : bool,
  pub ctl_state  : ListState,
  pub ctl_items  : Vec::<ListItem<'a>>,
  pub ctl_active : bool,
}

impl SettingsTab<'_> {
  pub fn new(theme : ColorTheme) -> SettingsTab<'static> {
    let ct_list_items = vec![ListItem::new(Line::from("Black&White")),
                             ListItem::new(Line::from("StarField")),
                             ListItem::new(Line::from("Omiliu")),
                             ListItem::new(Line::from("GAPS")),
                             ListItem::new(Line::from("Niuhi")),
                             ListItem::new(Line::from("Dune")),
                             ListItem::new(Line::from("LowerDecks")),
                             ListItem::new(Line::from("Matrix")),
                             ListItem::new(Line::from("PrincessPeach")),
    ];
    SettingsTab {
      theme,
      colortheme_popup : false,
      ctl_state  : ListState::default(),
      ctl_items  : ct_list_items,
      ctl_active : false,
    }
  }

  pub fn next_ct(&mut self) {
    let i = match self.ctl_state.selected() {
      Some(i) => {
        if i >= self.ctl_items.len() - 1 {
          0
        } else {
          i + 1
        }
      }
      None => 0,
    };
    self.ctl_state.select(Some(i));
  }

  pub fn previous_ct(&mut self) {
    let i = match self.ctl_state.selected() {
      Some(i) => {
        if i == 0 {
          self.ctl_items.len() - 1
        } else {
          i - 1
        }
      }
      None => 0,
    };
    self.ctl_state.select(Some(i));
  }

  pub fn unselect_ctl(&mut self) {
    self.ctl_state.select(None);
  }

  pub fn get_colorset(&self) -> Option<ColorSet> {
    let cs = match self.ctl_state.selected() {
      Some(i) => {
        match i {
          0 => Some(COLORSETBW),
          1 => Some(COLORSETSTARFIELD),
          2 => Some(COLORSETOMILU),
          3 => Some(COLORSETGAPS),
          4 => Some(COLORSETNIUHI),
          5 => Some(COLORSETDUNE),
          6 => Some(COLORSETLD),
          7 => Some(COLORSETMATRIX),
          8 => Some(COLORSETPRINCESSPEACH),
          _ => None,
        }
      }
      None => None,
    };
    cs
  }

  // Color::Blue was nice for background
  pub fn render(&mut self, main_window : &Rect, frame : &mut Frame) {
    let main_rows = Layout::default()
      .direction(Direction::Horizontal)
      .constraints(
          [Constraint::Percentage(50), Constraint::Percentage(50)].as_ref(),
      )
      .split(*main_window);

    let cols_row0 = Layout::default()
        .direction(Direction::Vertical)
        .constraints(
            [Constraint::Percentage(50), 
             Constraint::Percentage(50),
            ].as_ref()
        )
        .split(main_rows[0]);

    let cols_row1 = Layout::default()
        .direction(Direction::Vertical)
        .constraints(
            [Constraint::Percentage(50), 
             Constraint::Percentage(50),
            ].as_ref()
        )
        .split(main_rows[1]);

    let rows_cols_row1 = Layout::default()
        .direction(Direction::Horizontal)
        .constraints(
            [Constraint::Percentage(50),
             Constraint::Percentage(50)
            ].as_ref()
        )
        .split(cols_row1[1]);

    let par_title_string = String::from("Apply Color Theme");
    let (first, rest) = par_title_string.split_at(1);
    let par_title = Line::from(vec![
      Span::styled(
          first,
          Style::default()
              .fg(self.theme.hc)
              .add_modifier(Modifier::UNDERLINED)
              .add_modifier(Modifier::BOLD),
      ),
      Span::styled(rest, self.theme.style()),
    ]);

    let rbs = Block::default()
      .borders(Borders::ALL)
      .style(self.theme.style())
      .title(par_title)
      .border_type(BorderType::Plain);

    let color_theme_list = List::new(self.ctl_items.clone()).block(rbs)
      .highlight_style(self.theme.highlight().add_modifier(Modifier::BOLD))
      .highlight_symbol(">>")
      .repeat_highlight_symbol(true);
    match self.ctl_state.selected() {
      None => self.ctl_state.select(Some(1)),
      Some(_) => (),
    }
    let content = "Settings (WIP)"; 
    let main_view = Paragraph::new(content)
    .style(self.theme.style())
    .alignment(Alignment::Center)
    .block(
      Block::default()
        .borders(Borders::NONE)
    );

    let par_refresh_string = String::from("Refresh rate");
    let (first, rest) = par_refresh_string.split_at(1);
    let par_refresh_title = Line::from(vec![
      Span::styled(
          first,
          Style::default()
              .fg(self.theme.hc)
              .add_modifier(Modifier::UNDERLINED)
              .add_modifier(Modifier::BOLD),
      ),
      Span::styled(rest, self.theme.style()),
    ]);

    let refresh_view = Paragraph::new(content)
    .style(self.theme.style())
    .alignment(Alignment::Center)
    .block(
      Block::default()
        .title(par_refresh_title)
        .borders(Borders::ALL)
        .border_type(BorderType::Rounded),
    );
  
    let par_wf_fixed_y_title = String::from("Fix Waveform y-scale");
    let wf_fixed_y_view = Paragraph::new(content)
    .style(self.theme.style())
    .alignment(Alignment::Center)
    .block(
      Block::default()
        .title(par_wf_fixed_y_title)
        .borders(Borders::ALL)
        .border_type(BorderType::Rounded),
    );

    frame.render_widget(main_view, cols_row0[0]);
    frame.render_stateful_widget(color_theme_list, cols_row1[0], &mut self.ctl_state );
    frame.render_widget(refresh_view,    rows_cols_row1[0]);
    frame.render_widget(wf_fixed_y_view, rows_cols_row1[1]);
    if self.colortheme_popup {
      let popup = Popup::new("Any key to continue!")
        .title("New color theme selected!")
        .style(self.theme.style());
      frame.render_widget(&popup, frame.area());
    }
  }
}