diff --git a/Cargo.lock b/Cargo.lock index da6dee2..f2db642 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,6 +47,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "aliasable" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" + [[package]] name = "alloca" version = "0.4.0" @@ -1681,6 +1687,12 @@ dependencies = [ "hashbrown 0.17.1", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "heck" version = "0.5.0" @@ -2001,6 +2013,7 @@ dependencies = [ "iced_renderer", "log", "num-traits", + "ouroboros", "rustc-hash 2.1.1", "thiserror 2.0.18", "unicode-segmentation", @@ -3208,6 +3221,30 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "ouroboros" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0f050db9c44b97a94723127e6be766ac5c340c48f2c4bb3ffa11713744be59" +dependencies = [ + "aliasable", + "ouroboros_macro", + "static_assertions", +] + +[[package]] +name = "ouroboros_macro" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c7028bdd3d43083f6d8d4d5187680d0d3560d54df4cc9d752005268b41e64d0" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "proc-macro2-diagnostics", + "quote", + "syn 2.0.114", +] + [[package]] name = "owned_ttf_parser" version = "0.25.1" @@ -3436,6 +3473,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "proc-macro2-diagnostics" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", + "version_check", + "yansi", +] + [[package]] name = "profiling" version = "1.0.17" @@ -6077,7 +6127,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" dependencies = [ "anyhow", - "heck", + "heck 0.5.0", "wit-parser", ] @@ -6088,7 +6138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" dependencies = [ "anyhow", - "heck", + "heck 0.5.0", "indexmap", "prettyplease", "syn 2.0.114", @@ -6224,6 +6274,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9" +[[package]] +name = "yansi" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" + [[package]] name = "yazi" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index d7a2c39..7cef5e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.2" edition = "2024" [dependencies] -iced = { version = "0.14.0", features = ["tokio", "svg"]} +iced = { version = "0.14.0", features = ["tokio", "svg", "lazy"]} iced_core = "0.14.0" rand = "0.10.2" dirs = "6.0.0" @@ -28,7 +28,7 @@ criterion = "0.8.2" name = "split_bench" # Имя файла в benches/ без расширения harness = false # Отключаем стандартный тестовый раннер -[profile.release] -codegen-units = 1 -lto = true -opt-level = 3 \ No newline at end of file +#[profile.release] +#codegen-units = 1 +#lto = true +#opt-level = 3 \ No newline at end of file diff --git a/src/dictionary.rs b/src/dictionary.rs index 3345737..6a05230 100644 --- a/src/dictionary.rs +++ b/src/dictionary.rs @@ -338,71 +338,84 @@ impl DictionaryState { continue; } - let mut line = Row::new().width(Length::Fill).align_y(Center); - line = line.push( - checkbox(self.include_map[i]) - .label("") - .spacing(15) - .on_toggle(move |b| Include(i, b)), - ); - - line = line.push( - text_input("Слово", &word.key) - .size(ACCENT_FONT_SIZE) - .width(Length::Fill) - .on_input(move |string| SetKey(i, string)) - .on_submit(SubmitWord(i)) - .style(|x, status| { - let mut default_style = default(x, status); - default_style.border.radius = 0.0.into(); - default_style - }), - ); - line = line.push( - text_input("Перевод", &word.value) - .size(ACCENT_FONT_SIZE) - .width(Length::Fill) - .on_input(move |string| SetValue(i, string)) - .on_submit(SubmitWord(i)) - .style(|x, status| { - let mut default_style = default(x, status); - default_style.border.radius = 0.0.into(); - default_style - }), - ); - - line = line.push( - text_input("Теги", &word.tags) - .size(ACCENT_FONT_SIZE) - .width(Length::Fill) - .on_input(move |string| SetTags(i, string)) - .on_submit(SubmitWord(i)) - .style(|x, status| { - let mut default_style = default(x, status); - default_style.border.radius = 0.0.into(); - default_style - }), - ); - - let line_button = || { - let action = WordAction(i); - - if word.id == 0 { - return button("-").on_press(action).style(|_x, _status| Style { - background: None, - text_color: Color::BLACK, - border: Border::default(), - shadow: Shadow::default(), - snap: false, - }); - } - - button("").on_press(WordAction(i)).width(15) + let word_line_data = WordLineState{ + is_included: self.include_map[i], + key: word.key.clone(), + value: word.value.clone(), + tags: word.tags.clone(), + id: word.id, }; - line = line.push(line_button()).push(space().width(10)); + let lazy_line = lazy(word_line_data, move |data| { + let mut line = Row::new().width(Length::Fill).align_y(Center); + line = line.push( + checkbox(data.is_included) + .label("") + .spacing(15) + .on_toggle(move |b| Include(i, b)), + ); - col = col.push(line); + line = line.push( + text_input("Слово", &data.key) + .size(ACCENT_FONT_SIZE) + .width(Length::Fill) + .on_input(move |string| SetKey(i, string)) + .on_submit(SubmitWord(i)) + .style(|x, status| { + let mut default_style = default(x, status); + default_style.border.radius = 0.0.into(); + default_style + }), + ); + line = line.push( + text_input("Перевод", &data.value) + .size(ACCENT_FONT_SIZE) + .width(Length::Fill) + .on_input(move |string| SetValue(i, string)) + .on_submit(SubmitWord(i)) + .style(|x, status| { + let mut default_style = default(x, status); + default_style.border.radius = 0.0.into(); + default_style + }), + ); + + line = line.push( + text_input("Теги", &data.tags) + .size(ACCENT_FONT_SIZE) + .width(Length::Fill) + .on_input(move |string| SetTags(i, string)) + .on_submit(SubmitWord(i)) + .style(|x, status| { + let mut default_style = default(x, status); + default_style.border.radius = 0.0.into(); + default_style + }), + ); + + let line_button = || { + let action = WordAction(i); + + if data.id == 0 { + return button("-").on_press(action).style(|_x, _status| Style { + background: None, + text_color: Color::BLACK, + border: Border::default(), + shadow: Shadow::default(), + snap: false, + }); + } + + button("").on_press(WordAction(i)).width(15) + }; + line = line.push(line_button()).push(space().width(10)); + line + }); + + + + + col = col.push(lazy_line); } println!("Words rendering time: {:?}", time.elapsed()); @@ -573,3 +586,12 @@ pub fn app_data_dir() -> PathBuf { dir } + +#[derive(Hash, PartialEq, Eq)] +struct WordLineState{ + is_included: bool, + key: String, + value: String, + tags: String, + id: u32 +} \ No newline at end of file