Add dictionary and dictionary quiz pages
This commit is contained in:
@@ -0,0 +1,317 @@
|
||||
use crate::dictionary::DictionaryMessage::Test;
|
||||
use crate::dictionary_test::DictionaryQuizState;
|
||||
use crate::{NavigatedPage, Page, RootMessage};
|
||||
use iced::alignment::Vertical::Center;
|
||||
use iced::widget::button::Style;
|
||||
use iced::widget::*;
|
||||
use iced::{Border, Color, Length, Shadow, Task};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use DictionaryMessage::Back;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DictionaryState {
|
||||
dict: Vec<DictionaryElement>,
|
||||
include_map: Vec<bool>,
|
||||
tag_map: HashMap<String, bool>,
|
||||
reverse: bool
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct DictionaryElement {
|
||||
pub key: String,
|
||||
pub value: String,
|
||||
pub tags: String,
|
||||
}
|
||||
|
||||
impl DictionaryElement {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
key: String::new(),
|
||||
value: String::new(),
|
||||
tags: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum DictionaryMessage {
|
||||
Back,
|
||||
SetTags(usize, String),
|
||||
SetKey(usize, String),
|
||||
SetValue(usize, String),
|
||||
Remove(usize),
|
||||
NewWord,
|
||||
Include(usize, bool),
|
||||
IncludeTag(String, bool),
|
||||
Save,
|
||||
Test,
|
||||
ResetTags,
|
||||
SetReverse(bool),
|
||||
}
|
||||
|
||||
impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
fn navigate(&self, message: &DictionaryMessage) -> Option<Page> {
|
||||
if let Back = message {
|
||||
return Some(Page::PreviousPage);
|
||||
}
|
||||
if let Test = message {
|
||||
if self.include_map.iter().any(|x| *x) {
|
||||
let mut words = vec![];
|
||||
for i in 0..self.include_map.len(){
|
||||
if self.include_map[i] {
|
||||
words.push(self.dict[i].clone());
|
||||
}
|
||||
}
|
||||
return Some(Page::DictionaryQuiz(DictionaryQuizState::new(words, self.reverse)))
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DictionaryState {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
impl DictionaryState {
|
||||
pub fn new() -> Self {
|
||||
let mut current_dict = "[]".to_string();
|
||||
match File::open(dict_file()) {
|
||||
Ok(mut f) => {
|
||||
current_dict = String::new();
|
||||
f.read_to_string(&mut current_dict).unwrap();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
let list: Vec<DictionaryElement> = serde_json::from_str(¤t_dict).unwrap();
|
||||
let mut result = DictionaryState {
|
||||
include_map: vec![false; list.len()],
|
||||
dict: list,
|
||||
tag_map: HashMap::new(),
|
||||
reverse: false,
|
||||
};
|
||||
|
||||
result.update_tags();
|
||||
result
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: DictionaryMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
DictionaryMessage::NewWord => {
|
||||
self.dict.push(DictionaryElement::new());
|
||||
self.include_map.push(false);
|
||||
}
|
||||
DictionaryMessage::SetKey(i, v) => self.dict[i].key = v,
|
||||
DictionaryMessage::SetValue(i, v) => self.dict[i].value = v,
|
||||
DictionaryMessage::SetTags(i, v) => {
|
||||
self.dict[i].tags = v;
|
||||
self.update_tags();
|
||||
}
|
||||
DictionaryMessage::Remove(i) => {
|
||||
self.dict.remove(i);
|
||||
}
|
||||
DictionaryMessage::Include(i, b) => self.include_map[i] = b,
|
||||
DictionaryMessage::IncludeTag(t, v) => {
|
||||
println!("Including tag {}", t);
|
||||
self.tag_map.insert(t, v);
|
||||
self.update_words_include()
|
||||
}
|
||||
DictionaryMessage::ResetTags => {
|
||||
self.tag_map.iter_mut().for_each(|(_, v)| *v = false);
|
||||
self.include_map.iter_mut().for_each(|x| *x = false)
|
||||
}
|
||||
DictionaryMessage::Save => {
|
||||
let dir = dict_file();
|
||||
let content = serde_json::to_string_pretty(&self.dict.clone()).unwrap();
|
||||
fs::write(dir, content.clone())
|
||||
.unwrap_or_else(|e| println!("Can't write file: {}", e));
|
||||
println!("{}", content);
|
||||
},
|
||||
DictionaryMessage::SetReverse(v) => self.reverse = v,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Task::none()
|
||||
}
|
||||
|
||||
pub fn view(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||
container(row![
|
||||
iced::widget::column![
|
||||
button("Назад").on_press(Back),
|
||||
self.words_list(),
|
||||
row![
|
||||
button("Добавить слово").on_press(DictionaryMessage::NewWord),
|
||||
button("Сохранить словарь").on_press(DictionaryMessage::Save),
|
||||
]
|
||||
.spacing(10)
|
||||
]
|
||||
.spacing(5)
|
||||
.padding(10),
|
||||
self.filters()
|
||||
])
|
||||
.padding(10)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn words_list(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||
let mut col = Column::new().width(Length::Fill);
|
||||
|
||||
let mut i = 0;
|
||||
for word in &self.dict {
|
||||
let mut line = Row::new().width(Length::Fill).align_y(Center);
|
||||
line = line
|
||||
.push(
|
||||
checkbox(self.include_map[i])
|
||||
.on_toggle(move |b| DictionaryMessage::Include(i, b)),
|
||||
)
|
||||
.push(space().width(10));
|
||||
|
||||
line = line.push(
|
||||
text_input("Ключ", &word.key).size(20)
|
||||
.width(Length::Fill)
|
||||
.on_input(move |string| DictionaryMessage::SetKey(i, string)),
|
||||
);
|
||||
line = line.push(
|
||||
text_input("Значение", &word.value).size(20)
|
||||
.width(Length::Fill)
|
||||
.on_input(move |string| DictionaryMessage::SetValue(i, string)),
|
||||
);
|
||||
line = line.push(
|
||||
text_input("Тэги", &word.tags).size(20)
|
||||
.width(Length::Fill)
|
||||
.on_input(move |string| DictionaryMessage::SetTags(i, string)),
|
||||
);
|
||||
|
||||
line = line
|
||||
.push(
|
||||
button("-")
|
||||
.on_press_with(move || DictionaryMessage::Remove(i))
|
||||
.style(|_x, _status| Style {
|
||||
background: None,
|
||||
text_color: Color::BLACK,
|
||||
border: Border::default(),
|
||||
shadow: Shadow::default(),
|
||||
snap: false,
|
||||
}),
|
||||
)
|
||||
.push(space().width(10));
|
||||
|
||||
col = col.push(line);
|
||||
i += 1;
|
||||
}
|
||||
|
||||
scrollable(col).height(Length::Fill).into()
|
||||
}
|
||||
|
||||
fn filters(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||
iced::widget::column![
|
||||
text!("Всего слов: {}", self.dict.len()),
|
||||
text!(
|
||||
"Выбрано слов: {}",
|
||||
self.include_map.iter().filter(|i| **i).count()
|
||||
),
|
||||
self.tags_selector(),
|
||||
toggler(self.reverse).label("Обратный тест").on_toggle(DictionaryMessage::SetReverse),
|
||||
button(text!("Тест").center().width(Length::Fill))
|
||||
.on_press(Test)
|
||||
.width(Length::Fill),
|
||||
]
|
||||
.width(250)
|
||||
.spacing(10)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn tags_selector(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||
let mut col = Column::new().width(Length::Fill);
|
||||
col = col.push(
|
||||
button("Сбросить")
|
||||
.on_press(DictionaryMessage::ResetTags)
|
||||
.style(|x: &Theme, _status| Style {
|
||||
background: None,
|
||||
text_color: x.palette().primary,
|
||||
border: Border::default(),
|
||||
shadow: Shadow::default(),
|
||||
snap: false,
|
||||
}),
|
||||
);
|
||||
for tag in &self.tag_map {
|
||||
col = col.push(
|
||||
checkbox(*tag.1)
|
||||
.label(tag.0)
|
||||
.on_toggle(|x1| DictionaryMessage::IncludeTag(tag.0.clone(), x1)),
|
||||
)
|
||||
}
|
||||
|
||||
container(scrollable(col)).height(Length::Fill).into()
|
||||
}
|
||||
|
||||
fn update_tags(&mut self) {
|
||||
let mut tags_list: Vec<String> = vec![];
|
||||
for element in &self.dict {
|
||||
tags_list.append(&mut to_tags_list(element.tags.clone()));
|
||||
}
|
||||
|
||||
let current_tags = self
|
||||
.tag_map
|
||||
.keys()
|
||||
.map(|k| k.clone().to_string())
|
||||
.collect::<Vec<String>>();
|
||||
for current in current_tags {
|
||||
if !tags_list.contains(¤t) {
|
||||
self.tag_map.remove(¤t.clone());
|
||||
}
|
||||
}
|
||||
|
||||
for found_tag in &tags_list {
|
||||
if !self.tag_map.contains_key(&found_tag.clone()) {
|
||||
self.tag_map.insert(found_tag.clone(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_words_include(&mut self) {
|
||||
let include_tags = self
|
||||
.tag_map
|
||||
.iter()
|
||||
.filter(|i| *(*i).1)
|
||||
.map(|(t, _)| t.clone())
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
println!("Including include tags: {:?}", include_tags);
|
||||
|
||||
if include_tags.is_empty() {
|
||||
self.include_map.iter_mut().for_each(|x| *x = false);
|
||||
return;
|
||||
}
|
||||
|
||||
for i in 0..self.include_map.len() {
|
||||
let tags = to_tags_list(self.dict[i].tags.clone());
|
||||
if tags.iter().any(|t| include_tags.contains(t)) {
|
||||
self.include_map[i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn to_tags_list(ts: String) -> Vec<String> {
|
||||
ts.split(',')
|
||||
.map(|ts| ts.to_lowercase().trim().to_string())
|
||||
.filter(|t| !t.is_empty())
|
||||
.collect::<Vec<String>>()
|
||||
}
|
||||
|
||||
fn dict_file() -> PathBuf {
|
||||
let mut dir = dirs::data_dir().unwrap();
|
||||
dir.push("jap_learn");
|
||||
if !dir.exists() {
|
||||
fs::create_dir(dir.clone()).unwrap();
|
||||
}
|
||||
dir.push("dict.json");
|
||||
dir
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
use crate::dictionary::DictionaryElement;
|
||||
use crate::quiz::Score;
|
||||
use crate::Page::PreviousPage;
|
||||
use crate::RootMessage;
|
||||
use crate::{NavigatedPage, Page};
|
||||
use iced::widget::{button, container, row, text, text_input};
|
||||
use iced::{alignment, Fill, Task};
|
||||
use rand::prelude::SliceRandom;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DictionaryQuizState {
|
||||
words: Vec<DictionaryElement>,
|
||||
current_set: Vec<DictionaryElement>,
|
||||
answer: String,
|
||||
view: String,
|
||||
correct: String,
|
||||
score: Score,
|
||||
is_help: bool,
|
||||
reverse: bool,
|
||||
}
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum DictionaryQuizMessage {
|
||||
Next,
|
||||
Back,
|
||||
AnswerChanged(String),
|
||||
SubmitAnswer,
|
||||
}
|
||||
|
||||
impl NavigatedPage<DictionaryQuizMessage> for DictionaryQuizState {
|
||||
fn navigate(&self, message: &DictionaryQuizMessage) -> Option<Page> {
|
||||
match message {
|
||||
DictionaryQuizMessage::Back => Some(PreviousPage),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DictionaryQuizState {
|
||||
pub fn new(words: Vec<DictionaryElement>, reverse: bool) -> DictionaryQuizState {
|
||||
DictionaryQuizState {
|
||||
words,
|
||||
current_set: Vec::new(),
|
||||
answer: "".to_string(),
|
||||
view: "---".to_string(),
|
||||
correct: "".to_string(),
|
||||
score: Default::default(),
|
||||
is_help: false,
|
||||
reverse: reverse,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: DictionaryQuizMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
DictionaryQuizMessage::Next => {
|
||||
self.next();
|
||||
}
|
||||
DictionaryQuizMessage::Back => {}
|
||||
DictionaryQuizMessage::AnswerChanged(c) => self.answer = c.clone(),
|
||||
DictionaryQuizMessage::SubmitAnswer => self.submit(),
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
pub fn view(&self) -> iced::Element<'_, DictionaryQuizMessage> {
|
||||
container(
|
||||
iced::widget::column![
|
||||
row![
|
||||
text!("{}", self.view).size(54),
|
||||
text!(
|
||||
"{}",
|
||||
if self.is_help {
|
||||
self.correct.clone()
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
),
|
||||
]
|
||||
.align_y(alignment::Vertical::Center)
|
||||
.spacing(20),
|
||||
text_input("Перевод", &self.answer)
|
||||
.size(28)
|
||||
.width(150)
|
||||
.on_input(DictionaryQuizMessage::AnswerChanged)
|
||||
.on_submit(DictionaryQuizMessage::SubmitAnswer),
|
||||
row![
|
||||
text!("{}", self.score.total.to_string()).size(25),
|
||||
text!("{}", self.score.correct.to_string())
|
||||
.size(25)
|
||||
.color(iced::Color::from_rgb8(60, 170, 60)),
|
||||
text!("{}", self.score.fail.to_string())
|
||||
.color(iced::Color::from_rgb8(255, 79, 0))
|
||||
.size(25),
|
||||
]
|
||||
.spacing(10),
|
||||
button("Закончить").on_press(DictionaryQuizMessage::Back),
|
||||
]
|
||||
.spacing(10)
|
||||
.align_x(alignment::Horizontal::Center),
|
||||
)
|
||||
.center_y(Fill)
|
||||
.center_x(Fill)
|
||||
.into()
|
||||
}
|
||||
fn next(&mut self) {}
|
||||
|
||||
fn submit(&mut self) {
|
||||
if self.view == "---" {
|
||||
self.show_next();
|
||||
return;
|
||||
}
|
||||
|
||||
if !self.is_help {
|
||||
self.score.total += 1;
|
||||
}
|
||||
if self.answer == self.correct {
|
||||
if self.is_help == false {
|
||||
self.score.correct += 1;
|
||||
}
|
||||
self.show_next()
|
||||
} else {
|
||||
self.score.fail += 1;
|
||||
self.is_help = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn update_set(&mut self) {
|
||||
self.current_set.append(&mut self.words.clone());
|
||||
self.current_set.shuffle(&mut rand::rng())
|
||||
}
|
||||
|
||||
fn show_next(&mut self) {
|
||||
self.is_help = false;
|
||||
self.answer = String::new();
|
||||
|
||||
if self.current_set.is_empty() {
|
||||
self.update_set();
|
||||
}
|
||||
|
||||
let next = self.current_set.pop().unwrap();
|
||||
if self.reverse {
|
||||
self.view = next.value.clone();
|
||||
self.correct = next.key.clone();
|
||||
} else {
|
||||
self.view = next.key.clone();
|
||||
self.correct = next.value.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-6
@@ -3,14 +3,18 @@ mod lang;
|
||||
mod quiz;
|
||||
mod selector;
|
||||
mod writing;
|
||||
mod dictionary;
|
||||
mod dictionary_test;
|
||||
|
||||
use crate::quiz::*;
|
||||
use crate::selector::*;
|
||||
use crate::writing::{WritingMessage, WritingState};
|
||||
use crate::Page::{Quiz, Selector, Writing};
|
||||
use crate::Page::{Dictionary, DictionaryQuiz, Quiz, Selector, Writing};
|
||||
use iced::widget::text;
|
||||
use iced::Task;
|
||||
use iced::Element;
|
||||
use crate::dictionary::{DictionaryMessage, DictionaryState};
|
||||
use crate::dictionary_test::{DictionaryQuizMessage, DictionaryQuizState};
|
||||
|
||||
fn main() -> iced::Result {
|
||||
iced::application(ScreenState::boot, ScreenState::update, ScreenState::view)
|
||||
@@ -22,12 +26,16 @@ pub enum RootMessage {
|
||||
Selector(SelectorMessage),
|
||||
Quiz(QuizMessage),
|
||||
Writing(WritingMessage),
|
||||
Dictionary(DictionaryMessage),
|
||||
DictionaryQuiz(DictionaryQuizMessage),
|
||||
}
|
||||
|
||||
enum Page {
|
||||
Selector(SelectorState),
|
||||
Quiz(QuizState),
|
||||
Writing(WritingState),
|
||||
Dictionary(DictionaryState),
|
||||
DictionaryQuiz(DictionaryQuizState),
|
||||
PreviousPage,
|
||||
}
|
||||
|
||||
@@ -53,12 +61,13 @@ impl ScreenState {
|
||||
pub fn boot() -> (ScreenState, Task<RootMessage>){
|
||||
(ScreenState::default(), Task::none())
|
||||
}
|
||||
pub fn update(&mut self, message: RootMessage) {
|
||||
state_update!(message, self.stack, Selector, Quiz, Writing);
|
||||
pub fn update(&mut self, message: RootMessage) -> Task<RootMessage> {
|
||||
state_update!(message, self.stack, Selector, Quiz, Writing, Dictionary, DictionaryQuiz);
|
||||
Task::none()
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, RootMessage> {
|
||||
view_navigation!(self.stack, Quiz, Selector, Writing)
|
||||
view_navigation!(self.stack, Quiz, Selector, Writing, Dictionary, DictionaryQuiz)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,11 +104,11 @@ macro_rules! message_navigation {
|
||||
if let Some(new_page) = $state.navigate(&$msg) {
|
||||
if let Page::PreviousPage = new_page {
|
||||
$stack.pop();
|
||||
return;
|
||||
return Task::none();
|
||||
}
|
||||
$stack.push(new_page);
|
||||
} else {
|
||||
$state.update($msg);
|
||||
return $state.update($msg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+8
-7
@@ -1,8 +1,8 @@
|
||||
use crate::lang::KanaSet;
|
||||
use crate::Page::PreviousPage;
|
||||
use crate::{NavigatedPage, Page};
|
||||
use crate::{NavigatedPage, Page, RootMessage};
|
||||
use iced::widget::*;
|
||||
use iced::{alignment, Element, Fill};
|
||||
use iced::{alignment, Element, Fill, Task};
|
||||
use rand::seq::SliceRandom;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -51,14 +51,14 @@ impl Default for QuizState {
|
||||
}
|
||||
|
||||
impl QuizState {
|
||||
pub fn update(&mut self, message: QuizMessage) {
|
||||
pub fn update(&mut self, message: QuizMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
QuizMessage::ContentChanged(content) => {
|
||||
if content.contains("`") {
|
||||
self.is_help = true;
|
||||
self.score.fail += 1;
|
||||
|
||||
return;
|
||||
return Task::none();
|
||||
}
|
||||
self.current_roman = content;
|
||||
if self.correct_roman == self.current_roman {
|
||||
@@ -77,6 +77,7 @@ impl QuizState {
|
||||
}
|
||||
QuizMessage::Back => todo!(),
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn update_showed(&mut self) {
|
||||
@@ -144,7 +145,7 @@ pub enum QuizMessage {
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct Score {
|
||||
total: i32,
|
||||
correct: i32,
|
||||
fail: i32,
|
||||
pub(crate) total: i32,
|
||||
pub(crate) correct: i32,
|
||||
pub(crate) fail: i32,
|
||||
}
|
||||
|
||||
+15
-11
@@ -2,9 +2,10 @@ use crate::lang::{KanaSet, KanaType};
|
||||
use crate::selector::SelectorMessage::ChangeMode;
|
||||
use crate::writing::WritingState;
|
||||
use crate::Page::{Quiz, Writing};
|
||||
use crate::{NavigatedPage, Page, QuizState};
|
||||
use crate::{NavigatedPage, Page, QuizState, RootMessage};
|
||||
use iced::widget::*;
|
||||
use iced::{alignment, Element};
|
||||
use iced::{alignment, Element, Task};
|
||||
use crate::dictionary::DictionaryState;
|
||||
|
||||
pub struct SelectorState {
|
||||
pub set: KanaSet,
|
||||
@@ -26,6 +27,7 @@ pub enum SelectorMessage {
|
||||
Goto,
|
||||
Check(usize, bool),
|
||||
ChangeMode(bool),
|
||||
ToDictionary,
|
||||
}
|
||||
|
||||
impl NavigatedPage<SelectorMessage> for SelectorState {
|
||||
@@ -40,27 +42,32 @@ impl NavigatedPage<SelectorMessage> for SelectorState {
|
||||
Some(Quiz(quiz))
|
||||
};
|
||||
}
|
||||
if let SelectorMessage::ToDictionary = message {
|
||||
return Some(Page::Dictionary(DictionaryState::default()))
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl SelectorState {
|
||||
pub fn update(&mut self, message: SelectorMessage) {
|
||||
pub fn update(&mut self, message: SelectorMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
SelectorMessage::Change => match self.set.chars_type {
|
||||
KanaType::Katakana => self.set = KanaSet::hiragana(),
|
||||
KanaType::Hiragana => self.set = KanaSet::katakana(),
|
||||
},
|
||||
SelectorMessage::Goto => {}
|
||||
SelectorMessage::Check(i, b) => self.set.include_map[i] = b,
|
||||
ChangeMode(b) => self.is_writing = b,
|
||||
_ => {}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, SelectorMessage> {
|
||||
container(
|
||||
iced::widget::column![
|
||||
button("Переключить").on_press(SelectorMessage::Change),
|
||||
row![button("Переключить азбуки").on_press(SelectorMessage::Change),
|
||||
button("Словарь").on_press(SelectorMessage::ToDictionary),].spacing(10),
|
||||
self.rows_selector(),
|
||||
toggler(self.is_writing)
|
||||
.label("Режим письма")
|
||||
@@ -85,12 +92,9 @@ impl SelectorState {
|
||||
|
||||
for v in &self.set.dictionary[i] {
|
||||
chars_column = chars_column.push(
|
||||
container(
|
||||
text!("{}", v.0.clone().to_uppercase())
|
||||
.size(36),
|
||||
)
|
||||
.padding(20)
|
||||
.style(container::rounded_box),
|
||||
container(text!("{}", v.0.clone().to_uppercase()).size(36))
|
||||
.padding(20)
|
||||
.style(container::rounded_box),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -1,8 +1,8 @@
|
||||
use crate::lang::KanaSet;
|
||||
use crate::Page::PreviousPage;
|
||||
use crate::{NavigatedPage, Page};
|
||||
use crate::{NavigatedPage, Page, RootMessage};
|
||||
use iced::widget::*;
|
||||
use iced::{alignment, Element, Fill};
|
||||
use iced::{alignment, Element, Fill, Task};
|
||||
use rand::seq::SliceRandom;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -43,12 +43,13 @@ impl WritingState {
|
||||
}
|
||||
|
||||
impl WritingState {
|
||||
pub fn update(&mut self, message: WritingMessage) {
|
||||
pub fn update(&mut self, message: WritingMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
WritingMessage::Back => todo!(),
|
||||
WritingMessage::Next => self.next(),
|
||||
WritingMessage::SwitchShowMode(b) => self.show_all = b,
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn next(&mut self) {
|
||||
|
||||
Reference in New Issue
Block a user