Enum StepperAction

Source
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:

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);
   }
);
screenshot

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

Source

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 !!!");
    }
);
Source

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 !!!");
    }
);
Source

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);
    }
);
Source

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);
    }
);
Source

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);
    }
);
Source

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<'_>

Source§

fn user_event( &mut self, _event_loop: &ActiveEventLoop, user_event: StepperAction, )

Emitted when an event is sent from EventLoopProxy::send_event.
Source§

fn resumed(&mut self, _event_loop: &ActiveEventLoop)

Emitted when the application has been resumed. Read more
Source§

fn window_event( &mut self, event_loop: &ActiveEventLoop, window_id: WindowId, event: WindowEvent, )

Emitted when the OS sends an event to a winit window.
Source§

fn about_to_wait(&mut self, event_loop: &ActiveEventLoop)

Emitted when the event loop is about to block and wait for new events. Read more
Source§

fn suspended(&mut self, _event_loop: &ActiveEventLoop)

Emitted when the application has been suspended. Read more
Source§

fn exiting(&mut self, _event_loop: &ActiveEventLoop)

Emitted when the event loop is being shut down. Read more
Source§

fn memory_warning(&mut self, _event_loop: &ActiveEventLoop)

Emitted when the application has received a memory warning. Read more
Source§

fn new_events(&mut self, event_loop: &ActiveEventLoop, cause: StartCause)

Emitted when new events arrive from the OS to be processed. Read more
Source§

fn device_event( &mut self, event_loop: &ActiveEventLoop, device_id: DeviceId, event: DeviceEvent, )

Emitted when the OS sends an event to a device.
Source§

impl Debug for StepperAction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more