diff options
Diffstat (limited to 'src/ui.rs')
| -rwxr-xr-x | src/ui.rs | 48 |
1 files changed, 43 insertions, 5 deletions
@@ -21,11 +21,6 @@ impl InputMode { /// Renders the user interface widgets pub fn render(app: &mut App, frame: &mut Frame) { - // This is where you add new widgets. - // See the following resources: - // - https://docs.rs/ratatui/latest/ratatui/widgets/index.html - // - https://github.com/ratatui-org/ratatui/tree/master/examples - // Layout let layout = Layout::default() .direction(Direction::Vertical) @@ -46,6 +41,10 @@ pub fn render(app: &mut App, frame: &mut Frame) { draw_search_bar(frame, app, layout[1]); } } + + if app.playlist_popup { + draw_add_to_playlist(frame, app, layout[0]); + } } /// Draws the file tree browser @@ -238,3 +237,42 @@ fn draw_progress_bar(frame: &mut Frame, app: &mut App, size: Rect) { frame.render_widget(progress_bar, size); } + +fn draw_add_to_playlist(frame: &mut Frame, app: &mut App, area: Rect) { + let area = centered_rect(40, 50, area); + let mut state = ListState::default(); + let title = Block::default() + .title(Title::from("Add Selected Item to: ")) + .title(Title::from("<Esc> to Cancel".green().bold()).alignment(Alignment::Right)); + let list = List::new(app.append_list.list.clone()) + .block(title.borders(Borders::ALL)) + .highlight_style( + Style::new() + .fg(Color::Cyan) + .bg(Color::Black) + .add_modifier(Modifier::BOLD) + .add_modifier(Modifier::REVERSED), + ) + .highlight_symbol(">>") + .repeat_highlight_symbol(true); + + state.select(Some(app.append_list.index)); + frame.render_widget(Clear, area); //this clears out the background + frame.render_stateful_widget(list, area, &mut state); +} + +fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect { + let popup_layout = Layout::vertical([ + Constraint::Percentage((100 - percent_y) / 2), + Constraint::Percentage(percent_y), + Constraint::Percentage((100 - percent_y) / 2), + ]) + .split(r); + + Layout::horizontal([ + Constraint::Percentage((100 - percent_x) / 2), + Constraint::Percentage(percent_x), + Constraint::Percentage((100 - percent_x) / 2), + ]) + .split(popup_layout[1])[1] +} |
