From 33ee6d43dfb4234f66edcd95c7e1e49795925aef Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Tue, 24 Feb 2026 14:44:20 +0300 Subject: [PATCH] Add laps count in dictionary test --- Cargo.lock | 60 ------------------------------------------ Cargo.toml | 2 +- src/dictionary.rs | 6 ++--- src/dictionary_test.rs | 47 ++++++++++++++++++++++++++------- 4 files changed, 42 insertions(+), 73 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4002747..a75c3da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -817,12 +817,6 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" -[[package]] -name = "float_next_after" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf7cc16383c4b8d58b9905a8509f02926ce3058053c056376248d958c9df1e8" - [[package]] name = "foldhash" version = "0.1.5" @@ -1282,7 +1276,6 @@ dependencies = [ "iced_core", "iced_futures", "log", - "lyon_path", "raw-window-handle", "rustc-hash 2.1.1", "thiserror 2.0.18", @@ -1357,7 +1350,6 @@ dependencies = [ "iced_debug", "iced_graphics", "log", - "lyon", "rustc-hash 2.1.1", "thiserror 2.0.18", "wgpu", @@ -1593,58 +1585,6 @@ version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1dc47f592c06f33f8e3aea9591776ec7c9f9e4124778ff8a3c3b87159f7e593" -[[package]] -name = "lyon" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbcb7d54d54c8937364c9d41902d066656817dce1e03a44e5533afebd1ef4352" -dependencies = [ - "lyon_algorithms", - "lyon_tessellation", -] - -[[package]] -name = "lyon_algorithms" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c0829e28c4f336396f250d850c3987e16ce6db057ffe047ce0dd54aab6b647" -dependencies = [ - "lyon_path", - "num-traits", -] - -[[package]] -name = "lyon_geom" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e260b6de923e6e47adfedf6243013a7a874684165a6a277594ee3906021b2343" -dependencies = [ - "arrayvec", - "euclid", - "num-traits", -] - -[[package]] -name = "lyon_path" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aeca86bcfd632a15984ba029b539ffb811e0a70bf55e814ef8b0f54f506fdeb" -dependencies = [ - "lyon_geom", - "num-traits", -] - -[[package]] -name = "lyon_tessellation" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f586142e1280335b1bc89539f7c97dd80f08fc43e9ab1b74ef0a42b04aa353" -dependencies = [ - "float_next_after", - "lyon_path", - "num-traits", -] - [[package]] name = "malloc_buf" version = "0.0.6" diff --git a/Cargo.toml b/Cargo.toml index ea96505..e4564a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] -iced = { version = "0.14.0", features = ["canvas"] } +iced = { version = "0.14.0"} rand = "0.10.0" dirs = "6.0.0" serde = { version = "1.0.144", features = ["derive"] } diff --git a/src/dictionary.rs b/src/dictionary.rs index 2d59cc0..9e36580 100644 --- a/src/dictionary.rs +++ b/src/dictionary.rs @@ -254,7 +254,7 @@ impl DictionaryState { fn update_tags(&mut self) { let mut tags_list: Vec = vec![]; for element in &self.dict { - tags_list.append(&mut to_tags_list(element.tags.clone())); + tags_list.append(&mut split_with_coma(element.tags.clone())); } let current_tags = self @@ -291,7 +291,7 @@ impl DictionaryState { } for i in 0..self.include_map.len() { - let tags = to_tags_list(self.dict[i].tags.clone()); + let tags = split_with_coma(self.dict[i].tags.clone()); if tags.iter().any(|t| include_tags.contains(t)) { self.include_map[i] = true; } @@ -299,7 +299,7 @@ impl DictionaryState { } } -fn to_tags_list(ts: String) -> Vec { +pub fn split_with_coma(ts: String) -> Vec { ts.split(',') .map(|ts| ts.to_lowercase().trim().to_string()) .filter(|t| !t.is_empty()) diff --git a/src/dictionary_test.rs b/src/dictionary_test.rs index 25471fd..0b45d30 100644 --- a/src/dictionary_test.rs +++ b/src/dictionary_test.rs @@ -1,12 +1,14 @@ -use crate::dictionary::DictionaryElement; +use crate::dictionary::{split_with_coma, 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 iced::border::Radius; +use iced::widget::container::Style; +use iced::widget::{button, container, row, space, text, text_input, Row}; +use iced::Background::Color; +use iced::{alignment, Border, Element, Fill, Task, Theme}; use rand::prelude::SliceRandom; - #[derive(Debug, Clone)] pub struct DictionaryQuizState { words: Vec, @@ -17,6 +19,7 @@ pub struct DictionaryQuizState { score: Score, is_help: bool, reverse: bool, + laps: u32 } #[derive(Debug, Clone)] pub enum DictionaryQuizMessage { @@ -45,7 +48,8 @@ impl DictionaryQuizState { correct: "".to_string(), score: Default::default(), is_help: false, - reverse: reverse, + reverse, + laps: 0 } } @@ -61,9 +65,10 @@ impl DictionaryQuizState { Task::none() } - pub fn view(&self) -> iced::Element<'_, DictionaryQuizMessage> { + pub fn view(&self) -> Element<'_, DictionaryQuizMessage> { container( iced::widget::column![ + self.laps(), row![ text!("{}", self.view).size(54), text!( @@ -79,7 +84,7 @@ impl DictionaryQuizState { .spacing(20), text_input("Перевод", &self.answer) .size(28) - .width(150) + .width(250) .on_input(DictionaryQuizMessage::AnswerChanged) .on_submit(DictionaryQuizMessage::SubmitAnswer), row![ @@ -112,12 +117,13 @@ impl DictionaryQuizState { if !self.is_help { self.score.total += 1; } - if self.answer == self.correct { + if self.answer == self.correct || split_with_coma(self.correct.clone()).contains(&self.answer) { if self.is_help == false { self.score.correct += 1; } self.show_next() } else { + self.score.fail += 1; self.is_help = true; } @@ -125,7 +131,10 @@ impl DictionaryQuizState { fn update_set(&mut self) { self.current_set.append(&mut self.words.clone()); - self.current_set.shuffle(&mut rand::rng()) + self.current_set.shuffle(&mut rand::rng()); + if self.score.total != 0 { + self.laps += 1; + } } fn show_next(&mut self) { @@ -145,4 +154,24 @@ impl DictionaryQuizState { self.correct = next.value.clone(); } } + + fn laps(&self) -> Element<'_, DictionaryQuizMessage> { + let mut col = Row::new(); + for _ in 0..self.laps { + col = col.push(iced::widget::container(space().height(15).width(15)).style(|x: &Theme| { + Style{ + text_color: None, + background: Some(Color(x.palette().primary)), + border: Border{ + color: Default::default(), + width: 0.0, + radius: Radius::new(5), + }, + shadow: Default::default(), + snap: false, + } + })); + } + col.spacing(10).into() + } }