Respect animations preference when paging up/down

This commit is contained in:
2025-07-22 14:10:25 +02:00
parent 61575fbf65
commit a663de3ca0

View File

@ -1,4 +1,4 @@
use egui::{Color32, Context, RichText, Theme, Ui, Visuals};
use egui::{Color32, Context, RichText, Theme, Ui, Visuals, style::ScrollAnimation};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
@ -14,7 +14,7 @@ pub struct Preferences {
pub hide_handwriting_cursor: bool,
#[serde(skip)]
has_applied_theme: bool,
has_applied_prefs: bool,
}
impl Default for Preferences {
@ -22,7 +22,7 @@ impl Default for Preferences {
Self {
animations: true,
high_contrast: false,
has_applied_theme: false,
has_applied_prefs: false,
hide_handwriting_cursor: false,
}
}
@ -31,8 +31,20 @@ impl Default for Preferences {
impl Preferences {
/// Apply preferences, if they haven't already been applied.
pub fn apply(&mut self, ctx: &Context) {
if !self.has_applied_theme {
self.has_applied_theme = true;
if !self.has_applied_prefs {
self.has_applied_prefs = true;
let scroll_animation = if self.animations {
ScrollAnimation::default()
} else {
ScrollAnimation::none()
};
for theme in [Theme::Dark, Theme::Light] {
ctx.style_mut_of(theme, |style| {
style.scroll_animation = scroll_animation;
});
}
let mut dark_visuals = Visuals::dark();
let mut light_visuals = Visuals::light();
@ -71,11 +83,15 @@ impl Preferences {
pub fn show(&mut self, ui: &mut Ui) {
ui.label(RichText::new("Prefs").weak());
ui.toggle_value(&mut self.animations, "Animations");
let animations_toggle = ui.toggle_value(&mut self.animations, "Animations");
if animations_toggle.clicked() {
self.has_applied_prefs = false;
self.apply(ui.ctx());
}
let high_contrast_toggle = ui.toggle_value(&mut self.high_contrast, "High Contrast");
if high_contrast_toggle.clicked() {
self.has_applied_theme = false;
self.has_applied_prefs = false;
self.apply(ui.ctx());
}