diff --git a/src/quiz.rs b/src/quiz.rs index 11a214d..6099bfa 100644 --- a/src/quiz.rs +++ b/src/quiz.rs @@ -69,6 +69,10 @@ impl QuizState { self.is_help = false; self.score.total += 1; self.update_showed() + } else if self.current_roman.len() == self.correct_roman.len() { + self.score.total += 1; + self.score.fail += 1; + self.update_showed() } } QuizMessage::Back => todo!(), @@ -96,8 +100,7 @@ impl QuizState { container( iced::widget::column![ row![ - text!("{}", self.kana.to_uppercase()) - .size(54), + text!("{}", self.kana.to_uppercase()).size(54), text!( "{}", if self.is_help { @@ -128,7 +131,7 @@ impl QuizState { .spacing(10) .align_x(alignment::Horizontal::Center), ) - .center_y(Fill) + .center_y(Fill) .center_x(Fill) .into() } diff --git a/src/writing.rs b/src/writing.rs index d48bd72..da01084 100644 --- a/src/writing.rs +++ b/src/writing.rs @@ -13,6 +13,7 @@ pub struct WritingState { kana_total: String, roman_total: String, next_text: String, + show_all: bool, } impl NavigatedPage for WritingState { @@ -36,6 +37,7 @@ impl WritingState { kana_total: "".to_string(), roman_total: "".to_string(), next_text: "Дальше".to_string(), + show_all: false, } } } @@ -45,6 +47,7 @@ impl WritingState { match message { WritingMessage::Back => todo!(), WritingMessage::Next => self.next(), + WritingMessage::SwitchShowMode(b) => self.show_all = b, } } @@ -59,16 +62,33 @@ impl WritingState { return; } - let current = self.set.pop().unwrap(); - self.kana_total += &*format!("{} ", ¤t.0).to_string(); - self.roman_total += &*format!("{} ", ¤t.1.clone()).to_string(); - self.kana = current.1; + if self.show_all { + + if self.set.is_empty() == false && self.kana_total.is_empty() == false { + self.set.clear(); + } + for pair in &self.set { + self.kana = "---".to_string(); + self.roman_total += &*format!("{} ", &pair.1.clone()).to_string(); + self.kana_total += &*format!("{} ", &pair.0).to_string(); + } + + + } else { + let current = self.set.pop().unwrap(); + self.kana_total += &*format!("{} ", ¤t.0).to_string(); + self.roman_total += &*format!("{} ", ¤t.1.clone()).to_string(); + self.kana = current.1; + } } pub fn view(&self) -> Element<'_, WritingMessage> { container( iced::widget::column![ - text!("{}", self.roman_total).size(24), + checkbox(self.show_all) + .label("Показывать все сразу") + .on_toggle(WritingMessage::SwitchShowMode), + text!("{}", self.roman_total).size(34), text!("{}", self.kana).size(48), self.answers(), row![ @@ -82,15 +102,13 @@ impl WritingState { ) .center_x(Fill) .center_y(Fill) - .padding(10) + .padding(10) .into() } fn answers(&self) -> Element<'_, WritingMessage> { - if self.set.is_empty() { - text!("{}", self.kana_total) - .size(36) - .into() + if self.set.is_empty() { + text!("{}", self.kana_total).size(36).into() } else { space().height(36).into() } @@ -100,4 +118,5 @@ impl WritingState { pub enum WritingMessage { Next, Back, -} \ No newline at end of file + SwitchShowMode(bool), +}