More styling
This commit is contained in:
+72
-53
@@ -1,7 +1,5 @@
|
||||
use crate::data_provider::words::{delete_group, delete_word, update_group, update_word};
|
||||
use crate::dictionary::DictionaryMessage::{
|
||||
ChangeDirection, DeleteGroup, EditGroup, SaveGroup, Test,
|
||||
};
|
||||
use crate::dictionary::DictionaryMessage::*;
|
||||
use crate::dictionary_test::DictionaryQuizState;
|
||||
use crate::lang::{WordData, WordGroup};
|
||||
use crate::navigation::Page::Word;
|
||||
@@ -9,7 +7,6 @@ use crate::navigation::{NavigatedPage, Page};
|
||||
use crate::styling::*;
|
||||
use crate::word::WordState;
|
||||
use crate::{AppState, RootMessage};
|
||||
use DictionaryMessage::Back;
|
||||
use chrono::{DateTime, TimeDelta, Utc};
|
||||
use iced::alignment::Vertical::Center;
|
||||
use iced::widget::button::Style;
|
||||
@@ -24,6 +21,8 @@ use std::ops::Add;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, Instant};
|
||||
use iced::widget::text_input::default;
|
||||
use DictionaryMessage::Back;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DictionaryState {
|
||||
@@ -88,7 +87,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
)));
|
||||
}
|
||||
}
|
||||
if let DictionaryMessage::WordAction(index) = message {
|
||||
if let WordAction(index) = message {
|
||||
let word: WordData;
|
||||
{
|
||||
let state = self.state.lock().unwrap();
|
||||
@@ -126,7 +125,7 @@ impl DictionaryState {
|
||||
|
||||
pub fn update(&mut self, message: DictionaryMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
DictionaryMessage::NewWord => {
|
||||
NewWord => {
|
||||
let mut state = self.state.lock().unwrap();
|
||||
let mut word = WordData::new();
|
||||
word.group_id = state.word_groups[self.selected_group_index].id.clone();
|
||||
@@ -136,21 +135,21 @@ impl DictionaryState {
|
||||
self.include_map.push(false);
|
||||
}
|
||||
|
||||
DictionaryMessage::SetKey(i, v) => {
|
||||
SetKey(i, v) => {
|
||||
{
|
||||
let dict = &mut self.state.lock().unwrap().dictionary;
|
||||
dict[i].key = v;
|
||||
}
|
||||
return self.launch_auto_save_offset(i);
|
||||
}
|
||||
DictionaryMessage::SetValue(i, v) => {
|
||||
SetValue(i, v) => {
|
||||
{
|
||||
let dict = &mut self.state.lock().unwrap().dictionary;
|
||||
dict[i].value = v
|
||||
}
|
||||
return self.launch_auto_save_offset(i);
|
||||
}
|
||||
DictionaryMessage::SetTags(i, mut v) => {
|
||||
SetTags(i, mut v) => {
|
||||
{
|
||||
let dict = &mut self.state.lock().unwrap().dictionary;
|
||||
|
||||
@@ -172,7 +171,7 @@ impl DictionaryState {
|
||||
return self.launch_auto_save_offset(i);
|
||||
}
|
||||
|
||||
DictionaryMessage::WordAction(i) => {
|
||||
WordAction(i) => {
|
||||
let state = &mut self.state.lock().unwrap();
|
||||
let dict = &mut state.dictionary;
|
||||
let word = dict.remove(i);
|
||||
@@ -180,8 +179,8 @@ impl DictionaryState {
|
||||
self.auto_save_queue.remove(&i);
|
||||
delete_word(&word, &state.connection)
|
||||
}
|
||||
DictionaryMessage::Include(i, b) => self.include_map[i] = b,
|
||||
DictionaryMessage::IncludeTag(t, v) => {
|
||||
Include(i, b) => self.include_map[i] = b,
|
||||
IncludeTag(t, v) => {
|
||||
let index: u32;
|
||||
{
|
||||
let state = self.state.lock().unwrap();
|
||||
@@ -191,19 +190,19 @@ impl DictionaryState {
|
||||
self.update_words_include(index)
|
||||
}
|
||||
|
||||
DictionaryMessage::ResetTags => {
|
||||
ResetTags => {
|
||||
self.tag_map.iter_mut().for_each(|(_, v)| *v = false);
|
||||
self.include_map.iter_mut().for_each(|x| *x = false)
|
||||
}
|
||||
DictionaryMessage::SetReverse(v) => self.reverse = v,
|
||||
DictionaryMessage::Search(s) => {
|
||||
SetReverse(v) => self.reverse = v,
|
||||
Search(s) => {
|
||||
self.search = s;
|
||||
}
|
||||
DictionaryMessage::SetTyping(b) => self.no_typing = b,
|
||||
DictionaryMessage::SubmitWord(i) => self.save_word(i),
|
||||
SetTyping(b) => self.no_typing = b,
|
||||
SubmitWord(i) => self.save_word(i),
|
||||
Back => {}
|
||||
Test => {}
|
||||
DictionaryMessage::CreateGroup => {
|
||||
CreateGroup => {
|
||||
let state = &mut self.state.lock().unwrap();
|
||||
|
||||
state.word_groups.push(WordGroup {
|
||||
@@ -230,7 +229,7 @@ impl DictionaryState {
|
||||
update_group(group, connection);
|
||||
state.word_groups[self.selected_group_index] = group.clone();
|
||||
}
|
||||
DictionaryMessage::SelectGroup(i) => {
|
||||
SelectGroup(i) => {
|
||||
self.selected_group_index = i;
|
||||
let index: u32;
|
||||
{
|
||||
@@ -256,7 +255,7 @@ impl DictionaryState {
|
||||
ChangeDirection => {
|
||||
self.reverse_list = !self.reverse_list;
|
||||
}
|
||||
DictionaryMessage::TrySave(word_index) => {
|
||||
TrySave(word_index) => {
|
||||
let now = Utc::now();
|
||||
if !self.auto_save_queue.contains_key(&word_index) {
|
||||
return Task::none();
|
||||
@@ -283,7 +282,7 @@ impl DictionaryState {
|
||||
fn launch_auto_save_offset(&mut self, index: usize) -> Task<RootMessage> {
|
||||
let save_time = Utc::now().add(TimeDelta::milliseconds(900));
|
||||
self.auto_save_queue.insert(index, save_time);
|
||||
let message = RootMessage::Dictionary(DictionaryMessage::TrySave(index));
|
||||
let message = RootMessage::Dictionary(TrySave(index));
|
||||
Task::perform(
|
||||
async { tokio::time::sleep(Duration::from_secs(1)).await },
|
||||
|_| message,
|
||||
@@ -292,13 +291,18 @@ impl DictionaryState {
|
||||
|
||||
pub fn view(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||
back_overlay(
|
||||
iced::widget::column![
|
||||
self.groups_panel(),
|
||||
self.words_list(),
|
||||
button("Добавить слово")
|
||||
.style(jl_button)
|
||||
.on_press(DictionaryMessage::NewWord),
|
||||
row![
|
||||
iced::widget::column![
|
||||
self.groups_panel(),
|
||||
self.words_list(),
|
||||
button("Добавить слово")
|
||||
.style(jl_button)
|
||||
.on_press(NewWord),
|
||||
].spacing(5),
|
||||
self.filters(),
|
||||
|
||||
]
|
||||
.spacing(5)
|
||||
.into(),
|
||||
Back,
|
||||
)
|
||||
@@ -338,7 +342,7 @@ impl DictionaryState {
|
||||
line = line
|
||||
.push(
|
||||
checkbox(self.include_map[i])
|
||||
.on_toggle(move |b| DictionaryMessage::Include(i, b)),
|
||||
.on_toggle(move |b| Include(i, b)),
|
||||
)
|
||||
.push(space().width(10));
|
||||
|
||||
@@ -346,26 +350,41 @@ impl DictionaryState {
|
||||
text_input("Слово", &word.key)
|
||||
.size(ACCENT_FONT_SIZE)
|
||||
.width(Length::Fill)
|
||||
.on_input(move |string| DictionaryMessage::SetKey(i, string))
|
||||
.on_submit(DictionaryMessage::SubmitWord(i)),
|
||||
.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| DictionaryMessage::SetValue(i, string))
|
||||
.on_submit(DictionaryMessage::SubmitWord(i)),
|
||||
.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)
|
||||
text_input("Теги", &word.tags)
|
||||
.size(ACCENT_FONT_SIZE)
|
||||
.width(Length::Fill)
|
||||
.on_input(move |string| DictionaryMessage::SetTags(i, string))
|
||||
.on_submit(DictionaryMessage::SubmitWord(i)),
|
||||
.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 = DictionaryMessage::WordAction(i);
|
||||
let action = WordAction(i);
|
||||
|
||||
if word.id == 0 {
|
||||
return button("-").on_press(action).style(|_x, _status| Style {
|
||||
@@ -378,7 +397,7 @@ impl DictionaryState {
|
||||
}
|
||||
|
||||
button("")
|
||||
.on_press(DictionaryMessage::WordAction(i))
|
||||
.on_press(WordAction(i))
|
||||
.width(15)
|
||||
};
|
||||
|
||||
@@ -396,7 +415,7 @@ impl DictionaryState {
|
||||
|
||||
iced::widget::column![
|
||||
text_input("Поиск", &self.search)
|
||||
.on_input(DictionaryMessage::Search)
|
||||
.on_input(Search)
|
||||
.width(Length::Fill),
|
||||
text!("Всего слов: {}", dict.len()),
|
||||
text!(
|
||||
@@ -406,10 +425,10 @@ impl DictionaryState {
|
||||
self.tags_selector(),
|
||||
toggler(self.no_typing)
|
||||
.label("Без набора")
|
||||
.on_toggle(DictionaryMessage::SetTyping),
|
||||
.on_toggle(SetTyping),
|
||||
toggler(self.reverse)
|
||||
.label("Обратный тест")
|
||||
.on_toggle(DictionaryMessage::SetReverse),
|
||||
.on_toggle(SetReverse),
|
||||
button(text!("Тест").center().width(Length::Fill))
|
||||
.style(jl_button)
|
||||
.on_press(Test)
|
||||
@@ -424,7 +443,7 @@ impl DictionaryState {
|
||||
let mut col = Column::new().width(Length::Fill);
|
||||
col = col.push(
|
||||
button("Сбросить")
|
||||
.on_press(DictionaryMessage::ResetTags)
|
||||
.on_press(ResetTags)
|
||||
.style(|x: &Theme, _status| Style {
|
||||
background: None,
|
||||
text_color: x.palette().primary,
|
||||
@@ -439,7 +458,7 @@ impl DictionaryState {
|
||||
col = col.push(
|
||||
checkbox(*tag.1)
|
||||
.label(tag.0)
|
||||
.on_toggle(|x1| DictionaryMessage::IncludeTag(tag.0.clone(), x1)),
|
||||
.on_toggle(|x1| IncludeTag(tag.0.clone(), x1)),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -508,7 +527,7 @@ impl DictionaryState {
|
||||
row = row.push(
|
||||
button("+")
|
||||
.style(text)
|
||||
.on_press(DictionaryMessage::CreateGroup),
|
||||
.on_press(CreateGroup),
|
||||
);
|
||||
|
||||
let state = &self.state.lock().unwrap();
|
||||
@@ -519,7 +538,7 @@ impl DictionaryState {
|
||||
row = row.push(
|
||||
button(text!("{}", group.name.clone()))
|
||||
.style(text)
|
||||
.on_press(DictionaryMessage::SelectGroup(index)),
|
||||
.on_press(SelectGroup(index)),
|
||||
);
|
||||
index = index + 1;
|
||||
}
|
||||
@@ -560,12 +579,12 @@ pub fn app_data_dir() -> PathBuf {
|
||||
dir
|
||||
}
|
||||
|
||||
pub fn app_cache_dir() -> PathBuf {
|
||||
let mut dir = dirs::cache_dir().unwrap();
|
||||
dir.push("jap_learn");
|
||||
if !dir.exists() {
|
||||
fs::create_dir(dir.clone()).unwrap();
|
||||
}
|
||||
|
||||
dir
|
||||
}
|
||||
// pub fn app_cache_dir() -> PathBuf {
|
||||
// let mut dir = dirs::cache_dir().unwrap();
|
||||
// dir.push("jap_learn");
|
||||
// if !dir.exists() {
|
||||
// fs::create_dir(dir.clone()).unwrap();
|
||||
// }
|
||||
//
|
||||
// dir
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user