Struct MainLoopScheduler
pub struct MainLoopScheduler(/* private fields */);Expand description
MainLoopScheduler implements the Kanzi application main loop in form of a customizable sequence of stages, each consisting of a sequence of tasks,
where a task is any callable, including functions, function objects, and lambdas.
It also provides the default Kanzi stages, along with platform specific mechanisms for automatic suspension, and frame rate control.
You can customize the application main loop by extending its stages with additional tasks, replacing existing tasks with your own implementations, or adding timer tasks to execute some functionality at regular intervals.
Implementations§
§impl MainLoopScheduler
impl MainLoopScheduler
pub fn prepend_task(
&self,
stage: MainLoopStage,
name: impl AsRef<KanziStr>,
recurrence: TaskRecurrence,
closure: impl Task,
) -> Result<MainLoopTaskToken, Error>
pub fn prepend_task( &self, stage: MainLoopStage, name: impl AsRef<KanziStr>, recurrence: TaskRecurrence, closure: impl Task, ) -> Result<MainLoopTaskToken, Error>
Adds a task to the front of a stage.
§Arguments
stage- Reference to the stage.name- Name for the task.recurrence- Recurrence choice for the task that you want to insert.task- The task that you want to insert.
§Returns
Token of the added task. You can use that token to remove or replace the task.
pub fn append_task(
&self,
stage: MainLoopStage,
name: impl AsRef<KanziStr>,
recurrence: TaskRecurrence,
closure: impl Task,
) -> Result<MainLoopTaskToken, Error>
pub fn append_task( &self, stage: MainLoopStage, name: impl AsRef<KanziStr>, recurrence: TaskRecurrence, closure: impl Task, ) -> Result<MainLoopTaskToken, Error>
Adds a task to the back of a stage.
§Arguments
stage- Reference to the stage.name- Name for the task.recurrence- Recurrence choice for the task that you want to insert.task- The task that you want to insert.
§Returns
Token of the added task. You can use that token to remove or replace the task.
pub fn replace_task(
&self,
stage: MainLoopStage,
token: &MainLoopTaskToken,
closure: impl Task,
) -> Result<bool, Error>
pub fn replace_task( &self, stage: MainLoopStage, token: &MainLoopTaskToken, closure: impl Task, ) -> Result<bool, Error>
pub fn remove_task(
&self,
stage: MainLoopStage,
token: &MainLoopTaskToken,
) -> Result<bool, Error>
pub fn remove_task( &self, stage: MainLoopStage, token: &MainLoopTaskToken, ) -> Result<bool, Error>
pub fn clear_tasks(&self, stage: MainLoopStage) -> Result<(), Error>
pub fn clear_tasks(&self, stage: MainLoopStage) -> Result<(), Error>
§impl MainLoopScheduler
impl MainLoopScheduler
pub fn prepend_timer(
&self,
stage: MainLoopStage,
name: impl AsRef<KanziStr>,
recurrence: TimerRecurrence,
interval: Duration,
closure: impl TimerTask,
) -> Result<MainLoopTimerToken, Error>
pub fn prepend_timer( &self, stage: MainLoopStage, name: impl AsRef<KanziStr>, recurrence: TimerRecurrence, interval: Duration, closure: impl TimerTask, ) -> Result<MainLoopTimerToken, Error>
Adds a timer task to be executed before a stage in the main loop. Use this overload when you do not have the task name available at compile time.
§Arguments
stage- Reference to the stage.name- Name for the task.recurrence- Recurrence type of the task.interval- The amount of time after which to execute the task.task- The task.
§Returns
Token of the added task. You can use this token to remove the task.
§Errors
Returns an INVALID_ARGUMENT error if the provided Duration doesn’t fit into i64.
pub fn append_timer(
&self,
stage: MainLoopStage,
name: impl AsRef<KanziStr>,
recurrence: TimerRecurrence,
interval: Duration,
closure: impl TimerTask,
) -> Result<MainLoopTimerToken, Error>
pub fn append_timer( &self, stage: MainLoopStage, name: impl AsRef<KanziStr>, recurrence: TimerRecurrence, interval: Duration, closure: impl TimerTask, ) -> Result<MainLoopTimerToken, Error>
Adds a timer task to be executed after a stage in the main loop. Use this overload when you do not have the task name available at compile time.
§Arguments
stage- Reference to the stage.name- Name for the task.recurrence- Recurrence type of the task.interval- The amount of time after which to execute the task.task- The task.
§Returns
Token of the added task. You can use this token to remove the task.
§Errors
Returns an INVALID_ARGUMENT error if the provided Duration doesn’t fit into i64.
pub fn remove_timer(&self, token: &MainLoopTimerToken) -> Result<bool, Error>
pub fn remove_timer(&self, token: &MainLoopTimerToken) -> Result<bool, Error>
§impl MainLoopScheduler
impl MainLoopScheduler
pub fn set_current_frame_rendered(&self) -> Result<(), Error>
pub fn set_current_frame_rendered(&self) -> Result<(), Error>
Sets whether rendering was performed in the current frame.
Call this function from a task in the Render stage to inform the main loop that the task performed rendering.
The main loop uses this as a precondition for executing the Present stage for a frame.
pub fn is_current_frame_rendered(&self) -> Result<bool, Error>
pub fn is_current_frame_rendered(&self) -> Result<bool, Error>
pub fn set_frame_rate_limit(&self, frame_rate: u32) -> Result<(), Error>
pub fn set_frame_rate_limit(&self, frame_rate: u32) -> Result<(), Error>
Sets the frame rate limit of the application. This sets an upper limit on the number of frames rendered by Kanzi every second.
§Arguments
frame_rate- The number of frames to render every second. To disable frame rate limit, use 0.
pub fn enable_suspend_when_idle(
&self,
suspend_enable: bool,
) -> Result<(), Error>
pub fn enable_suspend_when_idle( &self, suspend_enable: bool, ) -> Result<(), Error>
Sets whether an application allows suspension.
§Arguments
suspend_enable- If the application allows suspension, usetrue, otherwisefalse.
pub fn is_suspend_when_idle_enabled(&self) -> Result<bool, Error>
pub fn is_suspend_when_idle_enabled(&self) -> Result<bool, Error>
Returns whether an application allows suspension.
§Returns
If the application allows suspension, true, otherwise false.
pub fn pause(&self) -> Result<(), Error>
pub fn pause(&self) -> Result<(), Error>
Pauses the main loop and changes its state to Paused.
let main_loop_scheduler = domain.main_loop_scheduler();
main_loop_scheduler.pause()?;
assert_eq!(main_loop_scheduler.get_state()?, kanzi::MainLoopState::Paused);pub fn resume(&self) -> Result<(), Error>
pub fn resume(&self) -> Result<(), Error>
Resumes the main loop and changes its state back to Running.
let main_loop_scheduler = domain.main_loop_scheduler();
main_loop_scheduler.resume()?;
assert_eq!(main_loop_scheduler.get_state()?, kanzi::MainLoopState::Running);pub fn quit(&self) -> Result<(), Error>
pub fn quit(&self) -> Result<(), Error>
Quits the main loop and changes its state to Quitting.
let main_loop_scheduler = domain.main_loop_scheduler();
main_loop_scheduler.quit()?;
assert_eq!(main_loop_scheduler.get_state()?, kanzi::MainLoopState::Quitting);pub fn get_state(&self) -> Result<MainLoopState, Error>
pub fn get_state(&self) -> Result<MainLoopState, Error>
Gets the main loop scheduler state.
Trait Implementations§
§impl Clone for MainLoopScheduler
impl Clone for MainLoopScheduler
§fn clone(&self) -> MainLoopScheduler
fn clone(&self) -> MainLoopScheduler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more