Final improvements
All checks were successful
Cargo CI / Build and Test (pull_request) Successful in 1m57s
Cargo CI / Lint (pull_request) Successful in 1m5s

This commit is contained in:
Wojciech Kozlowski 2024-08-29 17:18:06 +02:00
parent 220e569bda
commit 03d1dc56cb
4 changed files with 51 additions and 34 deletions

14
src/tui/ui/error.rs Normal file
View File

@ -0,0 +1,14 @@
use ratatui::{
layout::Alignment,
widgets::{Paragraph, Wrap},
};
pub struct ErrorOverlay;
impl ErrorOverlay {
pub fn paragraph(msg: &str) -> Paragraph {
Paragraph::new(msg)
.alignment(Alignment::Center)
.wrap(Wrap { trim: true })
}
}

View File

@ -1,4 +1,7 @@
use ratatui::{layout::Alignment, widgets::Paragraph}; use ratatui::{
layout::{Alignment, Rect},
widgets::Paragraph,
};
use crate::tui::{ use crate::tui::{
app::{AppPublicState, AppState}, app::{AppPublicState, AppState},
@ -11,7 +14,17 @@ pub struct Minibuffer<'a> {
} }
impl Minibuffer<'_> { impl Minibuffer<'_> {
pub fn paragraphs(state: &AppPublicState) -> Self { pub fn area(ar: Rect) -> Rect {
let space = 3;
Rect {
x: ar.x + 1 + space,
y: ar.y + 1,
width: ar.width.saturating_sub(2 + 2 * space),
height: 1,
}
}
pub fn new(state: &AppPublicState) -> Self {
let columns = 3; let columns = 3;
let mut mb = match state { let mut mb = match state {
AppState::Browse(_) => Minibuffer { AppState::Browse(_) => Minibuffer {

View File

@ -1,5 +1,6 @@
mod browse; mod browse;
mod display; mod display;
mod error;
mod info; mod info;
mod matches; mod matches;
mod minibuffer; mod minibuffer;
@ -8,11 +9,7 @@ mod reload;
mod style; mod style;
mod widgets; mod widgets;
use ratatui::{ use ratatui::{layout::Rect, widgets::Paragraph, Frame};
layout::{Alignment, Rect},
widgets::{Paragraph, Wrap},
Frame,
};
use musichoard::collection::{album::Album, Collection}; use musichoard::collection::{album::Album, Collection};
@ -24,11 +21,12 @@ use crate::tui::{
AlbumArea, AlbumState, ArtistArea, ArtistState, FrameArea, TrackArea, TrackState, AlbumArea, AlbumState, ArtistArea, ArtistState, FrameArea, TrackArea, TrackState,
}, },
display::UiDisplay, display::UiDisplay,
error::ErrorOverlay,
info::{AlbumOverlay, ArtistOverlay}, info::{AlbumOverlay, ArtistOverlay},
matches::AlbumMatchesState, matches::AlbumMatchesState,
minibuffer::Minibuffer, minibuffer::Minibuffer,
overlay::{OverlayBuilder, OverlaySize}, overlay::{OverlayBuilder, OverlaySize},
reload::ReloadMenu, reload::ReloadOverlay,
widgets::UiWidget, widgets::UiWidget,
}, },
}; };
@ -55,15 +53,8 @@ impl Ui {
} }
fn render_minibuffer(state: &AppPublicState, ar: Rect, fr: &mut Frame) { fn render_minibuffer(state: &AppPublicState, ar: Rect, fr: &mut Frame) {
let mb = Minibuffer::paragraphs(state); let mb = Minibuffer::new(state);
let area = Minibuffer::area(ar);
let space = 3;
let area = Rect {
x: ar.x + 1 + space,
y: ar.y + 1,
width: ar.width.saturating_sub(2 + 2 * space),
height: 1,
};
UiWidget::render_info_widget("Minibuffer", Paragraph::new(""), false, ar, fr); UiWidget::render_info_widget("Minibuffer", Paragraph::new(""), false, ar, fr);
UiWidget::render_columns(mb.paragraphs, mb.columns, false, area, fr); UiWidget::render_columns(mb.paragraphs, mb.columns, false, area, fr);
@ -130,6 +121,17 @@ impl Ui {
} }
} }
fn render_reload_overlay(frame: &mut Frame) {
let area = OverlayBuilder::default()
.with_width(OverlaySize::Value(39))
.with_height(OverlaySize::Value(4))
.build(frame.size());
let reload_text = ReloadOverlay::paragraph();
UiWidget::render_overlay_widget("Reload", reload_text, area, false, frame);
}
fn render_matches_overlay( fn render_matches_overlay(
matching: Option<&Album>, matching: Option<&Album>,
matches: Option<&[Match<Album>]>, matches: Option<&[Match<Album>]>,
@ -142,25 +144,12 @@ impl Ui {
UiWidget::render_overlay_list_widget(&matching_string, st.list, st.state, true, area, frame) UiWidget::render_overlay_list_widget(&matching_string, st.list, st.state, true, area, frame)
} }
fn render_reload_overlay(frame: &mut Frame) {
let area = OverlayBuilder::default()
.with_width(OverlaySize::Value(39))
.with_height(OverlaySize::Value(4))
.build(frame.size());
let reload_text = ReloadMenu::paragraph().alignment(Alignment::Center);
UiWidget::render_overlay_widget("Reload", reload_text, area, false, frame);
}
fn render_error_overlay<S: AsRef<str>>(title: S, msg: S, frame: &mut Frame) { fn render_error_overlay<S: AsRef<str>>(title: S, msg: S, frame: &mut Frame) {
let area = OverlayBuilder::default() let area = OverlayBuilder::default()
.with_height(OverlaySize::Value(4)) .with_height(OverlaySize::Value(4))
.build(frame.size()); .build(frame.size());
let error_text = Paragraph::new(msg.as_ref()) let error_text = ErrorOverlay::paragraph(msg.as_ref());
.alignment(Alignment::Center)
.wrap(Wrap { trim: true });
UiWidget::render_overlay_widget(title.as_ref(), error_text, area, true, frame); UiWidget::render_overlay_widget(title.as_ref(), error_text, area, true, frame);
} }

View File

@ -1,12 +1,13 @@
use ratatui::widgets::Paragraph; use ratatui::{layout::Alignment, widgets::Paragraph};
pub struct ReloadMenu; pub struct ReloadOverlay;
impl ReloadMenu { impl ReloadOverlay {
pub fn paragraph<'a>() -> Paragraph<'a> { pub fn paragraph<'a>() -> Paragraph<'a> {
Paragraph::new( Paragraph::new(
"d: database\n\ "d: database\n\
l: library", l: library",
) )
.alignment(Alignment::Center)
} }
} }