Trait piston_window::prelude::EventLoop
source · pub trait EventLoop: Sized {
Show 14 methods
// Required methods
fn get_event_settings(&self) -> EventSettings;
fn set_event_settings(&mut self, settings: EventSettings);
// Provided methods
fn set_ups(&mut self, frames: u64) { ... }
fn ups(self, frames: u64) -> Self { ... }
fn set_ups_reset(&mut self, frames: u64) { ... }
fn ups_reset(self, frames: u64) -> Self { ... }
fn set_max_fps(&mut self, frames: u64) { ... }
fn max_fps(self, frames: u64) -> Self { ... }
fn set_swap_buffers(&mut self, enable: bool) { ... }
fn swap_buffers(self, enable: bool) -> Self { ... }
fn set_bench_mode(&mut self, enable: bool) { ... }
fn bench_mode(self, enable: bool) -> Self { ... }
fn set_lazy(&mut self, enable: bool) { ... }
fn lazy(self, enable: bool) -> Self { ... }
}
Expand description
Methods implemented for changing event loop settings.
Required Methods§
sourcefn get_event_settings(&self) -> EventSettings
fn get_event_settings(&self) -> EventSettings
Returns event loop settings.
sourcefn set_event_settings(&mut self, settings: EventSettings)
fn set_event_settings(&mut self, settings: EventSettings)
Sets event loop settings.
Provided Methods§
sourcefn set_ups(&mut self, frames: u64)
fn set_ups(&mut self, frames: u64)
The number of updates per second
This is the fixed update rate on average over time.
If the event loop lags, it will try to catch up.
When set to 0
, update events are disabled.
sourcefn ups(self, frames: u64) -> Self
fn ups(self, frames: u64) -> Self
The number of updates per second
This is the fixed update rate on average over time.
If the event loop lags, it will try to catch up.
When set to 0
, update events are disabled.
sourcefn set_ups_reset(&mut self, frames: u64)
fn set_ups_reset(&mut self, frames: u64)
The number of delayed updates before skipping them to catch up.
When set to 0
, it will always try to catch up.
sourcefn ups_reset(self, frames: u64) -> Self
fn ups_reset(self, frames: u64) -> Self
The number of delayed updates before skipping them to catch up.
When set to 0
, it will always try to catch up.
sourcefn set_max_fps(&mut self, frames: u64)
fn set_max_fps(&mut self, frames: u64)
The maximum number of frames per second
The frame rate can be lower because the next frame is always scheduled from the previous frame. This causes the frames to “slip” over time.
sourcefn max_fps(self, frames: u64) -> Self
fn max_fps(self, frames: u64) -> Self
The maximum number of frames per second
The frame rate can be lower because the next frame is always scheduled from the previous frame. This causes the frames to “slip” over time.
sourcefn set_swap_buffers(&mut self, enable: bool)
fn set_swap_buffers(&mut self, enable: bool)
Enable or disable automatic swapping of buffers.
sourcefn swap_buffers(self, enable: bool) -> Self
fn swap_buffers(self, enable: bool) -> Self
Enable or disable automatic swapping of buffers.
sourcefn set_bench_mode(&mut self, enable: bool)
fn set_bench_mode(&mut self, enable: bool)
Enable or disable benchmark mode.
When enabled, it will render and update without sleep and ignore input.
Used to test performance by playing through as fast as possible.
Requires lazy
to be set to false
.
sourcefn bench_mode(self, enable: bool) -> Self
fn bench_mode(self, enable: bool) -> Self
Enable or disable benchmark mode.
When enabled, it will render and update without sleep and ignore input.
Used to test performance by playing through as fast as possible.
Requires lazy
to be set to false
.
sourcefn set_lazy(&mut self, enable: bool)
fn set_lazy(&mut self, enable: bool)
Enable or disable rendering only when receiving input. When enabled, update events are disabled. Idle events are emitted while receiving input.
Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() {
let title = "Hello Piston! (press any key to enter inner loop)";
let mut window: PistonWindow = WindowSettings::new(title, [640, 480])
.exit_on_esc(true)
.build()
.unwrap_or_else(|e| panic!("Failed to build PistonWindow: {}", e));
window.set_lazy(true);
while let Some(e) = window.next() {
window.draw_2d(&e, |c, g, _| {
clear([0.5, 1.0, 0.5, 1.0], g);
rectangle(
[1.0, 0.0, 0.0, 1.0],
[50.0, 50.0, 100.0, 100.0],
c.transform,
g,
);
});
if e.press_args().is_some() {
InnerApp {
title: "Inner loop (press X to exit inner loop)",
exit_button: Button::Keyboard(Key::X),
}
.run(&mut window);
window.set_title(title.into());
}
}
}