diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2023-11-05 15:25:29 +1300 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2023-12-19 21:17:35 +1300 |
commit | 6b6bd38e84d1d14a526765bd23926024b2eda3c7 (patch) | |
tree | e749fd95c37c551d5dd6f88c0cbee46c01d897b7 /src | |
parent | 5b4232c00733cd30bdb0d74ec7ebac5ab714aa32 (diff) | |
download | phosphor-6b6bd38e84d1d14a526765bd23926024b2eda3c7.zip |
Specify frame limit as FPS instead of as frame time
Diffstat (limited to 'src')
-rw-r--r-- | src/window_manager.rs | 12 |
1 files changed, 10 insertions, 2 deletions
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<dyn WindowController>) { let window = Window::new(&self.event_loop, controller); |