commit a618da3ed7a0b020c77a134764dfbb343c04fad6
parent 800ab26cb48a05c558742f226ad4128305600286
Author: William Casarin <jb55@jb55.com>
Date:   Sun,  9 Jul 2023 14:20:50 -0700
show fps on top panel
Diffstat:
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/app.rs b/src/app.rs
@@ -1,6 +1,7 @@
 use crate::abbrev;
 use crate::contacts::Contacts;
 use crate::fonts::setup_fonts;
+use crate::frame_history::FrameHistory;
 use crate::images::fetch_img;
 use crate::ui::padding;
 use crate::Result;
@@ -49,6 +50,8 @@ pub struct Damus {
     events: Vec<EventId>,
 
     img_cache: ImageCache,
+
+    frame_history: crate::frame_history::FrameHistory,
 }
 
 impl Default for Damus {
@@ -61,6 +64,7 @@ impl Default for Damus {
             events: vec![],
             img_cache: HashMap::new(),
             n_panels: 1,
+            frame_history: FrameHistory::default(),
         }
     }
 }
@@ -428,6 +432,12 @@ fn render_panel(ctx: &egui::Context, app: &mut Damus) {
             {
                 app.n_panels -= 1;
             }
+
+            ui.label(format!(
+                "FPS: {:.2}, {:10.1}ms",
+                app.frame_history.fps(),
+                app.frame_history.mean_frame_time() * 1e3
+            ));
         });
     });
 }
@@ -551,7 +561,10 @@ impl eframe::App for Damus {
 
     /// Called each time the UI needs repainting, which may be many times per second.
     /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
-    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
+    fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
+        self.frame_history
+            .on_new_frame(ctx.input(|i| i.time), frame.info().cpu_usage);
+
         #[cfg(feature = "profiling")]
         puffin::GlobalProfiler::lock().new_frame();
         update_damus(self, ctx);
diff --git a/src/lib.rs b/src/lib.rs
@@ -9,6 +9,7 @@ mod fonts;
 mod images;
 mod result;
 mod ui;
+mod frame_history;
 
 pub use app::Damus;
 pub use error::Error;