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
+69 -42
View File
@@ -1,13 +1,14 @@
use crate::data_provider::words::{delete_word, update_word};
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 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 std::sync::{Arc, Mutex};
use crate::navigation::{NavigatedPage, Page};
use crate::navigation::Page::PreviousPage;
use crate::styling::*;
#[derive(Clone)]
pub struct WordState {
@@ -18,7 +19,7 @@ pub struct WordState {
impl NavigatedPage<WordMessage> for WordState {
fn navigate(&self, message: &WordMessage) -> Option<Page> {
if let WordMessage::Back = message {
if let Back = message {
Some(PreviousPage)
} else {
None
@@ -35,34 +36,37 @@ impl WordState {
impl WordState {
pub fn update(&mut self, message: WordMessage) -> Task<RootMessage> {
match message {
WordMessage::Back => {}
WordMessage::Save => {
Back => {}
Save => {
let mut state = self.state.lock().unwrap();
state.dictionary[self.index] = self.word.clone();
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();
state.dictionary.remove(self.index);
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,
WordMessage::SetKey(n) => {
SetTags(n) => self.word.tags = n,
SetKey(n) => {
self.word.key = n;
}
WordMessage::SetValue(n) => {
SetValue(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());
}
},
WordMessage::AddAdditional(key) => {
AddAdditional(key) => {
self.word.additional.insert(key, "".to_string());
}
RemoveAdditional(key) => {
self.word.additional.remove(key.as_str());
}
}
Task::none()
}
@@ -73,14 +77,14 @@ impl WordState {
fast_add = fast_add.push(
button("Чтение")
.style(button::text)
.on_press(WordMessage::AddAdditional("reading".to_string())),
.on_press(AddAdditional("reading".to_string())),
);
}
if !self.word.additional.contains_key("description") {
fast_add = fast_add.push(
button("Описание")
.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(
button("В контексте")
.style(button::text)
.on_press(WordMessage::AddAdditional("context".to_string())),
.on_press(AddAdditional("context".to_string())),
);
}
let mut col = iced::widget::column![
button("Назад").style(jl_button).on_press(WordMessage::Back),
text!("Ключ"),
text_input("key", &self.word.key).on_input(WordMessage::SetKey),
text!("Значение"),
text_input("value", &self.word.value).on_input(WordMessage::SetValue),
text!("Теги"),
text_input("tags", &self.word.tags).on_input(WordMessage::SetTags),
column![
text!("Ключ"),
text_input("key", &self.word.key).on_input(SetKey),
]
.spacing(DEFAULT_SPACING / 4.0),
column![
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),
scrollable(fast_add),
];
@@ -107,21 +119,20 @@ impl WordState {
for more in &self.word.additional {
col = col.push(self.get_view_for_more(more));
}
container(
back_overlay(
column![
col.spacing(DEFAULT_SPACING).width(Fill).height(Fill),
col.spacing(DEFAULT_SPACING / 2.0).width(Fill).height(Fill),
row![
button("Сохранить").style(jl_button).on_press(WordMessage::Save),
button("Удалить")
.style(danger)
.on_press(WordMessage::Delete),
button("Сохранить").style(jl_button).on_press(Save),
button("Удалить").style(danger).on_press(Delete),
]
.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> {
@@ -140,19 +151,34 @@ impl WordState {
fn description_field(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
self.additional_field(value, "Описание".to_string(), "description".to_string())
}
fn context_field(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
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![
text!("{}", name),
text_input(id.clone().as_str(), &value.1)
.on_input(move |string| WordMessage::SetAdditional(id.clone(), string))
row![
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)
.into()
.spacing(DEFAULT_SPACING / 4.0)
.into()
}
}
#[derive(Debug, Clone)]
@@ -164,5 +190,6 @@ pub enum WordMessage {
SetKey(String),
SetValue(String),
AddAdditional(String),
RemoveAdditional(String),
SetAdditional(String, String),
}