Appeal button for dictionary test
This commit is contained in:
+32
-9
@@ -19,7 +19,7 @@ pub struct DictionaryQuizState {
|
|||||||
score: Score,
|
score: Score,
|
||||||
is_help: bool,
|
is_help: bool,
|
||||||
reverse: bool,
|
reverse: bool,
|
||||||
laps: u32
|
laps: u32,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum DictionaryQuizMessage {
|
pub enum DictionaryQuizMessage {
|
||||||
@@ -27,6 +27,7 @@ pub enum DictionaryQuizMessage {
|
|||||||
Back,
|
Back,
|
||||||
AnswerChanged(String),
|
AnswerChanged(String),
|
||||||
SubmitAnswer,
|
SubmitAnswer,
|
||||||
|
Appeal,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<DictionaryQuizMessage> for DictionaryQuizState {
|
impl NavigatedPage<DictionaryQuizMessage> for DictionaryQuizState {
|
||||||
@@ -49,7 +50,7 @@ impl DictionaryQuizState {
|
|||||||
score: Default::default(),
|
score: Default::default(),
|
||||||
is_help: false,
|
is_help: false,
|
||||||
reverse,
|
reverse,
|
||||||
laps: 0
|
laps: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +62,7 @@ impl DictionaryQuizState {
|
|||||||
DictionaryQuizMessage::Back => {}
|
DictionaryQuizMessage::Back => {}
|
||||||
DictionaryQuizMessage::AnswerChanged(c) => self.answer = c.clone(),
|
DictionaryQuizMessage::AnswerChanged(c) => self.answer = c.clone(),
|
||||||
DictionaryQuizMessage::SubmitAnswer => self.submit(),
|
DictionaryQuizMessage::SubmitAnswer => self.submit(),
|
||||||
|
DictionaryQuizMessage::Appeal => self.appeal_answer(),
|
||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
@@ -97,7 +99,11 @@ impl DictionaryQuizState {
|
|||||||
.size(25),
|
.size(25),
|
||||||
]
|
]
|
||||||
.spacing(10),
|
.spacing(10),
|
||||||
|
row![
|
||||||
button("Закончить").on_press(DictionaryQuizMessage::Back),
|
button("Закончить").on_press(DictionaryQuizMessage::Back),
|
||||||
|
self.appeal_button()
|
||||||
|
]
|
||||||
|
.spacing(10),
|
||||||
]
|
]
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.align_x(alignment::Horizontal::Center),
|
.align_x(alignment::Horizontal::Center),
|
||||||
@@ -117,13 +123,14 @@ impl DictionaryQuizState {
|
|||||||
if !self.is_help {
|
if !self.is_help {
|
||||||
self.score.total += 1;
|
self.score.total += 1;
|
||||||
}
|
}
|
||||||
if self.answer == self.correct || split_with_coma(self.correct.clone()).contains(&self.answer) {
|
if self.answer == self.correct
|
||||||
|
|| split_with_coma(self.correct.clone()).contains(&self.answer)
|
||||||
|
{
|
||||||
if self.is_help == false {
|
if self.is_help == false {
|
||||||
self.score.correct += 1;
|
self.score.correct += 1;
|
||||||
}
|
}
|
||||||
self.show_next()
|
self.show_next()
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
self.score.fail += 1;
|
self.score.fail += 1;
|
||||||
self.is_help = true;
|
self.is_help = true;
|
||||||
}
|
}
|
||||||
@@ -158,20 +165,36 @@ impl DictionaryQuizState {
|
|||||||
fn laps(&self) -> Element<'_, DictionaryQuizMessage> {
|
fn laps(&self) -> Element<'_, DictionaryQuizMessage> {
|
||||||
let mut col = Row::new();
|
let mut col = Row::new();
|
||||||
for _ in 0..self.laps {
|
for _ in 0..self.laps {
|
||||||
col = col.push(iced::widget::container(space().height(15).width(15)).style(|x: &Theme| {
|
col = col.push(iced::widget::container(space().height(15).width(15)).style(
|
||||||
Style{
|
|x: &Theme| Style {
|
||||||
text_color: None,
|
text_color: None,
|
||||||
background: Some(Color(x.palette().primary)),
|
background: Some(Color(x.palette().primary)),
|
||||||
border: Border{
|
border: Border {
|
||||||
color: Default::default(),
|
color: Default::default(),
|
||||||
width: 0.0,
|
width: 0.0,
|
||||||
radius: Radius::new(5),
|
radius: Radius::new(5),
|
||||||
},
|
},
|
||||||
shadow: Default::default(),
|
shadow: Default::default(),
|
||||||
snap: false,
|
snap: false,
|
||||||
}
|
},
|
||||||
}));
|
));
|
||||||
}
|
}
|
||||||
col.spacing(10).into()
|
col.spacing(10).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn appeal_button(&self) -> iced::Element<'_, DictionaryQuizMessage> {
|
||||||
|
if self.is_help {
|
||||||
|
return button("Апелляция")
|
||||||
|
.on_press(DictionaryQuizMessage::Appeal)
|
||||||
|
.into();
|
||||||
|
}
|
||||||
|
space().into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn appeal_answer(&mut self) {
|
||||||
|
self.score.correct += 1;
|
||||||
|
self.score.fail -= 1;
|
||||||
|
self.answer = self.correct.clone();
|
||||||
|
self.show_next()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -11,14 +11,14 @@ use crate::selector::*;
|
|||||||
use crate::writing::{WritingMessage, WritingState};
|
use crate::writing::{WritingMessage, WritingState};
|
||||||
use crate::Page::{Dictionary, DictionaryQuiz, Quiz, Selector, Writing};
|
use crate::Page::{Dictionary, DictionaryQuiz, Quiz, Selector, Writing};
|
||||||
use iced::widget::text;
|
use iced::widget::text;
|
||||||
use iced::Task;
|
use iced::{Font, Task};
|
||||||
use iced::Element;
|
use iced::Element;
|
||||||
use crate::dictionary::{DictionaryMessage, DictionaryState};
|
use crate::dictionary::{DictionaryMessage, DictionaryState};
|
||||||
use crate::dictionary_test::{DictionaryQuizMessage, DictionaryQuizState};
|
use crate::dictionary_test::{DictionaryQuizMessage, DictionaryQuizState};
|
||||||
|
|
||||||
fn main() -> iced::Result {
|
fn main() -> iced::Result {
|
||||||
iced::application(ScreenState::boot, ScreenState::update, ScreenState::view)
|
iced::application(ScreenState::boot, ScreenState::update, ScreenState::view)
|
||||||
.title("Kana learn app").font(include_bytes!("../noto.ttf")).run()
|
.title("Kana learn app").font(include_bytes!("../noto.ttf")).default_font(Font::with_name("Noto Sans JP")).run()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|||||||
Reference in New Issue
Block a user