Decouple number of columns from paragraphs
Some checks failed
Cargo CI / Build and Test (pull_request) Successful in 1m43s
Cargo CI / Lint (pull_request) Failing after 1m15s

This commit is contained in:
Wojciech Kozlowski 2024-02-10 23:17:40 +01:00
parent 64b93c837e
commit 78fcbafc04

View File

@ -347,25 +347,41 @@ impl<'a, 'b> TrackState<'a, 'b> {
}
}
struct Minibuffer;
struct Minibuffer<'a> {
paragraphs: Vec<Paragraph<'a>>,
columns: u16,
}
impl Minibuffer {
fn paragraphs(state: &AppPublicState) -> Vec<Paragraph> {
impl Minibuffer<'_> {
fn paragraphs(state: &AppPublicState) -> Self {
match state {
AppState::Browse(_) => vec![
Paragraph::new("m: show info overlay"),
Paragraph::new("g: show reload menu"),
],
AppState::Info(_) => vec![Paragraph::new("m: hide info overlay")],
AppState::Reload(_) => vec![
Paragraph::new("d: reload database"),
Paragraph::new("l: reload library"),
Paragraph::new("g: hide reload menu"),
],
AppState::Error(_) => {
vec![Paragraph::new("Press any key to dismiss the error message")]
}
AppState::Critical(_) => vec![Paragraph::new("Press ctrl+c to terminate the program")],
AppState::Browse(_) => Minibuffer {
paragraphs: vec![
Paragraph::new("m: show info overlay"),
Paragraph::new("g: show reload menu"),
],
columns: 3,
},
AppState::Info(_) => Minibuffer {
paragraphs: vec![Paragraph::new("m: hide info overlay")],
columns: 3,
},
AppState::Reload(_) => Minibuffer {
paragraphs: vec![
Paragraph::new("g: hide reload menu"),
Paragraph::new("d: reload database"),
Paragraph::new("l: reload library"),
],
columns: 3,
},
AppState::Error(_) => Minibuffer {
paragraphs: vec![Paragraph::new("Press any key to dismiss the error message...")],
columns: 1,
},
AppState::Critical(_) => Minibuffer {
paragraphs: vec![Paragraph::new("Press ctrl+c to terminate the program...")],
columns: 1,
},
}
}
}
@ -472,10 +488,13 @@ impl Ui {
);
}
fn columns(paragraphs: Vec<Paragraph>, area: Rect) -> Vec<Column> {
fn columns(paragraphs: Vec<Paragraph>, min: u16, area: Rect) -> Vec<Column> {
let mut x = area.x;
let mut width = area.width;
let mut remaining = paragraphs.len() as u16;
if remaining < min {
remaining = min;
}
let mut blocks = vec![];
for paragraph in paragraphs.into_iter() {
@ -501,11 +520,12 @@ impl Ui {
fn render_columns<B: Backend>(
paragraphs: Vec<Paragraph>,
min: u16,
active: bool,
area: Rect,
frame: &mut Frame<'_, B>,
) {
for column in Self::columns(paragraphs, area).into_iter() {
for column in Self::columns(paragraphs, min, area).into_iter() {
frame.render_widget(
column
.paragraph
@ -531,7 +551,9 @@ impl Ui {
}
fn render_minibuffer<B: Backend>(state: &AppPublicState, ar: Rect, fr: &mut Frame<'_, B>) {
let paragraphs = Minibuffer::paragraphs(state)
let mut mb = Minibuffer::paragraphs(state);
mb.paragraphs = mb
.paragraphs
.into_iter()
.map(|p| p.alignment(Alignment::Center))
.collect();
@ -544,7 +566,7 @@ impl Ui {
};
Self::render_info_widget("Minibuffer", Paragraph::new(""), false, ar, fr);
Self::render_columns(paragraphs, false, area, fr);
Self::render_columns(mb.paragraphs, mb.columns, false, area, fr);
}
fn render_main_frame<B: Backend>(