Krolyxon
Commit 05c4b17

rmptuisrcui.rs

65 lines · 2.6 KB · Rust

1use crate::app::App;
2use ratatui::{prelude::*, widgets::*};
3
4/// Renders the user interface widgets
5pub fn render(app: &mut App, frame: &mut Frame) {
6 // This is where you add new widgets.
7 // See the following resources:
8 // - https://docs.rs/ratatui/latest/ratatui/widgets/index.html
9 // - https://github.com/ratatui-org/ratatui/tree/master/examples
10
11 // List of songs
12 let mut song_state = ListState::default();
13 let size = Rect::new(100, 0, frame.size().width, frame.size().height - 3);
14 let list = List::new(app.conn.songs_filenames.clone())
15 .block(Block::default().title("Song List").borders(Borders::ALL))
16 .highlight_style(Style::new().add_modifier(Modifier::REVERSED))
17 .highlight_symbol(">>")
18 .repeat_highlight_symbol(true);
19
20 song_state.select(Some(app.song_list.index));
21 frame.render_stateful_widget(list, size, &mut song_state);
22
23 // Play Queue
24 let mut queue_state = ListState::default();
25 let size = Rect::new(0, 0, 100, frame.size().height - 25);
26 let list = List::new(app.play_deque.clone())
27 .block(Block::default().title("Play Queue").borders(Borders::ALL))
28 .highlight_style(Style::new().add_modifier(Modifier::REVERSED))
29 .highlight_symbol(">>")
30 .repeat_highlight_symbol(true);
31
32 app.update_queue();
33 frame.render_stateful_widget(list, size, &mut queue_state);
34
35 // Status
36 // let size = Rect::new(0, frame.size().height - 3, frame.size().width, 3);
37 // let song = app
38 // .conn
39 // .now_playing()
40 // .unwrap_or_else(|| "No Title Found".to_string());
41 //
42 // let (elapsed, total) = app.conn.conn.status().unwrap().time.unwrap();
43 //
44 // let mut lines = vec![];
45 // lines.push(Line::from(vec![
46 // Span::styled("Current: ", Style::default().fg(Color::Red)),
47 // Span::styled(song, Style::default().fg(Color::Yellow)),
48 // Span::styled(format!("[{}/{}]", elapsed.as_secs(), total.as_secs()), Style::default().fg(Color::Yellow)),
49 // ]));
50 // let status = Paragraph::new(Text::from(lines))
51 // .block(Block::default().title("Status").borders(Borders::ALL));
52 // frame.render_widget(status, size);
53
54 // Playlists
55 let mut state = ListState::default();
56 let size = Rect::new(0, 25, 100, frame.size().height - 25 - 3);
57 let list = List::new(app.pl_list.list.clone())
58 .block(Block::default().title("Playlists").borders(Borders::ALL))
59 .highlight_style(Style::new().add_modifier(Modifier::REVERSED))
60 .highlight_symbol(">>")
61 .repeat_highlight_symbol(true);
62
63 state.select(Some(app.pl_list.index));
64 frame.render_stateful_widget(list, size, &mut state);
65}