updated card display
This commit is contained in:
1 parent
632f0c341b
commit
5b2b48c88f
3 files changed
+114
-86
No files matched your search
+11
-86
@@ -1,22 +1,22 @@
|
||||
use crate::app::AppState;
|
||||
use crate::core::deck::DeckData;
|
||||
use crate::core::srs::WordOpenMode;
|
||||
use crate::data::Id;
|
||||
use crate::data::entities::{CardState, WordData};
|
||||
use crate::data::entities::{CardState, CustomField, WordData};
|
||||
use crate::data::repositories::Repository;
|
||||
use crate::data::Id;
|
||||
use crate::data_provider::voice::get_voice;
|
||||
use crate::jl_button;
|
||||
use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::{KeyPressedPage, NavigatedPage, Page, RootMessage};
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::pages::repetition::RepetitionMessage::Play;
|
||||
use crate::pages::repetitions::DeckRunData;
|
||||
use crate::styling::*;
|
||||
use crate::{push_error, push_error_task};
|
||||
use iced::alignment::Horizontal::Center;
|
||||
use iced::keyboard::key::Physical::Code;
|
||||
use iced::widget::text::Style;
|
||||
use iced::widget::{Column, button, column, container, row, rule, space, text, tooltip};
|
||||
use iced::{Element, Fill, Task, Theme, alignment, keyboard};
|
||||
use iced::widget::{button, column, container, row, text, tooltip};
|
||||
use iced::{keyboard, Element, Fill, Task, Theme};
|
||||
use rodio::MixerDeviceSink;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
@@ -32,6 +32,7 @@ pub struct RepetitionState {
|
||||
can_play: bool,
|
||||
sink: Arc<Option<MixerDeviceSink>>,
|
||||
opened: HashSet<Id>,
|
||||
custom_fields_cache: Vec<CustomField>,
|
||||
}
|
||||
|
||||
impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
||||
@@ -73,17 +74,7 @@ impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
||||
fn view(&self) -> Element<'_, RepetitionMessage> {
|
||||
back_overlay(
|
||||
column![
|
||||
container(self.draw_forward())
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.align_x(Center)
|
||||
.align_y(alignment::Vertical::Center),
|
||||
rule::horizontal(2),
|
||||
container(self.draw_backward())
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.align_x(Center)
|
||||
.align_y(alignment::Vertical::Center),
|
||||
crate::widgets::card_display::word_display(&self.settings.general_settings, &self.current_word, self.open, Play, self.custom_fields_cache.as_slice()),
|
||||
container(self.answer_bar())
|
||||
.width(Fill)
|
||||
.align_x(Center)
|
||||
@@ -92,7 +83,7 @@ impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
||||
"Затронуто слов {}, {}%",
|
||||
self.opened.len(),
|
||||
(self.opened.len() as f32 / self.set.len() as f32 * 10000.0).round() / 100.0
|
||||
)
|
||||
),
|
||||
]
|
||||
.height(Fill)
|
||||
.width(Fill)
|
||||
@@ -117,6 +108,8 @@ impl RepetitionState {
|
||||
None
|
||||
};
|
||||
|
||||
let custom_fields_cache = state.custom_fields.read().iter().cloned().collect();
|
||||
|
||||
Ok(RepetitionState {
|
||||
state,
|
||||
settings: set,
|
||||
@@ -127,6 +120,7 @@ impl RepetitionState {
|
||||
can_play: true,
|
||||
sink: Arc::new(sink_handle),
|
||||
opened: HashSet::new(),
|
||||
custom_fields_cache,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -169,43 +163,6 @@ impl RepetitionState {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn draw_forward(&self) -> Element<'_, RepetitionMessage> {
|
||||
self.draw_card_view(self.settings.forward.as_str())
|
||||
}
|
||||
|
||||
fn draw_backward(&self) -> Element<'_, RepetitionMessage> {
|
||||
if !self.open {
|
||||
return container(text!("?").size(72))
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.align_y(alignment::Vertical::Center)
|
||||
.align_x(Center)
|
||||
.into();
|
||||
}
|
||||
|
||||
self.draw_card_view(self.settings.backward.as_str())
|
||||
}
|
||||
|
||||
fn draw_card_view(&self, properties: &str) -> Element<'_, RepetitionMessage> {
|
||||
let word = &self.current_word;
|
||||
|
||||
let mut col = Column::new();
|
||||
|
||||
for view_type in properties.split(" ") {
|
||||
col = col.push(match view_type {
|
||||
"key" => self.draw_key(word),
|
||||
"value" => self.draw_value(word),
|
||||
"speech" => self.draw_voice(),
|
||||
"reading" => self.draw_reading(word),
|
||||
"context" => self.draw_context(word),
|
||||
"description" => self.draw_description(word),
|
||||
_ => space().into(),
|
||||
})
|
||||
}
|
||||
|
||||
col.spacing(DEFAULT_SPACING).align_x(Center).into()
|
||||
}
|
||||
|
||||
fn answer_bar(&self) -> Element<'_, RepetitionMessage> {
|
||||
if !self.open {
|
||||
return text!("Нажмите Пробел для открытия карточки")
|
||||
@@ -247,38 +204,6 @@ impl RepetitionState {
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn draw_key(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||
text!("{}", word.key).size(36).into()
|
||||
}
|
||||
fn draw_value(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||
text!("{}", word.value).size(24).into()
|
||||
}
|
||||
|
||||
fn draw_voice(&self) -> Element<'_, RepetitionMessage> {
|
||||
jl_button!("Воспроизвести")
|
||||
.on_press(RepetitionMessage::Play)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn draw_reading(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||
match word.additional.get(&Id(1)) {
|
||||
None => space().into(),
|
||||
Some(reading) => text!("{}", reading).size(24).into(),
|
||||
}
|
||||
}
|
||||
fn draw_context(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||
match word.additional.get(&Id(3)) {
|
||||
None => space().into(),
|
||||
Some(context) => text!("{}", context).center().size(24).into(),
|
||||
}
|
||||
}
|
||||
fn draw_description(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||
match word.additional.get(&Id(2)) {
|
||||
None => space().into(),
|
||||
Some(context) => text!("{}", context).center().size(24).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyPressedPage for RepetitionState {
|
||||
|
||||
Reference in new issue
Block a user