Add basic methods into NavigatedPage
This commit is contained in:
+56
-54
@@ -39,30 +39,7 @@ impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
||||
|
||||
fn navigated(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
impl RepetitionState {
|
||||
pub(crate) fn new(set: CardSetSettings, state: Arc<Mutex<AppState>>) -> RepetitionState {
|
||||
let mut card_set = CardSet::new(&set, state.clone());
|
||||
let (word, stat) = card_set.next();
|
||||
let sink_handle = rodio::DeviceSinkBuilder::open_default_sink().unwrap();
|
||||
|
||||
RepetitionState {
|
||||
state,
|
||||
settings: set,
|
||||
set: card_set,
|
||||
current_word: word,
|
||||
current_statistic: stat,
|
||||
open: false,
|
||||
can_play: true,
|
||||
sink: Arc::new(sink_handle),
|
||||
opened: HashSet::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RepetitionState {
|
||||
pub fn update(&mut self, message: RepetitionMessage) -> Task<RootMessage> {
|
||||
fn update(&mut self, message: RepetitionMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
RepetitionMessage::Back => {}
|
||||
RepetitionMessage::Next => return self.next(),
|
||||
@@ -87,6 +64,60 @@ impl RepetitionState {
|
||||
|
||||
Task::none()
|
||||
}
|
||||
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),
|
||||
container(self.answer_bar())
|
||||
.width(Fill)
|
||||
.align_x(Center)
|
||||
.height(80),
|
||||
text!(
|
||||
"Затронуто слов {}, {}%",
|
||||
self.opened.len(),
|
||||
(self.opened.len() as f32 / self.set.len() as f32 * 10000.0).round() / 100.0
|
||||
)
|
||||
]
|
||||
.height(Fill)
|
||||
.width(Fill)
|
||||
.into(),
|
||||
RepetitionMessage::Back,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl RepetitionState {
|
||||
pub(crate) fn new(set: CardSetSettings, state: Arc<Mutex<AppState>>) -> RepetitionState {
|
||||
let mut card_set = CardSet::new(&set, state.clone());
|
||||
let (word, stat) = card_set.next();
|
||||
let sink_handle = rodio::DeviceSinkBuilder::open_default_sink().unwrap();
|
||||
|
||||
RepetitionState {
|
||||
state,
|
||||
settings: set,
|
||||
set: card_set,
|
||||
current_word: word,
|
||||
current_statistic: stat,
|
||||
open: false,
|
||||
can_play: true,
|
||||
sink: Arc::new(sink_handle),
|
||||
opened: HashSet::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RepetitionState {
|
||||
|
||||
|
||||
fn next(&mut self) -> Task<RootMessage> {
|
||||
if self.open {
|
||||
@@ -137,36 +168,7 @@ impl RepetitionState {
|
||||
state.activity.insert(id, vec![(now, 1)]);
|
||||
}
|
||||
}
|
||||
pub 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),
|
||||
container(self.answer_bar())
|
||||
.width(Fill)
|
||||
.align_x(Center)
|
||||
.height(80),
|
||||
text!(
|
||||
"Затронуто слов {}, {}%",
|
||||
self.opened.len(),
|
||||
(self.opened.len() as f32 / self.set.len() as f32 * 10000.0).round() / 100.0
|
||||
)
|
||||
]
|
||||
.height(Fill)
|
||||
.width(Fill)
|
||||
.into(),
|
||||
RepetitionMessage::Back,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
fn draw_forward(&self) -> Element<'_, RepetitionMessage> {
|
||||
self.draw_card_view(self.settings.forward.as_str())
|
||||
|
||||
Reference in New Issue
Block a user