diff options
Diffstat (limited to 'src/ui.rs')
| -rwxr-xr-x | src/ui.rs | 77 |
1 files changed, 51 insertions, 26 deletions
@@ -1,4 +1,4 @@ -use crate::app::App; +use crate::app::{App, AppResult}; use ratatui::{prelude::*, widgets::*}; /// Renders the user interface widgets @@ -8,9 +8,51 @@ pub fn render(app: &mut App, frame: &mut Frame) { // - https://docs.rs/ratatui/latest/ratatui/widgets/index.html // - https://github.com/ratatui-org/ratatui/tree/master/examples - // List of songs + // Layout + let main_layout = Layout::default() + .direction(Direction::Vertical) + .constraints(vec![Constraint::Percentage(93), Constraint::Percentage(7)]) + .split(frame.size()); + + let outer_layout = Layout::default() + .direction(Direction::Horizontal) + .constraints(vec![Constraint::Percentage(50), Constraint::Percentage(50)]) + .split(main_layout[0]); + + let inner_layout = Layout::default() + .direction(Direction::Vertical) + .constraints(vec![Constraint::Percentage(50), Constraint::Percentage(50)]) + .split(outer_layout[1]); + + draw_song_list(frame, app, outer_layout[0]); + draw_queue(frame, app, inner_layout[0]); + draw_playlists(frame, app, inner_layout[1]); + + // Status + // let song = app + // .conn + // .now_playing().unwrap() + // .unwrap_or_else(|| "No Title Found".to_string()); + // + // let (elapsed, total) = app.conn.conn.status().unwrap().time.unwrap(); + // + // let mut lines = vec![]; + // lines.push(Line::from(vec![ + // Span::styled("Current: ", Style::default().fg(Color::Red)), + // Span::styled(song, Style::default().fg(Color::Yellow)), + // Span::styled( + // format!("[{}/{}]", elapsed.as_secs(), total.as_secs()), + // Style::default().fg(Color::Yellow), + // ), + // ])); + // let status = Paragraph::new(Text::from(lines)) + // .block(Block::default().title("Status").borders(Borders::ALL)); + // frame.render_widget(status, main_layout[1]); +} + +/// draws list of songs +fn draw_song_list(frame: &mut Frame, app: &mut App, size: Rect) { let mut song_state = ListState::default(); - let size = Rect::new(100, 0, frame.size().width, frame.size().height - 3); let list = List::new(app.conn.songs_filenames.clone()) .block(Block::default().title("Song List").borders(Borders::ALL)) .highlight_style(Style::new().add_modifier(Modifier::REVERSED)) @@ -19,10 +61,11 @@ pub fn render(app: &mut App, frame: &mut Frame) { song_state.select(Some(app.song_list.index)); frame.render_stateful_widget(list, size, &mut song_state); +} - // Play Queue +/// draws playing queue +fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) { let mut queue_state = ListState::default(); - let size = Rect::new(0, 0, 100, frame.size().height - 25); let list = List::new(app.play_deque.clone()) .block(Block::default().title("Play Queue").borders(Borders::ALL)) .highlight_style(Style::new().add_modifier(Modifier::REVERSED)) @@ -31,29 +74,11 @@ pub fn render(app: &mut App, frame: &mut Frame) { app.update_queue(); frame.render_stateful_widget(list, size, &mut queue_state); +} - // Status - // let size = Rect::new(0, frame.size().height - 3, frame.size().width, 3); - // let song = app - // .conn - // .now_playing() - // .unwrap_or_else(|| "No Title Found".to_string()); - // - // let (elapsed, total) = app.conn.conn.status().unwrap().time.unwrap(); - // - // let mut lines = vec![]; - // lines.push(Line::from(vec![ - // Span::styled("Current: ", Style::default().fg(Color::Red)), - // Span::styled(song, Style::default().fg(Color::Yellow)), - // Span::styled(format!("[{}/{}]", elapsed.as_secs(), total.as_secs()), Style::default().fg(Color::Yellow)), - // ])); - // let status = Paragraph::new(Text::from(lines)) - // .block(Block::default().title("Status").borders(Borders::ALL)); - // frame.render_widget(status, size); - - // Playlists +/// draws all playlists +fn draw_playlists(frame: &mut Frame, app: &mut App, size: Rect) { let mut state = ListState::default(); - let size = Rect::new(0, 25, 100, frame.size().height - 25 - 3); let list = List::new(app.pl_list.list.clone()) .block(Block::default().title("Playlists").borders(Borders::ALL)) .highlight_style(Style::new().add_modifier(Modifier::REVERSED)) |
