Add basic methods into NavigatedPage
This commit is contained in:
+50
-48
@@ -30,34 +30,8 @@ impl NavigatedPage<QuizMessage> for QuizState {
|
||||
|
||||
fn navigated(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
impl QuizState {
|
||||
pub(crate) fn new() -> QuizState {
|
||||
QuizState {
|
||||
kana: "ぁ".to_string(),
|
||||
correct_roman: "a".to_string(),
|
||||
is_help: false,
|
||||
current_roman: "".to_string(),
|
||||
set: KanaSet::hiragana(),
|
||||
queue: Vec::new(),
|
||||
score: Score {
|
||||
total: 0,
|
||||
correct: 0,
|
||||
fail: 0,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for QuizState {
|
||||
fn default() -> Self {
|
||||
QuizState::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl QuizState {
|
||||
pub fn update(&mut self, message: QuizMessage) -> Task<RootMessage> {
|
||||
fn update(&mut self, message: QuizMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
ContentChanged(content) => {
|
||||
if content.contains("`") {
|
||||
@@ -86,24 +60,9 @@ impl QuizState {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn update_showed(&mut self) {
|
||||
self.current_roman = String::new();
|
||||
let queue = &mut self.queue;
|
||||
|
||||
if queue.is_empty() {
|
||||
for pair in self.set.list() {
|
||||
queue.push(pair);
|
||||
}
|
||||
|
||||
queue.shuffle(&mut rand::rng());
|
||||
}
|
||||
|
||||
let pair = self.queue.pop().unwrap();
|
||||
self.kana = pair.0;
|
||||
self.correct_roman = pair.1;
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, QuizMessage> {
|
||||
fn view(&self) -> Element<'_, QuizMessage> {
|
||||
container(
|
||||
iced::widget::column![
|
||||
row![
|
||||
@@ -137,12 +96,55 @@ impl QuizState {
|
||||
.spacing(DEFAULT_SPACING),
|
||||
button("Закончить").style(jl_button).on_press(Back),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.align_x(alignment::Horizontal::Center),
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.align_x(alignment::Horizontal::Center),
|
||||
)
|
||||
.center_y(Fill)
|
||||
.center_x(Fill)
|
||||
.into()
|
||||
.center_y(Fill)
|
||||
.center_x(Fill)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl QuizState {
|
||||
pub(crate) fn new() -> QuizState {
|
||||
QuizState {
|
||||
kana: "ぁ".to_string(),
|
||||
correct_roman: "a".to_string(),
|
||||
is_help: false,
|
||||
current_roman: "".to_string(),
|
||||
set: KanaSet::hiragana(),
|
||||
queue: Vec::new(),
|
||||
score: Score {
|
||||
total: 0,
|
||||
correct: 0,
|
||||
fail: 0,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for QuizState {
|
||||
fn default() -> Self {
|
||||
QuizState::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl QuizState {
|
||||
fn update_showed(&mut self) {
|
||||
self.current_roman = String::new();
|
||||
let queue = &mut self.queue;
|
||||
|
||||
if queue.is_empty() {
|
||||
for pair in self.set.list() {
|
||||
queue.push(pair);
|
||||
}
|
||||
|
||||
queue.shuffle(&mut rand::rng());
|
||||
}
|
||||
|
||||
let pair = self.queue.pop().unwrap();
|
||||
self.kana = pair.0;
|
||||
self.correct_roman = pair.1;
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user