Dictionary partial rewritten and dictionary quiz rewritten

This commit is contained in:
micialware committed 2026-09-03 00:36:15 +03:00
1 parent f2035ca749
commit f19a6f64c3
2 files changed
+63 -48

No files matched your search

+52 -43
View File
@@ -88,6 +88,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
words, words,
self.reverse, self.reverse,
self.no_typing, self.no_typing,
self.state.clone()
))); )));
} }
if let WordAction(handle) = message if let WordAction(handle) = message
@@ -315,39 +316,50 @@ impl DictionaryState {
} }
fn words_list(&self) -> iced::Element<'_, DictionaryMessage> { fn words_list(&self) -> iced::Element<'_, DictionaryMessage> {
let time = Instant::now(); todo!("Make new display system")
let mut col = Column::new().width(Fill); // let time = Instant::now();
// let mut col = Column::new().width(Fill);
let query = &self.displayed_words_query; //
let dictionary = self.state.dictionary.read(); // let query = &self.displayed_words_query;
// let dictionary = self.state.dictionary.read();
//
for access_index in 0..query.len() { //
let mut i = access_index; // for access_index in 0..query.len() {
if self.reverse_list { // let mut i = access_index;
i = query.len() - access_index - 1; // if self.reverse_list {
// i = query.len() - access_index - 1;
// }
// let word_handle = &query[i];
// let word = dictionary.get_ref_static(*word_handle).unwrap();
//
// if !self.search.is_empty()
// && !word.key.contains(&self.search)
// && !word.value.contains(&self.search)
// && !word.tags.contains(&self.search)
// {
// continue;
// }
//
// let word_line_data = WordLineState {
// is_included: self.included.contains(word_handle),
// key: word.key.clone().into(),
// value: word.value.clone().into(),
// tags: word.tags.clone().into(),
// handle: word_handle.clone(),
// };
//
//
// let lazy_line = lazy(word_line_data, |data: &WordLineState| Self::word_line(data));
//
// col = col.push(lazy_line);
// }
//
// info!("Words rendering time: {:?}", time.elapsed());
// scrollable(col).height(Fill).into()
} }
let word_handle = &query[i];
let word = dictionary.get_ref_static(*word_handle).unwrap();
if !self.search.is_empty() pub fn word_line(data: &WordLineState) -> Row<'_, DictionaryMessage>
&& !word.key.contains(&self.search)
&& !word.value.contains(&self.search)
&& !word.tags.contains(&self.search)
{ {
continue;
}
let word_line_data = WordLineState {
is_included: self.included.contains(word_handle),
key: word.key.clone().into(),
value: word.value.clone().into(),
tags: word.tags.clone().into(),
handle: word_handle.clone(),
};
let lazy_line = lazy(word_line_data, move |data| {
let mut line = Row::new().width(Fill).align_y(Center); let mut line = Row::new().width(Fill).align_y(Center);
line = line.push( line = line.push(
checkbox(data.is_included) checkbox(data.is_included)
@@ -392,28 +404,25 @@ impl DictionaryState {
); );
let line_button = || { let line_button = || {
let action = WordAction(data.handle);
if !data.handle.real() { if !data.handle.real() {
return button("-").on_press(action).style(|_x, _status| Style { return button("-")
.on_press(WordAction(data.handle))
.style(|_x: &iced::Theme, _status: iced::widget::button::Status| Style {
background: None, background: None,
text_color: Color::BLACK, text_color: Color::BLACK,
border: Border::default(), border: Border::default(),
shadow: Shadow::default(), shadow: Shadow::default(),
snap: false, snap: false,
}); })
.width(15);
} }
button("").on_press(WordAction(data.handle)).width(15) button("")
.on_press(WordAction(data.handle))
.style(button::primary)
.width(15)
}; };
line.push(line_button()).push(space().width(10)) line.push(line_button()).push(space().width(10))
});
col = col.push(lazy_line);
}
info!("Words rendering time: {:?}", time.elapsed());
scrollable(col).height(Fill).into()
} }
fn filters(&self) -> iced::Element<'_, DictionaryMessage> { fn filters(&self) -> iced::Element<'_, DictionaryMessage> {
@@ -597,7 +606,7 @@ pub fn split_with_coma(ts: &str) -> Vec<String> {
.collect::<Vec<String>>() .collect::<Vec<String>>()
} }
#[derive(Hash, PartialEq, Eq)] #[derive(Clone, Hash, PartialEq, Eq)]
struct WordLineState { struct WordLineState {
is_included: bool, is_included: bool,
key: Box<str>, key: Box<str>,
+11 -5
View File
@@ -12,8 +12,11 @@ use iced::widget::container::Style;
use iced::widget::{Row, button, container, row, space, text, text_input}; use iced::widget::{Row, button, container, row, space, text, text_input};
use iced::{Border, Element, Fill, Task, Theme, alignment}; use iced::{Border, Element, Fill, Task, Theme, alignment};
use rand::prelude::SliceRandom; use rand::prelude::SliceRandom;
use crate::app::AppState;
use crate::data::repositories::Repository;
pub struct DictionaryQuizState { pub struct DictionaryQuizState {
state: AppState,
words: Vec<EntityHandle<WordData>>, words: Vec<EntityHandle<WordData>>,
current_set: Vec<EntityHandle<WordData>>, current_set: Vec<EntityHandle<WordData>>,
answer: String, answer: String,
@@ -103,8 +106,9 @@ impl NavigatedPage<DictionaryQuizMessage> for DictionaryQuizState {
} }
impl DictionaryQuizState { impl DictionaryQuizState {
pub fn new(words: Vec<EntityHandle<WordData>>, reverse: bool, no_typing: bool) -> DictionaryQuizState { pub fn new(words: Vec<EntityHandle<WordData>>, reverse: bool, no_typing: bool, state: AppState) -> DictionaryQuizState {
let state = DictionaryQuizState { let state = DictionaryQuizState {
state,
words, words,
current_set: Vec::new(), current_set: Vec::new(),
answer: "".to_string(), answer: "".to_string(),
@@ -181,12 +185,14 @@ impl DictionaryQuizState {
} }
}; };
let repo = self.state.dictionary.read();
let next = repo.get_static(next).unwrap();
if self.reverse { if self.reverse {
self.view = next.value.clone(); self.view = next.value;
self.correct = next.key.clone(); self.correct = next.key;
} else { } else {
self.view = next.key.clone(); self.view = next.key;
self.correct = next.value.clone(); self.correct = next.value;
} }
} }