Super repetitions optimization

This commit is contained in:
2026-08-09 14:34:38 +03:00
parent 4676b0eeef
commit 74f0f04a04
+42 -42
View File
@@ -14,10 +14,7 @@ use iced::widget::button::{danger, Status};
pub use iced::widget::button::{Catalog, Style};
use iced::widget::container::bordered_box;
use iced::widget::tooltip::Position::Top;
use iced::widget::{
button, column, container, radio, row, scrollable, space, svg, text, text_input, tooltip, Column,
Row,
};
use iced::widget::{button, column, container, lazy, radio, row, scrollable, space, svg, text, text_input, tooltip, Column, Row};
use iced::{Background, Border, Center, Color, Element, Fill, Length, Shadow, Task, Theme};
use iced_core::border::Radius;
use iced_core::svg::Handle;
@@ -267,14 +264,15 @@ impl RepetitionsState {
.spacing(DEFAULT_SPACING)
.into()
}
fn activity_bar(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {
const MAX_DAY_COUNT: f32 = 128.0;
let state = self.state.lock().unwrap();
let history = state.activity.get(&set.id);
let mut counts: Vec<u32> = vec![0; 30 * 7];
let now = Local::now().date_naive();
if let Some(history) = history {
for (date, activity) in history {
let distance = now - *date;
@@ -291,49 +289,51 @@ impl RepetitionsState {
}
}
let mut row = Row::new()
.padding(Padding {
top: 0.0,
right: 0.0,
bottom: 0.0,
left: DEFAULT_SPACING,
})
.spacing(QUARTER_SPACING);
lazy((counts, now), |(counts, now)| {
let mut row = Row::new()
.padding(Padding {
top: 0.0,
right: 0.0,
bottom: 0.0,
left: DEFAULT_SPACING,
})
.spacing(QUARTER_SPACING);
const MAX_DAY_COUNT: f32 = 128.0;
let mut iter = counts.into_iter();
for i in 0..30 {
let mut column = Column::new().spacing(QUARTER_SPACING);
let mut iter = counts.into_iter();
for i in 0..30 {
let mut column = Column::new().spacing(QUARTER_SPACING);
for j in 0..7 {
let value = iter.next().unwrap() as f32;
let k = (value / MAX_DAY_COUNT).min(1.0) * 0.9 + 0.1;
for j in 0..7 {
let value = *iter.next().unwrap() as f32;
let k = (value / MAX_DAY_COUNT).min(1.0) * 0.9 + 0.1;
let date = now.clone().checked_sub_days(Days::new(30 * 7 - i * 7 - j - 1)).unwrap();
let date = now.clone().checked_sub_days(Days::new(30 * 7 - i * 7 - j - 1)).unwrap();
column = column.push(tooltip(
iced::widget::container(space().height(15).width(15)).style(
move |x: &Theme| container::Style {
text_color: None,
background: Some(Background::Color(x.palette().primary.scale_alpha(k))),
border: Border {
color: Default::default(),
width: 0.0,
radius: Radius::new(5),
column = column.push(tooltip(
iced::widget::container(space().height(15).width(15)).style(
move |x: &Theme| container::Style {
text_color: None,
background: Some(Background::Color(x.palette().primary.scale_alpha(k))),
border: Border {
color: Default::default(),
width: 0.0,
radius: Radius::new(5),
},
shadow: Default::default(),
snap: false,
},
shadow: Default::default(),
snap: false,
},
),
text!("{} {} карточки", date.format("%Y.%m.%d"), value),
Top,
));
}
),
text!("{} {} карточки", date.format("%Y.%m.%d"), value),
Top,
));
}
row = row.push(column);
}
scrollable(column!["Карта активности", row].spacing(QUARTER_SPACING).align_x(Center))
}).into()
row = row.push(column);
}
scrollable(column!["Карта активности", row].spacing(QUARTER_SPACING).align_x(Center)).into()
}
fn words_words_view(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {