notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

app_size.rs (930B)


      1 use std::time::Duration;
      2 
      3 use egui::Context;
      4 
      5 use notedeck::{DataPath, DataPathType};
      6 
      7 use crate::timed_serializer::TimedSerializer;
      8 
      9 pub struct AppSizeHandler {
     10     serializer: TimedSerializer<egui::Vec2>,
     11 }
     12 
     13 impl AppSizeHandler {
     14     pub fn new(path: &DataPath) -> Self {
     15         let serializer =
     16             TimedSerializer::new(path, DataPathType::Setting, "app_size.json".to_owned())
     17                 .with_delay(Duration::from_millis(500));
     18 
     19         Self { serializer }
     20     }
     21 
     22     pub fn try_save_app_size(&mut self, ctx: &Context) {
     23         // There doesn't seem to be a way to check if user is resizing window, so if the rect is different than last saved, we'll wait DELAY before saving again to avoid spamming io
     24         let cur_size = ctx.input(|i| i.screen_rect.size());
     25         self.serializer.try_save(cur_size);
     26     }
     27 
     28     pub fn get_app_size(&self) -> Option<egui::Vec2> {
     29         self.serializer.get_item()
     30     }
     31 }