add help menu and remove unnecessary function
Build / build (push) Successful in 2m11s

This commit is contained in:
2026-07-27 18:51:11 +02:00
parent f721bdcd12
commit ebf1be2cb9
2 changed files with 122 additions and 55 deletions
+75 -10
View File
@@ -1,10 +1,16 @@
use ratatui::{
buffer::Buffer, layout::{
buffer::Buffer,
layout::{
Alignment, Constraint,
Direction::{self},
Layout, Rect,
}, style::{Color, Modifier, Style}, symbols, widgets::{
Block, BorderType::{self, Rounded}, LineGauge, List, ListDirection, ListItem, Paragraph, StatefulWidget, Widget,
},
style::{Color, Modifier, Style, Stylize},
symbols,
text::Line,
widgets::{
Block, BorderType::Rounded, Clear, LineGauge, List, ListDirection, ListItem, Paragraph,
Row, StatefulWidget, Table, Widget,
},
};
@@ -42,7 +48,12 @@ impl Widget for &mut App {
])
.split(outer_layout[1]);
let now_playing_block = Block::bordered().title(format!("Now Playing | Vol: {:.0}", self.player.volume() * 100.0)).border_type(Rounded);
let now_playing_block = Block::bordered()
.title(format!(
"Now Playing | Vol: {:.0}",
self.player.volume() * 100.0
))
.border_type(Rounded);
let inner = now_playing_block.inner(center_area[1]);
Widget::render(now_playing_block, center_area[1], buf);
@@ -89,6 +100,7 @@ impl Widget for &mut App {
Color::Gray
};
// Artists
let artists: Vec<ListItem> = self
.library
.artists
@@ -100,7 +112,8 @@ impl Widget for &mut App {
.block(
Block::bordered()
.title("Artists")
.border_style(Style::new().fg(artist_border_color)).border_type(Rounded),
.border_style(Style::new().fg(artist_border_color))
.border_type(Rounded),
)
.style(Style::new().white())
.highlight_symbol(">>")
@@ -110,6 +123,13 @@ impl Widget for &mut App {
StatefulWidget::render(artist_list, left_area[0], buf, &mut self.artist_state);
// Info
let instructions = Line::from(vec![
" Help ".gray().bold(),
"<?> ".blue().bold(),
]);
// Albums
let albums: Vec<ListItem> = self
.library
.albums_for_artist(
@@ -123,7 +143,9 @@ impl Widget for &mut App {
.block(
Block::bordered()
.title("Albums")
.border_style(Style::new().fg(album_border_color)).border_type(Rounded),
.title_bottom(instructions.right_aligned())
.border_style(Style::new().fg(album_border_color))
.border_type(Rounded),
)
.style(Style::new().white())
.highlight_symbol(">>")
@@ -133,18 +155,26 @@ impl Widget for &mut App {
StatefulWidget::render(album_list, center_area[0], buf, &mut self.album_state);
// Songs
let song_indexes: Vec<usize> = self.current_selected_song();
let song_items: Vec<ListItem> = song_indexes
.iter()
.map(|&index| ListItem::new(format!("{} ({})", self.library.songs[index].title.clone(), format_time(self.library.songs[index].duration.unwrap()))))
.map(|&index| {
ListItem::new(format!(
"{} ({})",
self.library.songs[index].title.clone(),
format_time(self.library.songs[index].duration.unwrap())
))
})
.collect();
let song_list = List::new(song_items)
.block(
Block::bordered()
.title("Songs")
.border_style(Style::new().fg(song_border_color)).border_type(Rounded),
.border_style(Style::new().fg(song_border_color))
.border_type(Rounded),
)
.style(Style::new().white())
.highlight_symbol(">>")
@@ -154,14 +184,26 @@ impl Widget for &mut App {
StatefulWidget::render(song_list, right_area[0], buf, &mut self.song_state);
// Queue
let queue_items: Vec<ListItem> = self
.queue
.iter()
.map(|&index| ListItem::new(format!("{} ({}))", self.library.songs[index].title.as_str(), format_time(self.library.songs[index].duration.unwrap()))))
.map(|&index| {
ListItem::new(format!(
"{} ({}))",
self.library.songs[index].title.as_str(),
format_time(self.library.songs[index].duration.unwrap())
))
})
.collect();
let queue_list = List::new(queue_items)
.block(Block::bordered().title("Queue").border_style(Style::new().fg(queue_border_color)).border_type(Rounded))
.block(
Block::bordered()
.title("Queue")
.border_style(Style::new().fg(queue_border_color))
.border_type(Rounded),
)
.style(Style::new().white())
.highlight_symbol(">>")
.repeat_highlight_symbol(true)
@@ -170,6 +212,29 @@ impl Widget for &mut App {
StatefulWidget::render(queue_list, right_area[1], buf, &mut self.queue_state);
// Help Menu
if self.control_popup {
let popup_block = Block::bordered().title("Controls").border_type(Rounded);
Widget::render(Clear, center_area[0], buf);
let header = Row::new(["", "Key", "Function"])
.style(Style::new().bold())
.bottom_margin(1);
let rows = self.get_controls();
let widths = [Constraint::Percentage(10), Constraint::Percentage(45), Constraint::Percentage(45)];
let help_menu = Table::new(rows, widths)
.header(header)
.column_spacing(1)
.style(Color::White)
.block(popup_block);
Widget::render(help_menu, center_area[0], buf);
}
// Play area
if let Some(song) = self.current_song() {
let duration = song.duration.unwrap_or(1.0);
Paragraph::new(song.title.as_str())