Optionally show all in writing test and update answers validation system

This commit is contained in:
2026-02-16 14:05:35 +03:00
parent 7448e71ca9
commit 170ccfc0fb
2 changed files with 36 additions and 14 deletions
+5 -2
View File
@@ -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 {
+23 -4
View File
@@ -13,6 +13,7 @@ pub struct WritingState {
kana_total: String,
roman_total: String,
next_text: String,
show_all: bool,
}
impl NavigatedPage<WritingMessage> 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;
}
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!("{} ", &current.0).to_string();
self.roman_total += &*format!("{} ", &current.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![
@@ -88,9 +108,7 @@ impl WritingState {
fn answers(&self) -> Element<'_, WritingMessage> {
if self.set.is_empty() {
text!("{}", self.kana_total)
.size(36)
.into()
text!("{}", self.kana_total).size(36).into()
} else {
space().height(36).into()
}
@@ -100,4 +118,5 @@ impl WritingState {
pub enum WritingMessage {
Next,
Back,
SwitchShowMode(bool),
}