commit 3fafda34b41615275d4ea26a5637806d7dbf6635
parent 205d627f99731d3ca244007c4a1fb865afec5a1f
Author: kernelkind <kernelkind@gmail.com>
Date: Mon, 13 Jan 2025 18:48:16 -0500
introduce ZoomHandler
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
1 file changed, 26 insertions(+), 0 deletions(-)
diff --git a/crates/notedeck_chrome/src/persist_zoom.rs b/crates/notedeck_chrome/src/persist_zoom.rs
@@ -0,0 +1,26 @@
+use egui::Context;
+use notedeck::{DataPath, DataPathType};
+
+use crate::timed_serializer::TimedSerializer;
+
+pub struct ZoomHandler {
+ serializer: TimedSerializer<f32>,
+}
+
+impl ZoomHandler {
+ pub fn new(path: &DataPath) -> Self {
+ let serializer =
+ TimedSerializer::new(path, DataPathType::Setting, "zoom_level.json".to_owned());
+
+ Self { serializer }
+ }
+
+ pub fn try_save_zoom_factor(&mut self, ctx: &Context) {
+ let cur_zoom_level = ctx.zoom_factor();
+ self.serializer.try_save(cur_zoom_level);
+ }
+
+ pub fn get_zoom_factor(&self) -> Option<f32> {
+ self.serializer.get_item()
+ }
+}