Krolyxon
Commit a0582ea

rmptuisrcui.rs

37 lines · 1.5 KB · Rust

1use crate::{app::App, connection::Connection};
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 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 state.select(Some(app.list.index));
21 frame.render_stateful_widget(list, size, &mut state);
22
23 // Play Queue
24 let size = Rect::new(0, 0, 100, frame.size().height - 25);
25 let list = List::new(app.play_deque.clone())
26 .block(Block::default().title("Play Queue").borders(Borders::ALL))
27 .highlight_style(Style::new().add_modifier(Modifier::REVERSED))
28 .highlight_symbol(">>")
29 .repeat_highlight_symbol(true);
30 frame.render_widget(list, size);
31
32 // Status
33 let size = Rect::new(0, frame.size().height - 3, frame.size().width, 3);
34 let status = Paragraph::new(app.conn.conn.status().unwrap().volume.to_string())
35 .block(Block::default().title("Status").borders(Borders::ALL));
36 frame.render_widget(status, size);
37}