diff --git a/Cargo.lock b/Cargo.lock
index 1a3f6b3..1b7abbe 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -18,6 +18,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "366ffbaa4442f4684d91e2cd7c5ea7c4ed8add41959a31447066e279e432b618"
+[[package]]
+name = "adler2"
+version = "2.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
+
[[package]]
name = "ahash"
version = "0.8.12"
@@ -410,6 +416,12 @@ dependencies = [
"syn",
]
+[[package]]
+name = "byteorder-lite"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
+
[[package]]
name = "bytes"
version = "1.11.1"
@@ -629,6 +641,12 @@ dependencies = [
"unicode-width",
]
+[[package]]
+name = "color_quant"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
+
[[package]]
name = "combine"
version = "4.6.7"
@@ -821,6 +839,15 @@ dependencies = [
"libc",
]
+[[package]]
+name = "crc32fast"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511"
+dependencies = [
+ "cfg-if",
+]
+
[[package]]
name = "criterion"
version = "0.8.2"
@@ -927,6 +954,12 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f"
+[[package]]
+name = "data-url"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "be1e0bca6c3637f992fc1cc7cbc52a78c1ef6db076dbf1059c4323d6a2048376"
+
[[package]]
name = "digest"
version = "0.11.2"
@@ -1144,12 +1177,37 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
+[[package]]
+name = "fdeflate"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c"
+dependencies = [
+ "simd-adler32",
+]
+
[[package]]
name = "find-msvc-tools"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
+[[package]]
+name = "flate2"
+version = "1.1.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c"
+dependencies = [
+ "crc32fast",
+ "miniz_oxide",
+]
+
+[[package]]
+name = "float-cmp"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
+
[[package]]
name = "fnv"
version = "1.0.7"
@@ -1401,6 +1459,16 @@ dependencies = [
"wasip3",
]
+[[package]]
+name = "gif"
+version = "0.13.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4ae047235e33e2829703574b54fdec96bfbad892062d97fed2f76022287de61b"
+dependencies = [
+ "color_quant",
+ "weezl",
+]
+
[[package]]
name = "gl_generator"
version = "0.14.0"
@@ -1878,8 +1946,9 @@ dependencies = [
"cosmic-text",
"iced_debug",
"iced_graphics",
- "kurbo",
+ "kurbo 0.10.4",
"log",
+ "resvg",
"rustc-hash 2.1.1",
"softbuffer",
"tiny-skia",
@@ -1900,6 +1969,7 @@ dependencies = [
"iced_debug",
"iced_graphics",
"log",
+ "resvg",
"rustc-hash 2.1.1",
"thiserror 2.0.18",
"wgpu",
@@ -2047,6 +2117,22 @@ dependencies = [
"icu_properties",
]
+[[package]]
+name = "image-webp"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3"
+dependencies = [
+ "byteorder-lite",
+ "quick-error",
+]
+
+[[package]]
+name = "imagesize"
+version = "0.13.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "edcd27d72f2f071c64249075f42e205ff93c9a4c5f6c6da53e79ed9f9832c285"
+
[[package]]
name = "indexmap"
version = "2.13.0"
@@ -2181,6 +2267,17 @@ dependencies = [
"smallvec",
]
+[[package]]
+name = "kurbo"
+version = "0.11.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c62026ae44756f8a599ba21140f350303d4f08dcdcc71b5ad9c9bb8128c13c62"
+dependencies = [
+ "arrayvec",
+ "euclid",
+ "smallvec",
+]
+
[[package]]
name = "lazy_static"
version = "1.5.0"
@@ -2370,6 +2467,16 @@ dependencies = [
"unicase",
]
+[[package]]
+name = "miniz_oxide"
+version = "0.8.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
+dependencies = [
+ "adler2",
+ "simd-adler32",
+]
+
[[package]]
name = "mio"
version = "1.1.1"
@@ -3125,6 +3232,12 @@ version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
+[[package]]
+name = "pico-args"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315"
+
[[package]]
name = "pin-project"
version = "1.1.10"
@@ -3202,6 +3315,19 @@ dependencies = [
"plotters-backend",
]
+[[package]]
+name = "png"
+version = "0.17.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526"
+dependencies = [
+ "bitflags 1.3.2",
+ "crc32fast",
+ "fdeflate",
+ "flate2",
+ "miniz_oxide",
+]
+
[[package]]
name = "polling"
version = "3.11.0"
@@ -3280,6 +3406,12 @@ version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eb8486b569e12e2c32ad3e204dbaba5e4b5b216e9367044f25f1dba42341773"
+[[package]]
+name = "quick-error"
+version = "2.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
+
[[package]]
name = "quick-xml"
version = "0.38.4"
@@ -3497,6 +3629,32 @@ dependencies = [
"web-sys",
]
+[[package]]
+name = "resvg"
+version = "0.45.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a8928798c0a55e03c9ca6c4c6846f76377427d2c1e1f7e6de3c06ae57942df43"
+dependencies = [
+ "gif",
+ "image-webp",
+ "log",
+ "pico-args",
+ "rgb",
+ "svgtypes",
+ "tiny-skia",
+ "usvg",
+ "zune-jpeg",
+]
+
+[[package]]
+name = "rgb"
+version = "0.8.53"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "47b34b781b31e5d73e9fbc8689c70551fd1ade9a19e3e28cfec8580a79290cc4"
+dependencies = [
+ "bytemuck",
+]
+
[[package]]
name = "rhai"
version = "1.24.0"
@@ -3670,6 +3828,24 @@ version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
+[[package]]
+name = "rustybuzz"
+version = "0.20.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd3c7c96f8a08ee34eff8857b11b49b07d71d1c3f4e88f8a88d4c9e9f90b1702"
+dependencies = [
+ "bitflags 2.10.0",
+ "bytemuck",
+ "core_maths",
+ "log",
+ "smallvec",
+ "ttf-parser",
+ "unicode-bidi-mirroring",
+ "unicode-ccc",
+ "unicode-properties",
+ "unicode-script",
+]
+
[[package]]
name = "ryu"
version = "1.0.23"
@@ -3847,6 +4023,27 @@ dependencies = [
"libc",
]
+[[package]]
+name = "simd-adler32"
+version = "0.3.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
+
+[[package]]
+name = "simplecss"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a9c6883ca9c3c7c90e888de77b7a5c849c779d25d74a1269b0218b14e8b136c"
+dependencies = [
+ "log",
+]
+
+[[package]]
+name = "siphasher"
+version = "1.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
+
[[package]]
name = "skrifa"
version = "0.37.0"
@@ -4040,6 +4237,9 @@ name = "strict-num"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731"
+dependencies = [
+ "float-cmp",
+]
[[package]]
name = "subtle"
@@ -4053,6 +4253,16 @@ version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0193cc4331cfd2f3d2011ef287590868599a2f33c3e69bc22c1a3d3acf9e02fb"
+[[package]]
+name = "svgtypes"
+version = "0.15.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "68c7541fff44b35860c1a7a47a7cadf3e4a304c457b58f9870d9706ece028afc"
+dependencies = [
+ "kurbo 0.11.3",
+ "siphasher",
+]
+
[[package]]
name = "swash"
version = "0.2.6"
@@ -4360,6 +4570,7 @@ dependencies = [
"bytemuck",
"cfg-if",
"log",
+ "png",
"tiny-skia-path",
]
@@ -4632,6 +4843,18 @@ version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5"
+[[package]]
+name = "unicode-bidi-mirroring"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5dfa6e8c60bb66d49db113e0125ee8711b7647b5579dc7f5f19c42357ed039fe"
+
+[[package]]
+name = "unicode-ccc"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ce61d488bcdc9bc8b5d1772c404828b17fc481c0a582b5581e95fb233aef503e"
+
[[package]]
name = "unicode-ident"
version = "1.0.23"
@@ -4644,6 +4867,12 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
+[[package]]
+name = "unicode-properties"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d"
+
[[package]]
name = "unicode-script"
version = "0.5.8"
@@ -4656,6 +4885,12 @@ version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
+[[package]]
+name = "unicode-vo"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b1d386ff53b415b7fe27b50bb44679e2cc4660272694b7b6f3326d8480823a94"
+
[[package]]
name = "unicode-width"
version = "0.1.14"
@@ -4686,6 +4921,33 @@ dependencies = [
"serde",
]
+[[package]]
+name = "usvg"
+version = "0.45.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "80be9b06fbae3b8b303400ab20778c80bbaf338f563afe567cf3c9eea17b47ef"
+dependencies = [
+ "base64",
+ "data-url",
+ "flate2",
+ "fontdb",
+ "imagesize",
+ "kurbo 0.11.3",
+ "log",
+ "pico-args",
+ "roxmltree",
+ "rustybuzz",
+ "simplecss",
+ "siphasher",
+ "strict-num",
+ "svgtypes",
+ "tiny-skia-path",
+ "unicode-bidi",
+ "unicode-script",
+ "unicode-vo",
+ "xmlwriter",
+]
+
[[package]]
name = "utf8_iter"
version = "1.0.4"
@@ -5033,6 +5295,12 @@ dependencies = [
"wasm-bindgen",
]
+[[package]]
+name = "weezl"
+version = "0.1.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88"
+
[[package]]
name = "wgpu"
version = "27.0.1"
@@ -5789,6 +6057,12 @@ version = "0.8.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ae8337f8a065cfc972643663ea4279e04e7256de865aa66fe25cec5fb912d3f"
+[[package]]
+name = "xmlwriter"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9"
+
[[package]]
name = "yazi"
version = "0.2.1"
@@ -5999,6 +6273,21 @@ dependencies = [
"pkg-config",
]
+[[package]]
+name = "zune-core"
+version = "0.4.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3f423a2c17029964870cfaabb1f13dfab7d092a62a29a89264f4d36990ca414a"
+
+[[package]]
+name = "zune-jpeg"
+version = "0.4.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "29ce2c8a9384ad323cf564b67da86e21d3cfdff87908bc1223ed5c99bc792713"
+dependencies = [
+ "zune-core",
+]
+
[[package]]
name = "zvariant"
version = "5.9.2"
diff --git a/Cargo.toml b/Cargo.toml
index b479d96..0a0c3d8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,7 +4,7 @@ version = "0.1.1"
edition = "2024"
[dependencies]
-iced = { version = "0.14.0", features = ["tokio"]}
+iced = { version = "0.14.0", features = ["tokio", "svg"]}
iced_core = "0.14.0"
rand = "0.10.1"
dirs = "6.0.0"
diff --git a/settings_icon.svg b/settings_icon.svg
new file mode 100644
index 0000000..1b5aa82
--- /dev/null
+++ b/settings_icon.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/data_provider/history.rs b/src/data_provider/history.rs
index 539ab23..8cf403a 100644
--- a/src/data_provider/history.rs
+++ b/src/data_provider/history.rs
@@ -1,3 +1,4 @@
+use std::fs;
use crate::dictionary::app_data_dir;
use crate::lang::WordOpenMode;
use chrono::{DateTime, Utc};
@@ -7,7 +8,7 @@ use std::io::{BufRead, BufReader};
use std::path::PathBuf;
pub fn get_history_of_set(id: u32) -> Vec {
- let app_dir = app_data_dir();
+ let app_dir = history_dir();
let head = app_dir.clone().join(format!("set_{}_history.csv", id));
let mut lines = Vec::new();
@@ -48,7 +49,7 @@ fn parse_history_items(strings: Vec) -> Vec {
}
pub fn push_note(set_id: u32, item: HistoryItem) {
- let app_dir = app_data_dir();
+ let app_dir = history_dir();
let path = app_dir.clone().join(format!("set_{}_history.csv", set_id));
let mut file = OpenOptions::new()
@@ -72,6 +73,14 @@ pub fn push_note(set_id: u32, item: HistoryItem) {
writeln!(&mut file, "{}", line_str.to_string()).unwrap();
}
+pub fn history_dir() -> PathBuf {
+ let directory = app_data_dir().join("history");
+ if !directory.exists() {
+ fs::create_dir(directory.clone()).unwrap();
+ }
+ directory
+}
+
#[derive(Clone)]
pub struct HistoryItem {
pub timestamp: DateTime,
diff --git a/src/main.rs b/src/main.rs
index 6f47f4e..b8261d1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,7 +14,10 @@ pub mod styling;
mod sync;
mod word;
mod writing;
+mod repetition_settings;
+use std::collections::HashMap;
+use chrono::{ NaiveDate};
use crate::data_provider::card_sets::load_sets;
use crate::data_provider::settings::get_setting;
use crate::data_provider::words::{load_word_groups, load_words};
@@ -60,6 +63,7 @@ pub struct AppState {
pub word_groups: Vec,
pub connection: Connection,
pub sync_data: AppSettings,
+ pub activity: HashMap>
}
impl AppState {
@@ -75,6 +79,7 @@ impl AppState {
word_groups: vec![],
connection,
sync_data: AppSettings { key: None },
+ activity: Default::default(),
}
}
}
diff --git a/src/navigation.rs b/src/navigation.rs
index 900113b..e4994a9 100644
--- a/src/navigation.rs
+++ b/src/navigation.rs
@@ -1,23 +1,28 @@
+use crate::data_provider::history::{get_history_of_set, history_dir};
use crate::data_provider::sqlite::create_db;
use crate::dictionary::{DictionaryMessage, DictionaryState};
use crate::dictionary_test::{DictionaryQuizMessage, DictionaryQuizState};
use crate::history::{HistoryMessage, HistoryState};
use crate::message_navigation;
use crate::navigation::Page::*;
-use crate::navigation::RootMessage::Keyboard;
+use crate::navigation::RootMessage::{DataLoaded, Keyboard };
use crate::quiz::{QuizMessage, QuizState};
use crate::randomizer::{RandomizerMessage, RandomizerState};
use crate::repetition::{RepetitionMessage, RepetitionState};
use crate::repetitions::{RepetitionsMessage, RepetitionsState};
use crate::selector::{SelectorMessage, SelectorState};
+use crate::repetition_settings::{RepetitionSettingsMessage, RepetitionSettingsState};
use crate::state_update;
use crate::sync::{SyncMessage, SyncState};
use crate::view_navigation;
use crate::word::{WordMessage, WordState};
use crate::writing::{WritingMessage, WritingState};
-use crate::{fill_state, AppState};
+use crate::{AppState, fill_state};
+use chrono::NaiveDate;
use iced::keyboard::Event;
use iced::{Element, Task};
+use rusqlite::fallible_iterator::FallibleIterator;
+use std::collections::HashMap;
use std::sync::{Arc, Mutex};
impl Default for ScreenState {
@@ -26,7 +31,8 @@ impl Default for ScreenState {
fill_state(&mut state);
let state = Arc::new(Mutex::new(state));
ScreenState {
- stack: vec![Page::Selector(SelectorState::new(state.clone()))],
+ stack: vec![Selector(SelectorState::new(state.clone()))],
+ app_state: state.clone(),
}
}
}
@@ -44,7 +50,9 @@ pub enum RootMessage {
Word(WordMessage),
Sync(SyncMessage),
History(HistoryMessage),
+ RepetitionSettings(RepetitionSettingsMessage),
Keyboard(Event),
+ DataLoaded(HashMap>),
}
pub enum Page {
@@ -59,23 +67,59 @@ pub enum Page {
Word(WordState),
Sync(SyncState),
History(HistoryState),
+ RepetitionSettings(RepetitionSettingsState),
+
PreviousPage,
}
pub struct ScreenState {
stack: Vec,
+ app_state: Arc>,
}
impl ScreenState {
pub fn boot() -> (ScreenState, Task) {
create_db();
- (ScreenState::default(), Task::none())
+ (
+ ScreenState::default(),
+ Task::perform(Self::load_additional_data(), |data| data),
+ )
}
+
+ async fn load_additional_data() -> RootMessage {
+ let directory = history_dir();
+ let mut map = HashMap::new();
+ for file in directory.read_dir().unwrap() {
+ if let Ok(file) = file {
+ let mut vec = vec![];
+ let history_file_name = file.file_name().into_string().unwrap();
+ let id = history_file_name[4..history_file_name.len() - 12]
+ .parse::()
+ .unwrap();
+
+ let history = get_history_of_set(id);
+ let by_date = history.chunk_by(|x, x1| {
+ x.timestamp.naive_local().date() == x1.timestamp.naive_local().date()
+ });
+ for group in by_date {
+ vec.push((group[0].timestamp.naive_local().date(), group.len() as u32));
+ }
+ map.insert(id, vec);
+ }
+ }
+ DataLoaded(map)
+ }
+
pub fn update(&mut self, message: RootMessage) -> Task {
if let Keyboard(e) = message {
return self.handle_keyboard(e);
}
+ if let DataLoaded(data) = message {
+ self.app_state.lock().unwrap().activity = data;
+ return Task::none();
+ }
+
state_update!(
message,
self.stack,
@@ -89,8 +133,10 @@ impl ScreenState {
Repetition,
Word,
Sync,
- History
+ History,
+ RepetitionSettings
);
+
Task::none()
}
pub fn view(&self) -> Element<'_, RootMessage> {
@@ -106,14 +152,15 @@ impl ScreenState {
Repetition,
Word,
Sync,
- History
+ History,
+ RepetitionSettings
)
}
fn handle_keyboard(&mut self, message: Event) -> Task {
let page = self.stack.last_mut().unwrap();
match page {
- Page::Repetition(page) => page.press(&message),
+ Repetition(page) => page.press(&message),
_ => Task::none(),
}
}
diff --git a/src/repetition_settings.rs b/src/repetition_settings.rs
new file mode 100644
index 0000000..0dd9106
--- /dev/null
+++ b/src/repetition_settings.rs
@@ -0,0 +1,38 @@
+use crate::navigation::Page::PreviousPage;
+use crate::navigation::{NavigatedPage, Page, RootMessage};
+use crate::repetition_settings::RepetitionSettingsMessage::*;
+use crate::styling::back_overlay;
+use iced::widget::row;
+use iced::{Element, Task};
+
+pub struct RepetitionSettingsState {}
+impl NavigatedPage for RepetitionSettingsState {
+ fn navigate(&self, message: &RepetitionSettingsMessage) -> Option {
+ if let Back = message {
+ Some(PreviousPage)
+ } else {
+ None
+ }
+ }
+}
+
+impl RepetitionSettingsState {
+ pub fn update(&mut self, message: RepetitionSettingsMessage) -> Task {
+ match message {
+ Back => {}
+ }
+ Task::none()
+ }
+
+ pub fn view(&self) -> Element<'_, RepetitionSettingsMessage> {
+ back_overlay(
+ row![].into(),
+ Back,
+ )
+ }
+}
+
+#[derive(Clone)]
+pub enum RepetitionSettingsMessage {
+ Back
+}
\ No newline at end of file
diff --git a/src/repetitions.rs b/src/repetitions.rs
index 8ff48aa..b87eb6e 100644
--- a/src/repetitions.rs
+++ b/src/repetitions.rs
@@ -2,21 +2,24 @@ use crate::data_provider::card_sets::{delete_set, update_card_set};
use crate::data_provider::card_stats::load_stats_of_set;
use crate::history::HistoryState;
use crate::lang::{SetOrderMode, WordData};
-use crate::navigation::Page::{History, PreviousPage, Repetition};
+use crate::navigation::Page::{History, PreviousPage, Repetition, RepetitionSettings};
use crate::navigation::{NavigatedPage, Page};
use crate::repetition::RepetitionState;
use crate::styling::*;
use crate::{AppState, RootMessage};
-use iced::widget::button::{danger, Status};
pub use iced::widget::button::{Catalog, Style};
+use iced::widget::button::{Status, danger};
use iced::widget::container::bordered_box;
use iced::widget::{
- button, column, container, radio, row, scrollable, space, text, text_input, Column,
+ Column, button, column, container, radio, row, scrollable, space, svg, text, text_input,
};
use iced::{Background, Border, Center, Color, Element, Fill, Length, Shadow, Task, Theme};
use iced_core::Padding;
+use iced_core::svg::Handle;
use rhai::{Engine, Scope};
use std::sync::{Arc, Mutex};
+use crate::repetition_settings::RepetitionSettingsState;
+use crate::repetitions::RepetitionsMessage::*;
#[derive(Clone)]
pub struct RepetitionsState {
@@ -28,22 +31,26 @@ pub struct RepetitionsState {
impl NavigatedPage for RepetitionsState {
fn navigate(&self, message: &RepetitionsMessage) -> Option {
- if let RepetitionsMessage::Back = message {
+ if let Back = message {
Some(PreviousPage)
- } else if let RepetitionsMessage::GoToHistory = message {
+ } else if let GoToHistory = message {
let card_set;
{
card_set = self.state.lock().unwrap().card_sets[self.selected_set.unwrap()].id;
}
Some(History(HistoryState::new(card_set, self.state.clone())))
- } else if let RepetitionsMessage::GoToRepetition = message {
+ } else if let GoToRepetition = message {
let clone = self.state.clone();
let card_set;
{
card_set = self.state.lock().unwrap().card_sets[self.selected_set.unwrap()].clone();
}
Some(Repetition(RepetitionState::new(card_set, clone)))
- } else {
+ }
+ else if let GoToSettings = message {
+ Some(RepetitionSettings(RepetitionSettingsState {}))
+ }
+ else {
None
}
}
@@ -64,33 +71,34 @@ impl RepetitionsState {
pub fn update(&mut self, message: RepetitionsMessage) -> Task {
let mut state = self.state.lock().unwrap();
match message {
- RepetitionsMessage::Next => {}
- RepetitionsMessage::Back => {}
- RepetitionsMessage::GoToRepetition => {}
- RepetitionsMessage::GoToHistory => {}
- RepetitionsMessage::CreateSet => {
+ Next => {}
+ Back => {}
+ GoToRepetition => {}
+ GoToHistory => {}
+ GoToSettings => {}
+ CreateSet => {
let index = state.card_sets.len() + 1;
state
.card_sets
.push(CardSetSettings::with_name(format!("Card set #{}", index)));
self.correct_filters.push(true);
}
- RepetitionsMessage::DeleteSet => {
+ DeleteSet => {
let set = state.card_sets.remove(self.selected_set.unwrap());
self.correct_filters.remove(self.selected_set.unwrap());
self.selected_set = None;
delete_set(&set, &state.connection);
}
- RepetitionsMessage::SelectSet(index) => {
+ SelectSet(index) => {
self.selected_set = Some(index);
let mut set = state.card_sets.get(index).unwrap().clone();
set.update_worst_words(&state);
state.card_sets[index] = set;
}
- RepetitionsMessage::SetName(new) => {
+ SetName(new) => {
state.card_sets[self.selected_set.unwrap()].name = new;
}
- RepetitionsMessage::Save => {
+ Save => {
for i in 0..state.card_sets.len() {
self.correct_filters[i] = state.card_sets[i].check_filter();
}
@@ -101,27 +109,27 @@ impl RepetitionsState {
state.card_sets[self.selected_set.unwrap()] = word.clone();
}
- RepetitionsMessage::SetForward(new) => {
+ SetForward(new) => {
state.card_sets[self.selected_set.unwrap()].forward = new;
}
- RepetitionsMessage::SetBackward(new) => {
+ SetBackward(new) => {
state.card_sets[self.selected_set.unwrap()].backward = new;
}
- RepetitionsMessage::SetFilter(new) => {
+ SetFilter(new) => {
state.card_sets[self.selected_set.unwrap()].filter = new;
}
- RepetitionsMessage::TryFilter => {
+ TryFilter => {
let set = state.card_sets.get(self.selected_set.unwrap()).unwrap();
let count = set.get_word_list(&state).len();
state.card_sets[self.selected_set.unwrap()].count = Some(count);
}
- RepetitionsMessage::SetOpenMode(mode) => {
+ SetOpenMode(mode) => {
state
.card_sets
.get_mut(self.selected_set.unwrap())
.unwrap()
.open_mode = mode;
- }
+ },
}
Task::none()
}
@@ -134,7 +142,7 @@ impl RepetitionsState {
button("Добавить")
.style(jl_button)
.width(Fill)
- .on_press(RepetitionsMessage::CreateSet),
+ .on_press(CreateSet),
]
.spacing(DEFAULT_SPACING)
.width(Length::FillPortion(1)),
@@ -145,7 +153,7 @@ impl RepetitionsState {
.width(Fill)
.height(Fill)
.into(),
- RepetitionsMessage::Back,
+ Back,
)
}
@@ -155,7 +163,7 @@ impl RepetitionsState {
{
return button(text!("Начать повторение").width(200).center())
.style(cta_button)
- .on_press(RepetitionsMessage::GoToRepetition)
+ .on_press(GoToRepetition)
.into();
}
space().into()
@@ -172,25 +180,29 @@ impl RepetitionsState {
column![
column![
text!("Название набора"),
- text_input("", &set.name).on_input(RepetitionsMessage::SetName)
+ row![
+ text_input("", &set.name).on_input(SetName),
+ button(svg(Handle::from_memory(SETTINGS_ICON))).width(43).on_press(GoToSettings),
+ ]
+ .spacing(HALF_SPACING)
]
.spacing(QUARTER_SPACING),
column![
text!("Передняя сторона"),
- text_input("", &set.forward).on_input(RepetitionsMessage::SetForward),
+ text_input("", &set.forward).on_input(SetForward),
]
.spacing(QUARTER_SPACING),
column![
text!("Задняя сторона"),
- text_input("", &set.backward).on_input(RepetitionsMessage::SetBackward),
+ text_input("", &set.backward).on_input(SetBackward),
]
.spacing(QUARTER_SPACING),
column![
text!("Фильтр"),
- text_input("", &set.filter).on_input(RepetitionsMessage::SetFilter),
+ text_input("", &set.filter).on_input(SetFilter),
button("Проверить фильтр")
.style(jl_button)
- .on_press(RepetitionsMessage::TryFilter),
+ .on_press(TryFilter),
self.count_view(&set),
]
.spacing(QUARTER_SPACING),
@@ -198,12 +210,12 @@ impl RepetitionsState {
"Обычный режим",
SetOrderMode::Default,
Some(set.open_mode),
- RepetitionsMessage::SetOpenMode
+ SetOpenMode
),
self.words_words_view(&set),
button("История")
.style(jl_button)
- .on_press(RepetitionsMessage::GoToHistory),
+ .on_press(GoToHistory),
]
.spacing(DEFAULT_SPACING)
.padding(Padding {
@@ -217,10 +229,10 @@ impl RepetitionsState {
row![
button("Сохранить")
.style(jl_button)
- .on_press(RepetitionsMessage::Save),
+ .on_press(Save),
button("Удалить")
.style(danger)
- .on_press(RepetitionsMessage::DeleteSet),
+ .on_press(DeleteSet),
space().width(Fill),
self.launch_button()
]
@@ -241,13 +253,13 @@ impl RepetitionsState {
"Начать с плохих слов",
SetOrderMode::TrainWorstFirst,
Some(set.open_mode),
- RepetitionsMessage::SetOpenMode
+ SetOpenMode
),
radio(
"Полностью случайно",
SetOrderMode::FullRandom,
Some(set.open_mode),
- RepetitionsMessage::SetOpenMode
+ SetOpenMode
)
]
.spacing(DEFAULT_SPACING)
@@ -277,7 +289,7 @@ impl RepetitionsState {
for set in sets {
column = column.push(
button(text!("{}", set.name.clone()))
- .on_press_with(move || RepetitionsMessage::SelectSet(i.clone()))
+ .on_press_with(move || SelectSet(i.clone()))
.style(move |_x: &Theme, status: Status| Style {
background: if status == Status::Hovered {
Some(Background::Color(Color::WHITE.scale_alpha(0.2)))
@@ -321,6 +333,7 @@ pub enum RepetitionsMessage {
TryFilter,
SetOpenMode(SetOrderMode),
GoToHistory,
+ GoToSettings,
}
#[derive(Clone)]
diff --git a/src/selector.rs b/src/selector.rs
index bea4403..5aaefc1 100644
--- a/src/selector.rs
+++ b/src/selector.rs
@@ -11,7 +11,7 @@ use crate::writing::WritingState;
use crate::{AppState, QuizState, RootMessage};
use iced::widget::button::{Status, Style};
use iced::widget::*;
-use iced::{alignment, Element, Task};
+use iced::{Element, Task, alignment};
use iced_core::Alignment::Center;
use iced_core::Background;
use iced_core::Color;
@@ -105,12 +105,12 @@ impl SelectorState {
button("Словарь")
.on_press(SelectorMessage::ToDictionary)
.style(Self::nav_style),
- button("Рандомайзер")
- .on_press(SelectorMessage::ToRandomize)
- .style(Self::nav_style),
button("Повторение")
.on_press(SelectorMessage::ToRepetitions)
.style(Self::nav_style),
+ button("Рандомайзер")
+ .on_press(SelectorMessage::ToRandomize)
+ .style(Self::nav_style),
button("Синхронизация")
.on_press(SelectorMessage::ToSync)
.style(Self::nav_style)
diff --git a/src/styling.rs b/src/styling.rs
index b7f227b..589f46d 100644
--- a/src/styling.rs
+++ b/src/styling.rs
@@ -13,6 +13,8 @@ pub const DEFAULT_SPACING: f32 = 16.0;
pub const ACCENT_FONT_SIZE: f32 = 22.0;
pub const BUTTON_RADIUS: f32 = 8.0;
+pub const SETTINGS_ICON: &[u8] = include_bytes!("../settings_icon.svg");
+
pub fn jl_button(theme: &Theme, status: Status) -> Style {
let mut style = primary(theme, status);
style.border = Border {