From 3adf3f9697c4e2beb10e652947046d5fddda2ed4 Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 12 Feb 2022 16:57:19 +0100 Subject: Say when the next card will be available --- src/gui/question.rs | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'src/gui/question.rs') diff --git a/src/gui/question.rs b/src/gui/question.rs index 64589d9..e88d6e5 100644 --- a/src/gui/question.rs +++ b/src/gui/question.rs @@ -1,4 +1,5 @@ use crate::{ + gui::util, model::{card::Card, difficulty, difficulty::Difficulty}, util::event::{Event, Events}, util::serialization, @@ -7,7 +8,7 @@ use anyhow::Result; use termion::event::Key; use tui::{ backend::Backend, - layout::{Alignment, Constraint, Direction, Layout, Rect}, + layout::{Alignment, Constraint, Direction, Layout}, style::{Color, Modifier, Style}, text::{Span, Spans, Text}, widgets::{Block, Borders, Paragraph, Wrap}, @@ -28,7 +29,7 @@ pub fn ask( terminal: &mut Terminal, events: &Events, card: &Card, - deck: String, + deck_name: &String, ) -> Result { let mut state = State { input: String::new(), @@ -52,16 +53,10 @@ pub fn ask( ) .split(f.size()); - let d1 = Paragraph::new(format!("{}", deck)) - .alignment(Alignment::Center) - .style( - Style::default() - .fg(Color::Blue) - .add_modifier(Modifier::BOLD), - ); + let d1 = util::title(deck_name); f.render_widget(d1, chunks[0]); - let question = Paragraph::new(center_vertically(chunks[1], &card.question)) + let question = Paragraph::new(util::center_vertically(chunks[1], &card.question)) .style(match state.answer { Answer::Write => { if state.input == "" { @@ -75,7 +70,7 @@ pub fn ask( .alignment(Alignment::Center); f.render_widget(question, chunks[1]); - let answer = Paragraph::new(center_vertically(chunks[2], &state.input)) + let answer = Paragraph::new(util::center_vertically(chunks[2], &state.input)) .style(match state.answer { Answer::Write => Style::default(), Answer::Difficulty { difficulty: _ } => { @@ -96,7 +91,7 @@ pub fn ask( difficulty: selected, } => { if !is_correct(&state.input, &card.responses) || card.responses.len() > 1 { - let paragraph = Paragraph::new(center_vertically( + let paragraph = Paragraph::new(util::center_vertically( chunks[3], &serialization::words_to_line(&card.responses), )) @@ -176,14 +171,6 @@ pub fn ask( } } -fn center_vertically(chunk: Rect, text: &String) -> String { - let text_lines = text.lines().count(); - let chunk_inner_lines: usize = (chunk.height - 2).into(); - let blank_lines = chunk_inner_lines - text_lines; - let newlines = "\n".repeat(blank_lines / 2); - format!("{}{}", newlines, text) -} - fn is_correct(input: &String, responses: &Vec) -> bool { responses .iter() -- cgit v1.2.3