persist_zoom.rs (647B)
1 use egui::Context; 2 use notedeck::{DataPath, DataPathType}; 3 4 use crate::timed_serializer::TimedSerializer; 5 6 pub struct ZoomHandler { 7 serializer: TimedSerializer<f32>, 8 } 9 10 impl ZoomHandler { 11 pub fn new(path: &DataPath) -> Self { 12 let serializer = 13 TimedSerializer::new(path, DataPathType::Setting, "zoom_level.json".to_owned()); 14 15 Self { serializer } 16 } 17 18 pub fn try_save_zoom_factor(&mut self, ctx: &Context) { 19 let cur_zoom_level = ctx.zoom_factor(); 20 self.serializer.try_save(cur_zoom_level); 21 } 22 23 pub fn get_zoom_factor(&self) -> Option<f32> { 24 self.serializer.get_item() 25 } 26 }