From 6b6bd38e84d1d14a526765bd23926024b2eda3c7 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sun, 5 Nov 2023 15:25:29 +1300 Subject: Specify frame limit as FPS instead of as frame time --- src/window_manager.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/window_manager.rs b/src/window_manager.rs index 2652682..9322adb 100644 --- a/src/window_manager.rs +++ b/src/window_manager.rs @@ -10,14 +10,22 @@ pub struct WindowManager { } impl WindowManager { - pub fn new(min_frame_duration: Duration) -> Self { + pub fn new() -> Self { Self { event_loop: EventLoop::new(), windows: HashMap::new(), - min_frame_duration, + min_frame_duration: Duration::ZERO, } } + pub fn with_frame_limit(mut self, limit: u64) -> Self { + self.min_frame_duration = match limit { + 0 => Duration::ZERO, + _ => Duration::from_nanos(1_000_000_000 / limit), + }; + return self; + } + /// Add a window to the window manager before the event loop begins. pub fn add_window(&mut self, controller: Box) { let window = Window::new(&self.event_loop, controller); -- cgit v1.2.3-70-g09d2