Final improvements
This commit is contained in:
parent
220e569bda
commit
03d1dc56cb
14
src/tui/ui/error.rs
Normal file
14
src/tui/ui/error.rs
Normal 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 })
|
||||
}
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
use ratatui::{layout::Alignment, widgets::Paragraph};
|
||||
use ratatui::{
|
||||
layout::{Alignment, Rect},
|
||||
widgets::Paragraph,
|
||||
};
|
||||
|
||||
use crate::tui::{
|
||||
app::{AppPublicState, AppState},
|
||||
@ -11,7 +14,17 @@ pub struct Minibuffer<'a> {
|
||||
}
|
||||
|
||||
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 mut mb = match state {
|
||||
AppState::Browse(_) => Minibuffer {
|
||||
|
@ -1,5 +1,6 @@
|
||||
mod browse;
|
||||
mod display;
|
||||
mod error;
|
||||
mod info;
|
||||
mod matches;
|
||||
mod minibuffer;
|
||||
@ -8,11 +9,7 @@ mod reload;
|
||||
mod style;
|
||||
mod widgets;
|
||||
|
||||
use ratatui::{
|
||||
layout::{Alignment, Rect},
|
||||
widgets::{Paragraph, Wrap},
|
||||
Frame,
|
||||
};
|
||||
use ratatui::{layout::Rect, widgets::Paragraph, Frame};
|
||||
|
||||
use musichoard::collection::{album::Album, Collection};
|
||||
|
||||
@ -24,11 +21,12 @@ use crate::tui::{
|
||||
AlbumArea, AlbumState, ArtistArea, ArtistState, FrameArea, TrackArea, TrackState,
|
||||
},
|
||||
display::UiDisplay,
|
||||
error::ErrorOverlay,
|
||||
info::{AlbumOverlay, ArtistOverlay},
|
||||
matches::AlbumMatchesState,
|
||||
minibuffer::Minibuffer,
|
||||
overlay::{OverlayBuilder, OverlaySize},
|
||||
reload::ReloadMenu,
|
||||
reload::ReloadOverlay,
|
||||
widgets::UiWidget,
|
||||
},
|
||||
};
|
||||
@ -55,15 +53,8 @@ impl Ui {
|
||||
}
|
||||
|
||||
fn render_minibuffer(state: &AppPublicState, ar: Rect, fr: &mut Frame) {
|
||||
let mb = Minibuffer::paragraphs(state);
|
||||
|
||||
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,
|
||||
};
|
||||
let mb = Minibuffer::new(state);
|
||||
let area = Minibuffer::area(ar);
|
||||
|
||||
UiWidget::render_info_widget("Minibuffer", Paragraph::new(""), false, ar, 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(
|
||||
matching: Option<&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)
|
||||
}
|
||||
|
||||
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) {
|
||||
let area = OverlayBuilder::default()
|
||||
.with_height(OverlaySize::Value(4))
|
||||
.build(frame.size());
|
||||
|
||||
let error_text = Paragraph::new(msg.as_ref())
|
||||
.alignment(Alignment::Center)
|
||||
.wrap(Wrap { trim: true });
|
||||
let error_text = ErrorOverlay::paragraph(msg.as_ref());
|
||||
|
||||
UiWidget::render_overlay_widget(title.as_ref(), error_text, area, true, frame);
|
||||
}
|
||||
|
@ -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> {
|
||||
Paragraph::new(
|
||||
"d: database\n\
|
||||
l: library",
|
||||
)
|
||||
.alignment(Alignment::Center)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user