More styling

This commit is contained in:
2026-08-01 19:36:43 +03:00
parent 9a1d68aac1
commit 42d0488f23
13 changed files with 295 additions and 253 deletions
+72 -53
View File
@@ -1,7 +1,5 @@
use crate::data_provider::words::{delete_group, delete_word, update_group, update_word}; use crate::data_provider::words::{delete_group, delete_word, update_group, update_word};
use crate::dictionary::DictionaryMessage::{ use crate::dictionary::DictionaryMessage::*;
ChangeDirection, DeleteGroup, EditGroup, SaveGroup, Test,
};
use crate::dictionary_test::DictionaryQuizState; use crate::dictionary_test::DictionaryQuizState;
use crate::lang::{WordData, WordGroup}; use crate::lang::{WordData, WordGroup};
use crate::navigation::Page::Word; use crate::navigation::Page::Word;
@@ -9,7 +7,6 @@ use crate::navigation::{NavigatedPage, Page};
use crate::styling::*; use crate::styling::*;
use crate::word::WordState; use crate::word::WordState;
use crate::{AppState, RootMessage}; use crate::{AppState, RootMessage};
use DictionaryMessage::Back;
use chrono::{DateTime, TimeDelta, Utc}; use chrono::{DateTime, TimeDelta, Utc};
use iced::alignment::Vertical::Center; use iced::alignment::Vertical::Center;
use iced::widget::button::Style; use iced::widget::button::Style;
@@ -24,6 +21,8 @@ use std::ops::Add;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use iced::widget::text_input::default;
use DictionaryMessage::Back;
#[derive(Clone)] #[derive(Clone)]
pub struct DictionaryState { 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 word: WordData;
{ {
let state = self.state.lock().unwrap(); let state = self.state.lock().unwrap();
@@ -126,7 +125,7 @@ impl DictionaryState {
pub fn update(&mut self, message: DictionaryMessage) -> Task<RootMessage> { pub fn update(&mut self, message: DictionaryMessage) -> Task<RootMessage> {
match message { match message {
DictionaryMessage::NewWord => { NewWord => {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
let mut word = WordData::new(); let mut word = WordData::new();
word.group_id = state.word_groups[self.selected_group_index].id.clone(); word.group_id = state.word_groups[self.selected_group_index].id.clone();
@@ -136,21 +135,21 @@ impl DictionaryState {
self.include_map.push(false); self.include_map.push(false);
} }
DictionaryMessage::SetKey(i, v) => { SetKey(i, v) => {
{ {
let dict = &mut self.state.lock().unwrap().dictionary; let dict = &mut self.state.lock().unwrap().dictionary;
dict[i].key = v; dict[i].key = v;
} }
return self.launch_auto_save_offset(i); return self.launch_auto_save_offset(i);
} }
DictionaryMessage::SetValue(i, v) => { SetValue(i, v) => {
{ {
let dict = &mut self.state.lock().unwrap().dictionary; let dict = &mut self.state.lock().unwrap().dictionary;
dict[i].value = v dict[i].value = v
} }
return self.launch_auto_save_offset(i); return self.launch_auto_save_offset(i);
} }
DictionaryMessage::SetTags(i, mut v) => { SetTags(i, mut v) => {
{ {
let dict = &mut self.state.lock().unwrap().dictionary; let dict = &mut self.state.lock().unwrap().dictionary;
@@ -172,7 +171,7 @@ impl DictionaryState {
return self.launch_auto_save_offset(i); return self.launch_auto_save_offset(i);
} }
DictionaryMessage::WordAction(i) => { WordAction(i) => {
let state = &mut self.state.lock().unwrap(); let state = &mut self.state.lock().unwrap();
let dict = &mut state.dictionary; let dict = &mut state.dictionary;
let word = dict.remove(i); let word = dict.remove(i);
@@ -180,8 +179,8 @@ impl DictionaryState {
self.auto_save_queue.remove(&i); self.auto_save_queue.remove(&i);
delete_word(&word, &state.connection) delete_word(&word, &state.connection)
} }
DictionaryMessage::Include(i, b) => self.include_map[i] = b, Include(i, b) => self.include_map[i] = b,
DictionaryMessage::IncludeTag(t, v) => { IncludeTag(t, v) => {
let index: u32; let index: u32;
{ {
let state = self.state.lock().unwrap(); let state = self.state.lock().unwrap();
@@ -191,19 +190,19 @@ impl DictionaryState {
self.update_words_include(index) self.update_words_include(index)
} }
DictionaryMessage::ResetTags => { ResetTags => {
self.tag_map.iter_mut().for_each(|(_, v)| *v = false); self.tag_map.iter_mut().for_each(|(_, v)| *v = false);
self.include_map.iter_mut().for_each(|x| *x = false) self.include_map.iter_mut().for_each(|x| *x = false)
} }
DictionaryMessage::SetReverse(v) => self.reverse = v, SetReverse(v) => self.reverse = v,
DictionaryMessage::Search(s) => { Search(s) => {
self.search = s; self.search = s;
} }
DictionaryMessage::SetTyping(b) => self.no_typing = b, SetTyping(b) => self.no_typing = b,
DictionaryMessage::SubmitWord(i) => self.save_word(i), SubmitWord(i) => self.save_word(i),
Back => {} Back => {}
Test => {} Test => {}
DictionaryMessage::CreateGroup => { CreateGroup => {
let state = &mut self.state.lock().unwrap(); let state = &mut self.state.lock().unwrap();
state.word_groups.push(WordGroup { state.word_groups.push(WordGroup {
@@ -230,7 +229,7 @@ impl DictionaryState {
update_group(group, connection); update_group(group, connection);
state.word_groups[self.selected_group_index] = group.clone(); state.word_groups[self.selected_group_index] = group.clone();
} }
DictionaryMessage::SelectGroup(i) => { SelectGroup(i) => {
self.selected_group_index = i; self.selected_group_index = i;
let index: u32; let index: u32;
{ {
@@ -256,7 +255,7 @@ impl DictionaryState {
ChangeDirection => { ChangeDirection => {
self.reverse_list = !self.reverse_list; self.reverse_list = !self.reverse_list;
} }
DictionaryMessage::TrySave(word_index) => { TrySave(word_index) => {
let now = Utc::now(); let now = Utc::now();
if !self.auto_save_queue.contains_key(&word_index) { if !self.auto_save_queue.contains_key(&word_index) {
return Task::none(); return Task::none();
@@ -283,7 +282,7 @@ impl DictionaryState {
fn launch_auto_save_offset(&mut self, index: usize) -> Task<RootMessage> { fn launch_auto_save_offset(&mut self, index: usize) -> Task<RootMessage> {
let save_time = Utc::now().add(TimeDelta::milliseconds(900)); let save_time = Utc::now().add(TimeDelta::milliseconds(900));
self.auto_save_queue.insert(index, save_time); self.auto_save_queue.insert(index, save_time);
let message = RootMessage::Dictionary(DictionaryMessage::TrySave(index)); let message = RootMessage::Dictionary(TrySave(index));
Task::perform( Task::perform(
async { tokio::time::sleep(Duration::from_secs(1)).await }, async { tokio::time::sleep(Duration::from_secs(1)).await },
|_| message, |_| message,
@@ -292,13 +291,18 @@ impl DictionaryState {
pub fn view(&self) -> iced::Element<'_, DictionaryMessage> { pub fn view(&self) -> iced::Element<'_, DictionaryMessage> {
back_overlay( back_overlay(
iced::widget::column![ row![
self.groups_panel(), iced::widget::column![
self.words_list(), self.groups_panel(),
button("Добавить слово") self.words_list(),
.style(jl_button) button("Добавить слово")
.on_press(DictionaryMessage::NewWord), .style(jl_button)
.on_press(NewWord),
].spacing(5),
self.filters(),
] ]
.spacing(5)
.into(), .into(),
Back, Back,
) )
@@ -338,7 +342,7 @@ impl DictionaryState {
line = line line = line
.push( .push(
checkbox(self.include_map[i]) checkbox(self.include_map[i])
.on_toggle(move |b| DictionaryMessage::Include(i, b)), .on_toggle(move |b| Include(i, b)),
) )
.push(space().width(10)); .push(space().width(10));
@@ -346,26 +350,41 @@ impl DictionaryState {
text_input("Слово", &word.key) text_input("Слово", &word.key)
.size(ACCENT_FONT_SIZE) .size(ACCENT_FONT_SIZE)
.width(Length::Fill) .width(Length::Fill)
.on_input(move |string| DictionaryMessage::SetKey(i, string)) .on_input(move |string| SetKey(i, string))
.on_submit(DictionaryMessage::SubmitWord(i)), .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( line = line.push(
text_input("Перевод", &word.value) text_input("Перевод", &word.value)
.size(ACCENT_FONT_SIZE) .size(ACCENT_FONT_SIZE)
.width(Length::Fill) .width(Length::Fill)
.on_input(move |string| DictionaryMessage::SetValue(i, string)) .on_input(move |string| SetValue(i, string))
.on_submit(DictionaryMessage::SubmitWord(i)), .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( line = line.push(
text_input("Тэги", &word.tags) text_input("Теги", &word.tags)
.size(ACCENT_FONT_SIZE) .size(ACCENT_FONT_SIZE)
.width(Length::Fill) .width(Length::Fill)
.on_input(move |string| DictionaryMessage::SetTags(i, string)) .on_input(move |string| SetTags(i, string))
.on_submit(DictionaryMessage::SubmitWord(i)), .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 line_button = || {
let action = DictionaryMessage::WordAction(i); let action = WordAction(i);
if word.id == 0 { if word.id == 0 {
return button("-").on_press(action).style(|_x, _status| Style { return button("-").on_press(action).style(|_x, _status| Style {
@@ -378,7 +397,7 @@ impl DictionaryState {
} }
button("") button("")
.on_press(DictionaryMessage::WordAction(i)) .on_press(WordAction(i))
.width(15) .width(15)
}; };
@@ -396,7 +415,7 @@ impl DictionaryState {
iced::widget::column![ iced::widget::column![
text_input("Поиск", &self.search) text_input("Поиск", &self.search)
.on_input(DictionaryMessage::Search) .on_input(Search)
.width(Length::Fill), .width(Length::Fill),
text!("Всего слов: {}", dict.len()), text!("Всего слов: {}", dict.len()),
text!( text!(
@@ -406,10 +425,10 @@ impl DictionaryState {
self.tags_selector(), self.tags_selector(),
toggler(self.no_typing) toggler(self.no_typing)
.label("Без набора") .label("Без набора")
.on_toggle(DictionaryMessage::SetTyping), .on_toggle(SetTyping),
toggler(self.reverse) toggler(self.reverse)
.label("Обратный тест") .label("Обратный тест")
.on_toggle(DictionaryMessage::SetReverse), .on_toggle(SetReverse),
button(text!("Тест").center().width(Length::Fill)) button(text!("Тест").center().width(Length::Fill))
.style(jl_button) .style(jl_button)
.on_press(Test) .on_press(Test)
@@ -424,7 +443,7 @@ impl DictionaryState {
let mut col = Column::new().width(Length::Fill); let mut col = Column::new().width(Length::Fill);
col = col.push( col = col.push(
button("Сбросить") button("Сбросить")
.on_press(DictionaryMessage::ResetTags) .on_press(ResetTags)
.style(|x: &Theme, _status| Style { .style(|x: &Theme, _status| Style {
background: None, background: None,
text_color: x.palette().primary, text_color: x.palette().primary,
@@ -439,7 +458,7 @@ impl DictionaryState {
col = col.push( col = col.push(
checkbox(*tag.1) checkbox(*tag.1)
.label(tag.0) .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( row = row.push(
button("+") button("+")
.style(text) .style(text)
.on_press(DictionaryMessage::CreateGroup), .on_press(CreateGroup),
); );
let state = &self.state.lock().unwrap(); let state = &self.state.lock().unwrap();
@@ -519,7 +538,7 @@ impl DictionaryState {
row = row.push( row = row.push(
button(text!("{}", group.name.clone())) button(text!("{}", group.name.clone()))
.style(text) .style(text)
.on_press(DictionaryMessage::SelectGroup(index)), .on_press(SelectGroup(index)),
); );
index = index + 1; index = index + 1;
} }
@@ -560,12 +579,12 @@ pub fn app_data_dir() -> PathBuf {
dir dir
} }
pub fn app_cache_dir() -> PathBuf { // pub fn app_cache_dir() -> PathBuf {
let mut dir = dirs::cache_dir().unwrap(); // let mut dir = dirs::cache_dir().unwrap();
dir.push("jap_learn"); // dir.push("jap_learn");
if !dir.exists() { // if !dir.exists() {
fs::create_dir(dir.clone()).unwrap(); // fs::create_dir(dir.clone()).unwrap();
} // }
//
dir // dir
} // }
+10 -9
View File
@@ -7,6 +7,7 @@ use iced::widget::{button, container, row, space, text, text_input, Row};
use iced::Background::Color; use iced::Background::Color;
use iced::{alignment, Border, Element, Fill, Task, Theme}; use iced::{alignment, Border, Element, Fill, Task, Theme};
use rand::prelude::SliceRandom; use rand::prelude::SliceRandom;
use crate::dictionary_test::DictionaryQuizMessage::*;
use crate::lang::WordData; use crate::lang::WordData;
use crate::navigation::{NavigatedPage, Page}; use crate::navigation::{NavigatedPage, Page};
use crate::navigation::Page::PreviousPage; use crate::navigation::Page::PreviousPage;
@@ -36,7 +37,7 @@ pub enum DictionaryQuizMessage {
impl NavigatedPage<DictionaryQuizMessage> for DictionaryQuizState { impl NavigatedPage<DictionaryQuizMessage> for DictionaryQuizState {
fn navigate(&self, message: &DictionaryQuizMessage) -> Option<Page> { fn navigate(&self, message: &DictionaryQuizMessage) -> Option<Page> {
match message { match message {
DictionaryQuizMessage::Back => Some(PreviousPage), Back => Some(PreviousPage),
_ => None, _ => None,
} }
} }
@@ -64,10 +65,10 @@ impl DictionaryQuizState {
pub fn update(&mut self, message: DictionaryQuizMessage) -> Task<RootMessage> { pub fn update(&mut self, message: DictionaryQuizMessage) -> Task<RootMessage> {
match message { match message {
DictionaryQuizMessage::Back => {} Back => {}
DictionaryQuizMessage::AnswerChanged(c) => self.answer = c.clone(), AnswerChanged(c) => self.answer = c.clone(),
DictionaryQuizMessage::SubmitAnswer => self.submit(), SubmitAnswer => self.submit(),
DictionaryQuizMessage::Appeal => self.appeal_answer(), Appeal => self.appeal_answer(),
} }
Task::none() Task::none()
} }
@@ -92,8 +93,8 @@ impl DictionaryQuizState {
text_input("Перевод", &self.answer) text_input("Перевод", &self.answer)
.size(28) .size(28)
.width(250) .width(250)
.on_input(DictionaryQuizMessage::AnswerChanged) .on_input(AnswerChanged)
.on_submit(DictionaryQuizMessage::SubmitAnswer), .on_submit(SubmitAnswer),
row![ row![
text!("{}", self.score.total.to_string()).size(25), text!("{}", self.score.total.to_string()).size(25),
text!("{}", self.score.correct.to_string()) text!("{}", self.score.correct.to_string())
@@ -105,7 +106,7 @@ impl DictionaryQuizState {
] ]
.spacing(DEFAULT_SPACING), .spacing(DEFAULT_SPACING),
row![ row![
button("Закончить").style(jl_button).on_press(DictionaryQuizMessage::Back), button("Закончить").style(jl_button).on_press(Back),
self.appeal_button() self.appeal_button()
] ]
.spacing(DEFAULT_SPACING), .spacing(DEFAULT_SPACING),
@@ -206,7 +207,7 @@ impl DictionaryQuizState {
fn appeal_button(&self) -> Element<'_, DictionaryQuizMessage> { fn appeal_button(&self) -> Element<'_, DictionaryQuizMessage> {
if self.is_help && self.no_typing == false { if self.is_help && self.no_typing == false {
return button("Апелляция").style(jl_button) return button("Апелляция").style(jl_button)
.on_press(DictionaryQuizMessage::Appeal) .on_press(Appeal)
.into(); .into();
} }
space().into() space().into()
+19 -21
View File
@@ -1,18 +1,17 @@
use crate::data_provider::history::{HistoryItem, get_history_of_set}; use crate::data_provider::history::{get_history_of_set, HistoryItem};
use crate::lang::WordData; use crate::lang::WordData;
use crate::navigation::{NavigatedPage, Page};
use crate::styling::*;
use crate::{AppState, RootMessage}; use crate::{AppState, RootMessage};
use HistoryMessage::Back;
use iced::alignment::Horizontal::Center; use iced::alignment::Horizontal::Center;
use iced::widget::space::horizontal; use iced::widget::space::horizontal;
use iced::widget::*; use iced::widget::*;
use iced::{Element, Fill, FillPortion, Left, Task}; use iced::{Element, Fill, FillPortion, Task};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use crate::navigation::{NavigatedPage, Page}; use HistoryMessage::Back;
use crate::styling::*;
#[derive(Clone)] #[derive(Clone)]
pub struct HistoryState { pub struct HistoryState {
set_id: u32,
list: Vec<HistoryItem>, list: Vec<HistoryItem>,
words: Vec<WordData>, words: Vec<WordData>,
} }
@@ -21,7 +20,6 @@ impl NavigatedPage<HistoryMessage> for HistoryState {
fn navigate(&self, message: &HistoryMessage) -> Option<Page> { fn navigate(&self, message: &HistoryMessage) -> Option<Page> {
match message { match message {
Back => Some(Page::PreviousPage), Back => Some(Page::PreviousPage),
_ => None,
} }
} }
} }
@@ -43,7 +41,6 @@ impl HistoryState {
.collect(); .collect();
Self { Self {
set_id: id,
list: history, list: history,
words, words,
} }
@@ -54,25 +51,26 @@ impl HistoryState {
} }
pub fn view(&self) -> Element<'_, HistoryMessage> { pub fn view(&self) -> Element<'_, HistoryMessage> {
container( back_overlay(iced::widget::row![
iced::widget::column![
button("Назад").style(jl_button).on_press(Back),
iced::widget::row![
horizontal().width(FillPortion(1)), horizontal().width(FillPortion(1)),
scrollable(self.history_lines().padding(DEFAULT_SPACING)) scrollable(self.history_lines().padding(DEFAULT_SPACING))
.height(Fill) .height(Fill)
.width(FillPortion(5)), .width(FillPortion(5)),
horizontal().width(FillPortion(1)) horizontal().width(FillPortion(1))
] ]
.height(Fill) .height(Fill)
.width(Fill) .width(Fill).into(), Back)
] // container(
.align_x(Left) // iced::widget::column![
.width(Fill), // button("Назад").style(jl_button).on_press(Back),
) //
.center_x(Fill) // ]
.padding(10) // .align_x(Left)
.into() // .width(Fill),
// )
// .center_x(Fill)
// .padding(10)
// .into()
} }
fn history_lines(&self) -> Column<'_, HistoryMessage> { fn history_lines(&self) -> Column<'_, HistoryMessage> {
+31 -7
View File
@@ -298,7 +298,7 @@ impl CardStatistics {
let time = Utc::now() - self.last_open; let time = Utc::now() - self.last_open;
let days = time.num_days(); let days = time.num_days();
let multiplier = FADE_PER_DAY.powi(days as i32); let multiplier = FADE_PER_DAY.powi(days as i32);
self.score as f32 * multiplier (self.score as f32 * multiplier).max(1.0)
} }
} }
@@ -574,17 +574,30 @@ impl SemiRandomSRSModule {
#[derive(Clone)] #[derive(Clone)]
struct WorstWordsSRSModule { struct WorstWordsSRSModule {
initialized: bool, initialized: bool,
rounds: u8, pool_size: usize,
pool: Vec<u32> rounds_remaining: u8,
pool: Vec<usize>,
queue: Vec<usize>,
rounds_count: u8,
} }
impl SRSModule for WorstWordsSRSModule { impl SRSModule for WorstWordsSRSModule {
fn next(&mut self, _: &mut CardSet) -> usize { fn next(&mut self, set: &mut CardSet) -> usize {
todo!() if self.rounds_remaining == 0 {
self.fill_pool(set);
self.rounds_remaining = self.rounds_count;
}
if self.queue.is_empty() {
self.queue.append(&mut self.pool.clone());
self.rounds_remaining -= 1;
}
self.queue.pop().unwrap()
} }
fn open(&mut self, _: WordOpenMode, _: usize, _: CardStatistics) { fn open(&mut self, _: WordOpenMode, _: usize, _: CardStatistics) {
todo!()
} }
fn init(&mut self, _: &mut CardSet) { fn init(&mut self, _: &mut CardSet) {
@@ -596,8 +609,19 @@ impl WorstWordsSRSModule {
fn new() -> WorstWordsSRSModule { fn new() -> WorstWordsSRSModule {
WorstWordsSRSModule { WorstWordsSRSModule {
initialized: false, initialized: false,
rounds: 0, pool_size: 15,
rounds_count: 2,
rounds_remaining: 0,
pool: vec![], pool: vec![],
queue: vec![],
} }
} }
fn fill_pool(&mut self, set: &CardSet) {
let mut sorted = set.set.clone().into_iter().zip(0..set.set.len()).collect::<Vec<_>>();
sorted.sort_by_key(|c| c.0.score);
let mut worst = sorted[0..self.pool_size].iter().map(|(_, index)| *index).collect::<Vec<usize>>();
worst.shuffle(&mut rand::rng());
self.pool = worst;
}
} }
+1 -2
View File
@@ -24,9 +24,8 @@ use crate::navigation::{AppSettings, RootMessage, ScreenState};
use crate::quiz::*; use crate::quiz::*;
use crate::repetitions::CardSetSettings; use crate::repetitions::CardSetSettings;
use crate::RootMessage::Keyboard; use crate::RootMessage::Keyboard;
use fontdb::Database;
use iced::{keyboard, Program, Subscription, Theme};
use iced::Font; use iced::Font;
use iced::{keyboard, Program, Subscription, Theme};
use rusqlite::Connection; use rusqlite::Connection;
+6 -5
View File
@@ -5,6 +5,7 @@ use iced::{alignment, Element, Fill, Task};
use rand::seq::SliceRandom; use rand::seq::SliceRandom;
use crate::navigation::{NavigatedPage, Page}; use crate::navigation::{NavigatedPage, Page};
use crate::navigation::Page::PreviousPage; use crate::navigation::Page::PreviousPage;
use crate::quiz::QuizMessage::*;
use crate::styling::*; use crate::styling::*;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@@ -20,7 +21,7 @@ pub struct QuizState {
impl NavigatedPage<QuizMessage> for QuizState { impl NavigatedPage<QuizMessage> for QuizState {
fn navigate(&self, message: &QuizMessage) -> Option<Page> { fn navigate(&self, message: &QuizMessage) -> Option<Page> {
if let QuizMessage::Back = message { if let Back = message {
Some(PreviousPage) Some(PreviousPage)
} else { } else {
None None
@@ -55,7 +56,7 @@ impl Default for QuizState {
impl QuizState { impl QuizState {
pub fn update(&mut self, message: QuizMessage) -> Task<RootMessage> { pub fn update(&mut self, message: QuizMessage) -> Task<RootMessage> {
match message { match message {
QuizMessage::ContentChanged(content) => { ContentChanged(content) => {
if content.contains("`") { if content.contains("`") {
self.is_help = true; self.is_help = true;
self.score.fail += 1; self.score.fail += 1;
@@ -77,7 +78,7 @@ impl QuizState {
self.update_showed() self.update_showed()
} }
} }
QuizMessage::Back => todo!(), Back => todo!(),
} }
Task::none() Task::none()
} }
@@ -118,7 +119,7 @@ impl QuizState {
text_input("Романдзи", &self.current_roman) text_input("Романдзи", &self.current_roman)
.size(28) .size(28)
.width(150) .width(150)
.on_input(QuizMessage::ContentChanged), .on_input(ContentChanged),
row![ row![
text!("{}", self.score.total.to_string()).size(25), text!("{}", self.score.total.to_string()).size(25),
text!("{}", self.score.correct.to_string()) text!("{}", self.score.correct.to_string())
@@ -129,7 +130,7 @@ impl QuizState {
.size(25), .size(25),
] ]
.spacing(DEFAULT_SPACING), .spacing(DEFAULT_SPACING),
button("Закончить").style(jl_button).on_press(QuizMessage::Back), button("Закончить").style(jl_button).on_press(Back),
] ]
.spacing(DEFAULT_SPACING) .spacing(DEFAULT_SPACING)
.align_x(alignment::Horizontal::Center), .align_x(alignment::Horizontal::Center),
+29 -20
View File
@@ -1,17 +1,16 @@
pub mod randomizer { pub mod randomizer {
use crate::randomizer::randomizer::RandomizerMessage::{Back, Start, Edit}; use crate::navigation::{NavigatedPage, Page};
use crate::{RootMessage}; use crate::randomizer::randomizer::RandomizerMessage::{Back, Edit, Start};
use iced::widget::{button, container, text_editor}; use crate::styling::{back_overlay, jl_button};
use crate::RootMessage;
use iced::widget::{button, text_editor};
use iced::Task; use iced::Task;
use rand::prelude::SliceRandom; use rand::prelude::SliceRandom;
use crate::navigation::{NavigatedPage, Page};
use crate::styling::jl_button;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct RandomizerState { pub struct RandomizerState {
text: text_editor::Content, text: text_editor::Content,
list: Vec<String> list: Vec<String>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@@ -38,15 +37,23 @@ pub mod randomizer {
impl RandomizerState { impl RandomizerState {
pub fn new() -> RandomizerState { pub fn new() -> RandomizerState {
RandomizerState { text: Default::default(), list: vec![] } RandomizerState {
text: Default::default(),
list: vec![],
}
} }
pub fn update(&mut self, message: RandomizerMessage) -> Task<RootMessage> { pub fn update(&mut self, message: RandomizerMessage) -> Task<RootMessage> {
match message { match message {
Edit(action) => { Edit(action) => {
self.text.perform(action); self.text.perform(action);
self.list = self.text.text().split("\n").map(|s| s.to_string()).collect(); self.list = self
}, .text
.text()
.split("\n")
.map(|s| s.to_string())
.collect();
}
Start => { Start => {
self.list.shuffle(&mut rand::rng()); self.list.shuffle(&mut rand::rng());
self.text = text_editor::Content::with_text(self.list.join("\n").as_str()); self.text = text_editor::Content::with_text(self.list.join("\n").as_str());
@@ -57,17 +64,19 @@ pub mod randomizer {
} }
pub fn view(&self) -> iced::Element<'_, RandomizerMessage> { pub fn view(&self) -> iced::Element<'_, RandomizerMessage> {
container( back_overlay(
iced::widget::column![ iced::widget::column![
button("Назад").style(jl_button).on_press(Back), text_editor(&self.text)
text_editor(&self.text).on_action(Edit .on_action(Edit)
).width(400).height(400).placeholder("Каждый элемент с новой строки"), .width(400)
button("Перемешать").style(jl_button).on_press(Start), .height(400)
] .placeholder("Каждый элемент с новой строки"),
.spacing(5), button("Перемешать").style(jl_button).on_press(Start),
]
.spacing(5)
.into(),
Back,
) )
.padding(10)
.into()
} }
} }
} }
+5 -17
View File
@@ -8,8 +8,8 @@ use crate::{AppState, RootMessage};
use iced::alignment::Horizontal::Center; use iced::alignment::Horizontal::Center;
use iced::keyboard::key::Physical::Code; use iced::keyboard::key::Physical::Code;
use iced::widget::text::Style; use iced::widget::text::Style;
use iced::widget::{Column, button, column, container, row, rule, space, text, tooltip}; use iced::widget::{button, column, container, row, rule, space, text, tooltip, Column};
use iced::{Element, Fill, Left, Task, Theme, alignment, keyboard}; use iced::{alignment, keyboard, Element, Fill, Task, Theme};
use rodio::MixerDeviceSink; use rodio::MixerDeviceSink;
use std::collections::HashSet; use std::collections::HashSet;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@@ -113,12 +113,7 @@ impl RepetitionState {
} }
pub fn view(&self) -> Element<'_, RepetitionMessage> { pub fn view(&self) -> Element<'_, RepetitionMessage> {
container( back_overlay(column![
iced::widget::column![
button("Назад")
.style(jl_button)
.on_press(RepetitionMessage::Back),
column![
container(self.draw_forward()) container(self.draw_forward())
.width(Fill) .width(Fill)
.height(Fill) .height(Fill)
@@ -141,15 +136,8 @@ impl RepetitionState {
/ 100.0 / 100.0
) )
] ]
.height(Fill) .height(Fill)
.width(Fill) .width(Fill).into(), RepetitionMessage::Back)
]
.align_x(Left)
.width(Fill),
)
.center_x(Fill)
.padding(10)
.into()
} }
fn draw_forward(&self) -> Element<'_, RepetitionMessage> { fn draw_forward(&self) -> Element<'_, RepetitionMessage> {
+7 -17
View File
@@ -11,7 +11,7 @@ use iced::widget::button::{danger, Status};
pub use iced::widget::button::{Catalog, Style}; pub use iced::widget::button::{Catalog, Style};
use iced::widget::container::bordered_box; use iced::widget::container::bordered_box;
use iced::widget::{button, column, container, radio, row, scrollable, space, text, text_input, Column}; use iced::widget::{button, column, container, radio, row, scrollable, space, text, text_input, Column};
use iced::{Background, Border, Center, Color, Element, Fill, Left, Length, Shadow, Task, Theme}; use iced::{Background, Border, Center, Color, Element, Fill, Length, Shadow, Task, Theme};
use rhai::{Engine, Scope}; use rhai::{Engine, Scope};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@@ -120,10 +120,7 @@ impl RepetitionsState {
} }
pub fn view(&self) -> Element<'_, RepetitionsMessage> { pub fn view(&self) -> Element<'_, RepetitionsMessage> {
container( back_overlay(row![
iced::widget::column![
button("Назад").style(jl_button).on_press(RepetitionsMessage::Back),
row![
column![ column![
scrollable(self.sets_list()).height(Fill), scrollable(self.sets_list()).height(Fill),
button("Добавить").style(jl_button) button("Добавить").style(jl_button)
@@ -135,17 +132,10 @@ impl RepetitionsState {
self.selected_set_view(), self.selected_set_view(),
self.launch_button() self.launch_button()
] ]
.align_y(Center) .align_y(Center)
.spacing(DEFAULT_SPACING) .spacing(DEFAULT_SPACING)
.width(Fill) .width(Fill)
.height(Fill) .height(Fill).into(), RepetitionsMessage::Back)
]
.align_x(Left)
.width(Fill),
)
.center_x(Fill)
.padding(10)
.into()
} }
fn launch_button(&self) -> Element<'_, RepetitionsMessage> { fn launch_button(&self) -> Element<'_, RepetitionsMessage> {
@@ -223,7 +213,7 @@ impl RepetitionsState {
fn count_view(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> { fn count_view(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {
if let Some(count) = set.count { if let Some(count) = set.count {
return text!("Колличество слов: {}", count).into(); return text!("Количество слов: {}", count).into();
} }
space().into() space().into()
} }
+5 -5
View File
@@ -9,7 +9,7 @@ use crate::{AppState, QuizState, RootMessage};
use iced::widget::*; use iced::widget::*;
use iced::{alignment, Element, Task}; use iced::{alignment, Element, Task};
use crate::navigation::{NavigatedPage, Page}; use crate::navigation::{NavigatedPage, Page};
use crate::navigation::Page::{Quiz, Writing}; use crate::navigation::Page::*;
use crate::styling::*; use crate::styling::*;
use crate::sync::SyncState; use crate::sync::SyncState;
@@ -44,16 +44,16 @@ impl NavigatedPage<SelectorMessage> for SelectorState {
}; };
} }
if let SelectorMessage::ToDictionary = message { if let SelectorMessage::ToDictionary = message {
return Some(Page::Dictionary(DictionaryState::new(self.state.clone()))); return Some(Dictionary(DictionaryState::new(self.state.clone())));
} }
if let SelectorMessage::ToRandomize = message { if let SelectorMessage::ToRandomize = message {
return Some(Page::Randomizer(RandomizerState::default())); return Some(Randomizer(RandomizerState::default()));
} }
if let SelectorMessage::ToRepetitions = message { if let SelectorMessage::ToRepetitions = message {
return Some(Page::Repetitions(RepetitionsState::new(self.state.clone()))); return Some(Repetitions(RepetitionsState::new(self.state.clone())));
} }
if let SelectorMessage::ToSync = message { if let SelectorMessage::ToSync = message {
return Some(Page::Sync(SyncState::new(self.state.clone()))); return Some(Sync(SyncState::new(self.state.clone())));
} }
None None
} }
+12 -14
View File
@@ -1,11 +1,11 @@
use crate::repetitions::Style;
use iced::border::Radius; use iced::border::Radius;
use iced::Element;
use iced::widget::button::{primary, Status}; use iced::widget::button::{primary, Status};
use iced::widget::{button, container}; use iced::widget::{button, container};
use crate::repetitions::Style; use iced::Element;
use iced_core::{Border, Theme};
use iced_core::alignment::Horizontal::Left; use iced_core::alignment::Horizontal::Left;
use iced_core::Length::Fill; use iced_core::Length::Fill;
use iced_core::{Border, Theme};
pub const DEFAULT_SPACING: f32 = 16.0; pub const DEFAULT_SPACING: f32 = 16.0;
pub const ACCENT_FONT_SIZE: f32 = 22.0; pub const ACCENT_FONT_SIZE: f32 = 22.0;
@@ -13,8 +13,7 @@ const BUTTON_RADIUS: f32 = 8.0;
pub fn jl_button(theme: &Theme, status: Status) -> Style { pub fn jl_button(theme: &Theme, status: Status) -> Style {
let mut style = primary(theme, status); let mut style = primary(theme, status);
style.border = Border style.border = Border {
{
color: Default::default(), color: Default::default(),
width: 0.0, width: 0.0,
radius: Radius::new(BUTTON_RADIUS), radius: Radius::new(BUTTON_RADIUS),
@@ -25,15 +24,14 @@ pub fn jl_button(theme: &Theme, status: Status) -> Style {
pub fn back_overlay<'a, T: Clone + 'a>(content: Element<'a, T>, back_message: T) -> Element<'a, T> { pub fn back_overlay<'a, T: Clone + 'a>(content: Element<'a, T>, back_message: T) -> Element<'a, T> {
container( container(
iced::widget::column![ iced::widget::column![
button("Назад") button("Назад").style(jl_button).on_press(back_message),
.style(jl_button)
.on_press(back_message),
content content
] ]
.align_x(Left) .spacing(5)
.width(Fill), .align_x(Left)
.width(Fill),
) )
.center_x(Fill) .center_x(Fill)
.padding(10) .padding(10)
.into() .into()
} }
+28 -40
View File
@@ -3,12 +3,12 @@ use crate::dictionary::app_data_dir;
use crate::navigation::Page::PreviousPage; use crate::navigation::Page::PreviousPage;
use crate::navigation::{NavigatedPage, Page}; use crate::navigation::{NavigatedPage, Page};
use crate::styling::*; use crate::styling::*;
use crate::sync::SyncMessage::NextAnimation; use crate::sync::SyncMessage::*;
use crate::{fill_state, AppState, RootMessage}; use crate::{fill_state, AppState, RootMessage};
use iced::widget::button::danger; use iced::widget::button::danger;
use iced::widget::container::rounded_box; use iced::widget::container::rounded_box;
use iced::widget::{button, column, container, progress_bar, row, space, text}; use iced::widget::{button, column, container, progress_bar, row, space, text};
use iced::{Center, Element, Fill, Font, Left, Length, Task}; use iced::{Center, Element, Fill, Font, Length, Task};
use std::io; use std::io;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time::Duration; use std::time::Duration;
@@ -41,7 +41,7 @@ pub struct SyncState {
impl NavigatedPage<SyncMessage> for SyncState { impl NavigatedPage<SyncMessage> for SyncState {
fn navigate(&self, message: &SyncMessage) -> Option<Page> { fn navigate(&self, message: &SyncMessage) -> Option<Page> {
if let SyncMessage::Back = message if let Back = message
&& !self.frozen && !self.frozen
{ {
Some(PreviousPage) Some(PreviousPage)
@@ -62,25 +62,25 @@ impl SyncState {
pub fn update(&mut self, message: SyncMessage) -> Task<RootMessage> { pub fn update(&mut self, message: SyncMessage) -> Task<RootMessage> {
match message { match message {
SyncMessage::Back => {} Back => {}
SyncMessage::CopyKey => { CopyKey => {
let state = self.state.lock().unwrap(); let state = self.state.lock().unwrap();
let key = state.sync_data.key.clone().unwrap(); let key = state.sync_data.key.clone().unwrap();
return iced::clipboard::write(key) return iced::clipboard::write(key)
.map(|_val: String| RootMessage::Sync(SyncMessage::KeyCopied)); .map(|_val: String| RootMessage::Sync(KeyCopied));
} }
SyncMessage::InitSync => { InitSync => {
return Task::perform(first_sync(), |id| { return Task::perform(first_sync(), |id| {
RootMessage::Sync(SyncMessage::IdReceived(id)) RootMessage::Sync(IdReceived(id))
}); });
} }
SyncMessage::GetKey => { GetKey => {
return iced::clipboard::read().map(|key| { return iced::clipboard::read().map(|key| {
RootMessage::Sync(SyncMessage::IdReceived(key.unwrap_or_else(String::new))) RootMessage::Sync(IdReceived(key.unwrap_or_else(String::new)))
}); });
} }
SyncMessage::KeyCopied => {} KeyCopied => {}
SyncMessage::IdReceived(new_id) => { IdReceived(new_id) => {
if validate_id(&new_id) == false { if validate_id(&new_id) == false {
return Task::none(); return Task::none();
} }
@@ -88,7 +88,7 @@ impl SyncState {
state.sync_data.key = Some(new_id.clone()); state.sync_data.key = Some(new_id.clone());
set_setting("SYNC_KEY".to_string(), new_id, &state.connection); set_setting("SYNC_KEY".to_string(), new_id, &state.connection);
} }
SyncMessage::Send => { Send => {
self.prepare_to_db_interaction(); self.prepare_to_db_interaction();
let id = self.state.lock().unwrap().sync_data.key.clone().unwrap(); let id = self.state.lock().unwrap().sync_data.key.clone().unwrap();
@@ -98,13 +98,13 @@ impl SyncState {
|_| RootMessage::Sync(NextAnimation), |_| RootMessage::Sync(NextAnimation),
), ),
Task::perform(send_data(id), |_| { Task::perform(send_data(id), |_| {
RootMessage::Sync(SyncMessage::NetworkFinished) RootMessage::Sync(NetworkFinished)
}), }),
]); ]);
return tasks; return tasks;
} }
SyncMessage::GetLast => { GetLast => {
let id = self.state.lock().unwrap().sync_data.key.clone().unwrap(); let id = self.state.lock().unwrap().sync_data.key.clone().unwrap();
let tasks = Task::batch([ let tasks = Task::batch([
Task::perform( Task::perform(
@@ -112,7 +112,7 @@ impl SyncState {
|_| RootMessage::Sync(NextAnimation), |_| RootMessage::Sync(NextAnimation),
), ),
Task::perform(load_data(id), |_| { Task::perform(load_data(id), |_| {
RootMessage::Sync(SyncMessage::NetworkFinished) RootMessage::Sync(NetworkFinished)
}), }),
]); ]);
@@ -130,7 +130,7 @@ impl SyncState {
); );
} }
} }
SyncMessage::NetworkFinished => { NetworkFinished => {
self.frozen = false; self.frozen = false;
let mut updated_state = AppState::new(); let mut updated_state = AppState::new();
fill_state(&mut updated_state); fill_state(&mut updated_state);
@@ -143,8 +143,8 @@ impl SyncState {
state.word_groups = updated_state.word_groups; state.word_groups = updated_state.word_groups;
} }
SyncMessage::Disable => {} Disable => {}
SyncMessage::DisableSync => { DisableSync => {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
state.sync_data.key = None; state.sync_data.key = None;
@@ -155,21 +155,9 @@ impl SyncState {
} }
pub fn view(&self) -> Element<'_, SyncMessage> { pub fn view(&self) -> Element<'_, SyncMessage> {
container( back_overlay(row![space().width(Fill), self.sync_column(), space().width(Fill)]
column![ .spacing(DEFAULT_SPACING)
button("Назад").style(jl_button).on_press(SyncMessage::Back), .width(Fill).into(), Back)
row![space().width(Fill), self.sync_column(), space().width(Fill)]
.spacing(DEFAULT_SPACING)
.width(Fill)
]
.align_x(Left)
.width(Fill)
.height(Fill)
.spacing(DEFAULT_SPACING),
)
.center_x(Fill)
.padding(10)
.into()
} }
fn sync_column(&self) -> Element<'_, SyncMessage> { fn sync_column(&self) -> Element<'_, SyncMessage> {
@@ -188,23 +176,23 @@ impl SyncState {
.style(rounded_box), .style(rounded_box),
button("Скопировать в буфер обмена").style(jl_button) button("Скопировать в буфер обмена").style(jl_button)
.on_press(SyncMessage::CopyKey) .on_press(CopyKey)
.width(Fill), .width(Fill),
row![ row![
button("↑ Отправить").style(jl_button).on_press(SyncMessage::Send), button("↑ Отправить").style(jl_button).on_press(Send),
space().width(Fill), space().width(Fill),
button("↓ Скачать").style(jl_button).on_press(SyncMessage::GetLast) button("↓ Скачать").style(jl_button).on_press(GetLast)
] ]
.spacing(DEFAULT_SPACING), .spacing(DEFAULT_SPACING),
container(network_view).width(Fill), container(network_view).width(Fill),
button("Отключить синхронизацию") button("Отключить синхронизацию")
.style(danger) .style(danger)
.on_press(SyncMessage::DisableSync), .on_press(DisableSync),
] ]
} else { } else {
column![ column![
button("Создать сохранение").style(jl_button).on_press(SyncMessage::InitSync), button("Создать сохранение").style(jl_button).on_press(InitSync),
button("Вставить ключ из буфера").style(jl_button).on_press(SyncMessage::GetKey), button("Вставить ключ из буфера").style(jl_button).on_press(GetKey),
] ]
} }
} }
+66 -39
View File
@@ -1,13 +1,14 @@
use crate::data_provider::words::{delete_word, update_word}; use crate::data_provider::words::{delete_word, update_word};
use crate::lang::WordData; use crate::lang::WordData;
use crate::navigation::Page::PreviousPage;
use crate::navigation::{NavigatedPage, Page};
use crate::styling::*;
use crate::word::WordMessage::*;
use crate::{AppState, RootMessage}; use crate::{AppState, RootMessage};
use iced::widget::button::danger; use iced::widget::button::danger;
use iced::widget::{button, column, container, row, rule, scrollable, space, text, text_input}; use iced::widget::{button, column, row, rule, scrollable, space, text, text_input};
use iced::{Element, Fill, Task}; use iced::{Element, Fill, Task};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use crate::navigation::{NavigatedPage, Page};
use crate::navigation::Page::PreviousPage;
use crate::styling::*;
#[derive(Clone)] #[derive(Clone)]
pub struct WordState { pub struct WordState {
@@ -18,7 +19,7 @@ pub struct WordState {
impl NavigatedPage<WordMessage> for WordState { impl NavigatedPage<WordMessage> for WordState {
fn navigate(&self, message: &WordMessage) -> Option<Page> { fn navigate(&self, message: &WordMessage) -> Option<Page> {
if let WordMessage::Back = message { if let Back = message {
Some(PreviousPage) Some(PreviousPage)
} else { } else {
None None
@@ -35,34 +36,37 @@ impl WordState {
impl WordState { impl WordState {
pub fn update(&mut self, message: WordMessage) -> Task<RootMessage> { pub fn update(&mut self, message: WordMessage) -> Task<RootMessage> {
match message { match message {
WordMessage::Back => {} Back => {}
WordMessage::Save => { Save => {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
state.dictionary[self.index] = self.word.clone(); state.dictionary[self.index] = self.word.clone();
update_word(&mut self.word, &state.connection); update_word(&mut self.word, &state.connection);
return Task::done(RootMessage::Word(WordMessage::Back)); return Task::done(RootMessage::Word(Back));
} }
WordMessage::Delete => { Delete => {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
state.dictionary.remove(self.index); state.dictionary.remove(self.index);
delete_word(&self.word, &state.connection); delete_word(&self.word, &state.connection);
return Task::done(RootMessage::Word(WordMessage::Back)); return Task::done(RootMessage::Word(Back));
} }
WordMessage::SetTags(n) => self.word.tags = n, SetTags(n) => self.word.tags = n,
WordMessage::SetKey(n) => { SetKey(n) => {
self.word.key = n; self.word.key = n;
} }
WordMessage::SetValue(n) => { SetValue(n) => {
self.word.value = n; self.word.value = n;
} }
WordMessage::SetAdditional(key, value) => match key.as_str() { SetAdditional(key, value) => match key.as_str() {
_ => { _ => {
self.word.additional.insert(key, value.clone()); self.word.additional.insert(key, value.clone());
} }
}, },
WordMessage::AddAdditional(key) => { AddAdditional(key) => {
self.word.additional.insert(key, "".to_string()); self.word.additional.insert(key, "".to_string());
} }
RemoveAdditional(key) => {
self.word.additional.remove(key.as_str());
}
} }
Task::none() Task::none()
} }
@@ -73,14 +77,14 @@ impl WordState {
fast_add = fast_add.push( fast_add = fast_add.push(
button("Чтение") button("Чтение")
.style(button::text) .style(button::text)
.on_press(WordMessage::AddAdditional("reading".to_string())), .on_press(AddAdditional("reading".to_string())),
); );
} }
if !self.word.additional.contains_key("description") { if !self.word.additional.contains_key("description") {
fast_add = fast_add.push( fast_add = fast_add.push(
button("Описание") button("Описание")
.style(button::text) .style(button::text)
.on_press(WordMessage::AddAdditional("description".to_string())), .on_press(AddAdditional("description".to_string())),
); );
} }
@@ -88,18 +92,26 @@ impl WordState {
fast_add = fast_add.push( fast_add = fast_add.push(
button("В контексте") button("В контексте")
.style(button::text) .style(button::text)
.on_press(WordMessage::AddAdditional("context".to_string())), .on_press(AddAdditional("context".to_string())),
); );
} }
let mut col = iced::widget::column![ let mut col = iced::widget::column![
button("Назад").style(jl_button).on_press(WordMessage::Back), column![
text!("Ключ"), text!("Ключ"),
text_input("key", &self.word.key).on_input(WordMessage::SetKey), text_input("key", &self.word.key).on_input(SetKey),
text!("Значение"), ]
text_input("value", &self.word.value).on_input(WordMessage::SetValue), .spacing(DEFAULT_SPACING / 4.0),
text!("Теги"), column![
text_input("tags", &self.word.tags).on_input(WordMessage::SetTags), text!("Значение"),
text_input("value", &self.word.value).on_input(SetValue),
]
.spacing(DEFAULT_SPACING / 4.0),
column![
text!("Теги"),
text_input("tags", &self.word.tags).on_input(SetTags),
]
.spacing(DEFAULT_SPACING / 4.0),
rule::horizontal(2), rule::horizontal(2),
scrollable(fast_add), scrollable(fast_add),
]; ];
@@ -107,21 +119,20 @@ impl WordState {
for more in &self.word.additional { for more in &self.word.additional {
col = col.push(self.get_view_for_more(more)); col = col.push(self.get_view_for_more(more));
} }
container(
back_overlay(
column![ column![
col.spacing(DEFAULT_SPACING).width(Fill).height(Fill), col.spacing(DEFAULT_SPACING / 2.0).width(Fill).height(Fill),
row![ row![
button("Сохранить").style(jl_button).on_press(WordMessage::Save), button("Сохранить").style(jl_button).on_press(Save),
button("Удалить") button("Удалить").style(danger).on_press(Delete),
.style(danger)
.on_press(WordMessage::Delete),
] ]
.spacing(DEFAULT_SPACING) .spacing(DEFAULT_SPACING)
] ]
.spacing(DEFAULT_SPACING), .spacing(DEFAULT_SPACING)
.into(),
Back,
) )
.padding(DEFAULT_SPACING)
.into()
} }
fn get_view_for_more(&self, value: (&String, &String)) -> Element<'_, WordMessage> { fn get_view_for_more(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
@@ -145,14 +156,29 @@ impl WordState {
self.additional_field(value, "В контексте".to_string(), "context".to_string()) self.additional_field(value, "В контексте".to_string(), "context".to_string())
} }
fn additional_field(&self, value: (&String, &String), name: String, id: String) -> Element<'_, WordMessage> { fn additional_field(
&self,
value: (&String, &String),
name: String,
id: String,
) -> Element<'_, WordMessage> {
column![ column![
text!("{}", name), text!("{}", name),
text_input(id.clone().as_str(), &value.1) row![
.on_input(move |string| WordMessage::SetAdditional(id.clone(), string)) text_input(id.clone().as_str(), &value.1)
.on_input({
let value = id.clone();
move |string| SetAdditional(value.clone(), string)
})
.width(Fill),
button("-")
.on_press(RemoveAdditional(id.clone()))
.style(danger),
]
.spacing(DEFAULT_SPACING / 4.0),
] ]
.spacing(DEFAULT_SPACING) .spacing(DEFAULT_SPACING / 4.0)
.into() .into()
} }
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@@ -164,5 +190,6 @@ pub enum WordMessage {
SetKey(String), SetKey(String),
SetValue(String), SetValue(String),
AddAdditional(String), AddAdditional(String),
RemoveAdditional(String),
SetAdditional(String, String), SetAdditional(String, String),
} }