Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: If8fe8b38c1d9c4fecd40ff71f88d2ae06a6a6964
72 lines
2 KiB
Rust
72 lines
2 KiB
Rust
use ratatui::{
|
|
Frame,
|
|
layout::Rect,
|
|
style::{Color, Modifier, Style},
|
|
text::{Line, Span},
|
|
widgets::{Block, Borders, List, ListItem},
|
|
};
|
|
|
|
use crate::app::AppState;
|
|
|
|
pub fn render(f: &mut Frame, state: &AppState, area: Rect) {
|
|
let items: Vec<ListItem> = if state.play_queue.is_empty() {
|
|
vec![ListItem::new(Line::from(Span::styled(
|
|
" Queue is empty. Select items in the library and press 'q' to add.",
|
|
Style::default().fg(Color::DarkGray),
|
|
)))]
|
|
} else {
|
|
state
|
|
.play_queue
|
|
.iter()
|
|
.enumerate()
|
|
.map(|(i, item)| {
|
|
let is_current = state.queue_current_index == Some(i);
|
|
let is_selected = state.queue_selected == Some(i);
|
|
let prefix = if is_current { ">> " } else { " " };
|
|
let type_color = super::media_type_color(&item.media_type);
|
|
let id_suffix = if item.media_id.len() > 8 {
|
|
&item.media_id[item.media_id.len() - 8..]
|
|
} else {
|
|
&item.media_id
|
|
};
|
|
let text = if let Some(ref artist) = item.artist {
|
|
format!("{prefix}{} - {} [{}]", item.title, artist, id_suffix)
|
|
} else {
|
|
format!("{prefix}{} [{}]", item.title, id_suffix)
|
|
};
|
|
|
|
let style = if is_selected {
|
|
Style::default()
|
|
.fg(Color::Cyan)
|
|
.add_modifier(Modifier::BOLD)
|
|
} else if is_current {
|
|
Style::default()
|
|
.fg(Color::Green)
|
|
.add_modifier(Modifier::BOLD)
|
|
} else {
|
|
Style::default().fg(type_color)
|
|
};
|
|
|
|
ListItem::new(Line::from(Span::styled(text, style)))
|
|
})
|
|
.collect()
|
|
};
|
|
|
|
let repeat_str = match state.queue_repeat {
|
|
0 => "Off",
|
|
1 => "One",
|
|
_ => "All",
|
|
};
|
|
let shuffle_str = if state.queue_shuffle { "On" } else { "Off" };
|
|
let title = format!(
|
|
" Queue ({}) | Repeat: {} | Shuffle: {} ",
|
|
state.play_queue.len(),
|
|
repeat_str,
|
|
shuffle_str,
|
|
);
|
|
|
|
let list =
|
|
List::new(items).block(Block::default().borders(Borders::ALL).title(title));
|
|
|
|
f.render_widget(list, area);
|
|
}
|