treewide: fix various UI bugs; optimize crypto dependencies & format
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: If8fe8b38c1d9c4fecd40ff71f88d2ae06a6a6964
This commit is contained in:
parent
764aafa88d
commit
3ccddce7fd
178 changed files with 58342 additions and 54241 deletions
|
|
@ -1,69 +1,72 @@
|
|||
use ratatui::Frame;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::style::{Color, Modifier, Style};
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::widgets::{Block, Borders, List, ListItem};
|
||||
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 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)
|
||||
};
|
||||
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()
|
||||
};
|
||||
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 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));
|
||||
let list =
|
||||
List::new(items).block(Block::default().borders(Borders::ALL).title(title));
|
||||
|
||||
f.render_widget(list, area);
|
||||
f.render_widget(list, area);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue