Add shortcut to reload database and/or library #116

Merged
wojtek merged 14 commits from 105---add-shortcut-to-reload-database-and/or-library into main 2024-02-03 14:32:13 +01:00
Showing only changes of commit 00f8c4477e - Show all commits

View File

@ -306,28 +306,33 @@ impl<'a, 'b> TrackState<'a, 'b> {
pub struct Ui; pub struct Ui;
impl Ui { impl Ui {
fn style(_active: bool) -> Style { fn style(_active: bool, error: bool) -> Style {
Style::default().fg(Color::White).bg(Color::Black) let style = Style::default().bg(Color::Black);
if error {
style.fg(Color::Red)
} else {
style.fg(Color::White)
}
} }
fn block_style(active: bool) -> Style { fn block_style(active: bool, error: bool) -> Style {
Self::style(active) Self::style(active, error)
} }
fn highlight_style(active: bool) -> Style { fn highlight_style(active: bool) -> Style {
if active { if active {
Style::default().fg(Color::White).bg(Color::DarkGray) Style::default().fg(Color::White).bg(Color::DarkGray)
} else { } else {
Self::style(false) Self::style(false, false)
} }
} }
fn block<'a>(title: &str, active: bool) -> Block<'a> { fn block<'a>(title: &str, active: bool, error: bool) -> Block<'a> {
Block::default() Block::default()
.title_alignment(Alignment::Center) .title_alignment(Alignment::Center)
.borders(Borders::ALL) .borders(Borders::ALL)
.border_type(BorderType::Rounded) .border_type(BorderType::Rounded)
.style(Self::block_style(active)) .style(Self::block_style(active, error))
.title(format!(" {title} ")) .title(format!(" {title} "))
} }
@ -342,8 +347,8 @@ impl Ui {
frame.render_stateful_widget( frame.render_stateful_widget(
list.highlight_style(Self::highlight_style(active)) list.highlight_style(Self::highlight_style(active))
.highlight_symbol(">> ") .highlight_symbol(">> ")
.style(Self::style(active)) .style(Self::style(active, false))
.block(Self::block(title, active)), .block(Self::block(title, active, false)),
area, area,
list_state, list_state,
); );
@ -358,8 +363,8 @@ impl Ui {
) { ) {
frame.render_widget( frame.render_widget(
paragraph paragraph
.style(Self::style(active)) .style(Self::style(active, false))
.block(Self::block(title, active)), .block(Self::block(title, active, false)),
area, area,
); );
} }
@ -368,13 +373,14 @@ impl Ui {
title: &str, title: &str,
paragraph: Paragraph, paragraph: Paragraph,
area: Rect, area: Rect,
error: bool,
frame: &mut Frame<'_, B>, frame: &mut Frame<'_, B>,
) { ) {
frame.render_widget(Clear, area); frame.render_widget(Clear, area);
frame.render_widget( frame.render_widget(
paragraph paragraph
.style(Self::style(true)) .style(Self::style(true, error))
.block(Self::block(title, true)), .block(Self::block(title, true, error)),
area, area,
); );
} }
@ -451,7 +457,7 @@ impl Ui {
let artist_selection = &mut selection.artist; let artist_selection = &mut selection.artist;
let artist_overlay = ArtistOverlay::new(artists, &artist_selection.state); let artist_overlay = ArtistOverlay::new(artists, &artist_selection.state);
Self::render_overlay_widget("Artist", artist_overlay.properties, area, frame); Self::render_overlay_widget("Artist", artist_overlay.properties, area, false, frame);
} }
fn render_reload_overlay<B: Backend>(frame: &mut Frame<'_, B>) { fn render_reload_overlay<B: Backend>(frame: &mut Frame<'_, B>) {
@ -466,7 +472,7 @@ impl Ui {
) )
.alignment(Alignment::Center); .alignment(Alignment::Center);
Self::render_overlay_widget("Reload", reload_text, area, frame); Self::render_overlay_widget("Reload", reload_text, area, false, frame);
} }
fn render_error_overlay<S: AsRef<str>, B: Backend>(msg: S, frame: &mut Frame<'_, B>) { fn render_error_overlay<S: AsRef<str>, B: Backend>(msg: S, frame: &mut Frame<'_, B>) {
@ -478,8 +484,7 @@ impl Ui {
.alignment(Alignment::Center) .alignment(Alignment::Center)
.wrap(Wrap { trim: true }); .wrap(Wrap { trim: true });
// FIXME: highlight with red Self::render_overlay_widget("Error", error_text, area, true, frame);
Self::render_overlay_widget("Error", error_text, area, frame);
} }
} }