pub enum StepperAction {
Add(Box<dyn for<'a> IStepper + Send + 'static>, TypeId, StepperId),
RemoveAll(TypeId),
Remove(StepperId),
Quit(StepperId, String),
Event(StepperId, String, String),
}
Expand description
Steppers actions list. These are the events you can trigger from any threads. There are 3 ways to trigger an action:
- Main thread/program where you can use sk: Sk::send_event or crate::sk::Sk::quit directly.
- From any IStepper you should use SkInfo::send_event.
- From any threads you should use winit::event_loop::EventLoopProxy::send_event. You can get a proxy clone from SkInfo::get_event_loop_proxy or Sk::get_event_loop_proxy.
https://stereokit.net/Pages/StereoKit/SK.html
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::named_colors,
tools::{title::Title, screenshot::{ScreenshotViewer, SHOW_SCREENSHOT_WINDOW}}, };
use std::any::TypeId; // we need this to remove all the steppers of a given type.
let mut title = Title::new("StepperAction", Some(named_colors::GREEN), None, None);
title.transform = Matrix::t_r([-1.0, 0.0, -1.0], [0.0, 155.0, 0.0]);
sk.send_event(StepperAction::add("Title_green_ID", title.clone()));
sk.send_event(StepperAction::add_default::<Title>("Title_white_ID"));
sk.send_event(StepperAction::add_default::<ScreenshotViewer>("ScreenshotViewer_ID"));
sk.send_event(StepperAction::event("main thread".into(), SHOW_SCREENSHOT_WINDOW, "true"));
filename_scr = "screenshots/stepper_actions.jpeg";
number_of_steps = 4;
test_screenshot!( // !!!! Get a proper main loop !!!!
if iter == 0 {
assert_eq!(sk.get_steppers_count(), 3);
sk.send_event(StepperAction::remove("Title_white_ID"));
} else if iter == 1 {
assert_eq!(sk.get_steppers_count(), 2);
sk.send_event(StepperAction::remove_all(TypeId::of::<Title>()));
} else if iter == 2 {
assert_eq!(sk.get_steppers_count(), 1);
sk.send_event(StepperAction::add("Title_green_ID", title.clone()));
} else if iter < number_of_steps + 2{
assert_eq!(sk.get_steppers_count(), 2);
}
);

