diff options
author | Joris | 2022-02-12 16:57:19 +0100 |
---|---|---|
committer | Joris | 2022-02-12 16:57:19 +0100 |
commit | 3adf3f9697c4e2beb10e652947046d5fddda2ed4 (patch) | |
tree | 689e704cf4665cc4cd1949c06d4a7b0553d07501 /src/gui/question.rs | |
parent | a2ba205df12332a360d89991fe508f964d88c73f (diff) | |
download | flashcards-3adf3f9697c4e2beb10e652947046d5fddda2ed4.tar.gz flashcards-3adf3f9697c4e2beb10e652947046d5fddda2ed4.tar.bz2 flashcards-3adf3f9697c4e2beb10e652947046d5fddda2ed4.zip |
Say when the next card will be available
Diffstat (limited to 'src/gui/question.rs')
-rw-r--r-- | src/gui/question.rs | 27 |
1 files changed, 7 insertions, 20 deletions
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<B: Backend>( terminal: &mut Terminal<B>, events: &Events, card: &Card, - deck: String, + deck_name: &String, ) -> Result<Difficulty> { let mut state = State { input: String::new(), @@ -52,16 +53,10 @@ pub fn ask<B: Backend>( ) .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<B: Backend>( .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<B: Backend>( 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<B: Backend>( } } -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<String>) -> bool { responses .iter() |