Variants§
Add(Box<dyn for<'a> IStepper + Send + 'static>, TypeId, StepperId)
Add a new stepper of TypeID, identified by its StepperID
RemoveAll(TypeId)
Remove all steppers of TypeID
Remove(StepperId)
Remove the stepper identified by its StepperID
Quit(StepperId, String)
Quit the app,
Event(StepperId, String, String)
Event sent by a stepper for those who need it. Key -> Value are strings.
Implementations§
Source§impl StepperAction
impl StepperAction
Sourcepub fn add_default<T: IStepper + Send + Default + 'static>(
stepper_id: impl AsRef<str>,
) -> Self
pub fn add_default<T: IStepper + Send + Default + 'static>( stepper_id: impl AsRef<str>, ) -> Self
This instantiates and registers an instance of the IStepper type provided as the generic parameter. SK will hold onto it, Initialize it, Step it every frame, and call Shutdown when the application ends. This is generally safe to do before Sk.initialize is called, the constructor is called right away, and Initialize is called right after Sk.initialize, or at the start of the next frame before the next main Step callback if SK is already initialized. https://stereokit.net/Pages/StereoKit/SK/AddStepper.html
stepper_id
- The id to give to the stepper.
§Examples
use stereokit_rust::tools::screenshot::{ScreenshotViewer, SHOW_SCREENSHOT_WINDOW};
sk.send_event(StepperAction::add_default::<ScreenshotViewer>("ScreenshotViewer_ID"));
test_steps!( // !!!! Get a proper main loop !!!!
if iter < number_of_steps + 2 {
assert_eq!(sk.get_steppers_count(), 1);
} else if iter == number_of_steps + 2 {
/// We sk.quit() at 4 and at 5 the stepper has been removed.
assert_eq!(sk.get_steppers_count(), 0);
} else {
panic!("there is not iter 6 !!!");
}
);
Sourcepub fn add<T: IStepper + Send + 'static>(
stepper_id: impl AsRef<str>,
stepper: T,
) -> Self
pub fn add<T: IStepper + Send + 'static>( stepper_id: impl AsRef<str>, stepper: T, ) -> Self
This instantiates and registers an instance of the IStepper type provided as the generic parameter. SK will hold onto it, Initialize it, Step it every frame, and call Shutdown when the application ends. This is generally safe to do before Sk.initialize is called, the constructor is called right away, and Initialize is called right after Sk.initialize, or at the start of the next frame before the next main Step callback if SK is already initialized. https://stereokit.net/Pages/StereoKit/SK/AddStepper.html
stepper_id
- The id of the stepper.stepper
- The stepper to add.
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::named_colors,
tools::title::Title, };
use std::any::TypeId; // we need this to remove all the steppers of a given type.
let mut title = Title::new("Stepper 1", Some(named_colors::GREEN), None, None);
title.transform = Matrix::t_r([0.0, 0.0, -1.0], [0.0, 135.0, 0.0]);
sk.send_event(StepperAction::add("Title_green_ID", title.clone()));
test_steps!( // !!!! Get a proper main loop !!!!
if iter < number_of_steps + 2 {
assert_eq!(sk.get_steppers_count(), 1);
} else if iter == number_of_steps + 2 {
/// We sk.quit() at 4 and at 5 the stepper has been removed.
assert_eq!(sk.get_steppers_count(), 0);
} else {
panic!("there is not iter 6 !!!");
}
);
Sourcepub fn remove_all(type_id: TypeId) -> Self
pub fn remove_all(type_id: TypeId) -> Self
This removes all IStepper instances that are assignable to the generic type specified. This will call the IStepper’s Shutdown method on each removed instance before returning. https://stereokit.net/Pages/StereoKit/SK/RemoveStepper.html
type_id
- The type of the steppers to remove.
§Examples
use stereokit_rust::tools::{title::Title, screenshot::ScreenshotViewer};
sk.send_event(StepperAction::add_default::<ScreenshotViewer>("ScreenshotViewer_ID"));
sk.send_event(StepperAction::add_default::<Title>("Title_white_ID1"));
sk.send_event(StepperAction::add_default::<Title>("Title_white_ID2"));
test_steps!( // !!!! Get a proper main loop !!!!
if iter == number_of_steps {
assert_eq!(sk.get_steppers_count(), 3);
sk.send_event(StepperAction::remove_all(std::any::TypeId::of::<Title>()));
} else if iter == number_of_steps + 1 {
assert_eq!(sk.get_steppers_count(), 1);
}
);
Sourcepub fn remove(stepper_id: impl AsRef<str>) -> Self
pub fn remove(stepper_id: impl AsRef<str>) -> Self
This removes one or all IStepper instances that are assignable to the generic type specified. This will call the IStepper’s Shutdown method on each removed instance before returning. https://stereokit.net/Pages/StereoKit/SK/RemoveStepper.html
stepper_id
- The id of the stepper to remove.
§Examples
use stereokit_rust::tools::{title::Title, screenshot::ScreenshotViewer};
sk.send_event(StepperAction::add_default::<ScreenshotViewer>("ScreenshotViewer_ID"));
sk.send_event(StepperAction::add_default::<Title>("Title_white_ID1"));
sk.send_event(StepperAction::add_default::<Title>("Title_white_ID2"));
test_steps!( // !!!! Get a proper main loop !!!!
if iter == number_of_steps {
assert_eq!(sk.get_steppers_count(), 3);
sk.send_event(StepperAction::remove("Title_white_ID1"));
} else if iter == number_of_steps + 1 {
assert_eq!(sk.get_steppers_count(), 2);
}
);
Sourcepub fn quit(stepper_id: impl AsRef<str>, reason: impl AsRef<str>) -> Self
pub fn quit(stepper_id: impl AsRef<str>, reason: impl AsRef<str>) -> Self
Quit the app, https://stereokit.net/Pages/StereoKit/SK/Quit.html
stepper_id
- The id of the stepper that ask to quit.reason
- The reason why the stepper ask to quit.
see also Sk::quit
§Examples
use stereokit_rust::tools::screenshot::{ScreenshotViewer, SHOW_SCREENSHOT_WINDOW};
sk.send_event(StepperAction::add_default::<ScreenshotViewer>("ScreenshotViewer_ID"));
test_steps!( // !!!! Get a proper main loop !!!!
if iter == number_of_steps {
// Same as Sk::quit()
sk.send_event(StepperAction::quit("ScreenshotViewer_ID", "test_quit"));
} else if iter >= number_of_steps + 1 {
/// We sk.quit() at 4 and at 5 the stepper has been removed.
assert_eq!(sk.get_steppers_count(), 0);
} else {
assert_eq!(sk.get_steppers_count(), 1);
}
);
Sourcepub fn event<S: AsRef<str>>(stepper_id: S, key: S, value: S) -> Self
pub fn event<S: AsRef<str>>(stepper_id: S, key: S, value: S) -> Self
Event sent by a stepper for those who need it. Key -> Value are strings. https://stereokit.net/Pages/StereoKit/SK/SendEvent.html
stepper_id
- The id of the stepper that send the event or is the target of the event. This is useful for filter the event.key
- The key of the event.value
- The value of the event.
§Examples
use stereokit_rust::tools::screenshot::{ScreenshotViewer, SHOW_SCREENSHOT_WINDOW};
sk.send_event(StepperAction::add_default::<ScreenshotViewer>("ScreenshotViewer_ID"));
sk.send_event(StepperAction::event("main thread", SHOW_SCREENSHOT_WINDOW, "true"));
test_steps!( // !!!! Get a proper main loop !!!!
if iter < number_of_steps + 2 {
assert_eq!(sk.get_steppers_count(), 1);
} else if iter == number_of_steps + 2 {
/// We sk.quit() at 4 and at 5 the stepper has been removed.
assert_eq!(sk.get_steppers_count(), 0);
} else {
panic!("there is not iter 6 !!!");
}
);
Trait Implementations§
Source§impl ApplicationHandler<StepperAction> for SkClosures<'_>
impl ApplicationHandler<StepperAction> for SkClosures<'_>
Source§fn user_event(
&mut self,
_event_loop: &ActiveEventLoop,
user_event: StepperAction,
)
fn user_event( &mut self, _event_loop: &ActiveEventLoop, user_event: StepperAction, )
EventLoopProxy::send_event
.Source§fn resumed(&mut self, _event_loop: &ActiveEventLoop)
fn resumed(&mut self, _event_loop: &ActiveEventLoop)
Source§fn window_event(
&mut self,
event_loop: &ActiveEventLoop,
window_id: WindowId,
event: WindowEvent,
)
fn window_event( &mut self, event_loop: &ActiveEventLoop, window_id: WindowId, event: WindowEvent, )
Source§fn about_to_wait(&mut self, event_loop: &ActiveEventLoop)
fn about_to_wait(&mut self, event_loop: &ActiveEventLoop)
Source§fn suspended(&mut self, _event_loop: &ActiveEventLoop)
fn suspended(&mut self, _event_loop: &ActiveEventLoop)
Source§fn exiting(&mut self, _event_loop: &ActiveEventLoop)
fn exiting(&mut self, _event_loop: &ActiveEventLoop)
Source§fn memory_warning(&mut self, _event_loop: &ActiveEventLoop)
fn memory_warning(&mut self, _event_loop: &ActiveEventLoop)
Source§fn new_events(&mut self, event_loop: &ActiveEventLoop, cause: StartCause)
fn new_events(&mut self, event_loop: &ActiveEventLoop, cause: StartCause)
Source§fn device_event(
&mut self,
event_loop: &ActiveEventLoop,
device_id: DeviceId,
event: DeviceEvent,
)
fn device_event( &mut self, event_loop: &ActiveEventLoop, device_id: DeviceId, event: DeviceEvent, )
Auto Trait Implementations§
impl Freeze for StepperAction
impl !RefUnwindSafe for StepperAction
impl Send for StepperAction
impl !Sync for StepperAction
impl Unpin for StepperAction
impl !UnwindSafe for StepperAction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.