Steppers

Struct Steppers 

Source
pub struct Steppers { /* private fields */ }
Expand description

Steppers manager. This is used internally by StereoKit, but you can use it to prepare your next scene managers. Non canonical. https://stereokit.net/Pages/StereoKit.Framework/IStepper.html

§Example

use stereokit_rust::{maths::{Vec3, Matrix}, util::named_colors, framework::Steppers,
    tools::{title::Title, screenshot::{ScreenshotViewer, SHOW_SCREENSHOT_WINDOW}}, };

let mut steppers = Steppers::new(sk.get_sk_info_clone());

let mut title = Title::new("Steppers", Some(named_colors::BLUE), None, None);
title.transform = Matrix::t_r([-0.5, 0.5, -1.5], [0.0, 155.0, 0.0]);
steppers.send_event(StepperAction::add("Title_blue_ID1", title.clone()));

title.transform = Matrix::t_r([-0.5, -0.5, -1.5], [0.0, 245.0, 0.0]);
// We may use the same ID for different steppers
steppers.send_event(StepperAction::add("Title_blue_ID2", title.clone()));
sk      .send_event(StepperAction::add("Title_blue_ID2", title.clone()));

steppers.send_event(StepperAction::add_default::<ScreenshotViewer>("ScreenshotViewer_ID"));
steppers.send_event(StepperAction::event("main thread".into(), SHOW_SCREENSHOT_WINDOW, "true"));

filename_scr = "screenshots/steppers.jpeg";
number_of_steps = 4;
test_screenshot!( // !!!! Get a proper main loop !!!!
    if iter == 0 {
        assert_eq!(steppers.get_count(), 0);
        assert_eq!(sk.get_steppers_count(), 1);
        sk.swap_steppers(&mut steppers);
    } else if iter == 1 {
        assert_eq!(steppers.get_count(), 1);
        assert_eq!(sk.get_steppers_count(), 3);
        sk.swap_steppers(&mut steppers);
    } else if iter == 2 {
        assert_eq!(steppers.get_count(), 3);
        assert_eq!(sk.get_steppers_count(), 1);
        sk.swap_steppers(&mut steppers);
    } else if iter == number_of_steps + 1 {
        assert_eq!(sk.get_steppers_count(), 3);
        assert_eq!(steppers.get_count(), 1);
        steppers.shutdown();
    } else if iter == number_of_steps + 2 {
        /// all the steppers should be removed from Sk and steppers
        assert_eq!(sk.get_steppers_count(), 0);
        assert_eq!(steppers.get_count(), 0);
    }
);
screenshot

Implementations§

Source§

impl Steppers

Source

pub fn new(sk_info: Rc<RefCell<SkInfo>>) -> Self

The only way to create a Steppers manager. You don’t need it unless you want to swap different steppers.

  • sk_info - A SkInfo Rc clone of the running Sk instance.

Sk Create the default one when it is initialized.

§Example
use stereokit_rust::{maths::{Vec3, Matrix}, framework::Steppers};

let mut steppers = Steppers::new(sk.get_sk_info_clone());

test_steps!( // !!!! Get a proper main loop !!!!
    assert_eq!(steppers.get_count(), 0);
);
Source

pub fn send_event(&mut self, action: StepperAction)

Push an action to consumme befor next frame

  • action - The action to push.

see also Sk::send_event winit::event_loop::EventLoopProxy::send_event

§Example
use stereokit_rust::{maths::{Vec3, Matrix}, util::named_colors, framework::Steppers,
    tools::{title::Title, screenshot::{ScreenshotViewer, SHOW_SCREENSHOT_WINDOW}}, };

let mut steppers = Steppers::new(sk.get_sk_info_clone());

let mut title = Title::new("Steppers", Some(named_colors::BLUE), None, None);
steppers.send_event(StepperAction::add("Title_blue_ID1", title.clone()));
steppers.send_event(StepperAction::add("Title_blue_ID2", title.clone()));
steppers.send_event(StepperAction::add_default::<ScreenshotViewer>("ScreenshotViewer_ID"));
steppers.send_event(StepperAction::event("main thread".into(), SHOW_SCREENSHOT_WINDOW, "true"));
steppers.send_event(StepperAction::remove("Title_blue_ID2"));

sk.swap_steppers(&mut steppers);
test_steps!( // !!!! Get a proper main loop !!!!
    if iter < number_of_steps + 2 {
        assert_eq!(steppers.get_count(), 0);
        assert_eq!(sk.get_steppers_count(), 2);
    }
);
Source

pub fn get_stepper_handlers(&self) -> &[StepperHandler]

An enumerable list of all currently active ISteppers registered with StereoKit. This does not include Steppers that have been added, but are not yet initialized. Stepper initialization happens at the beginning of the frame, before the app’s Step.

see also Sk::get_steppers to get the default running Steppers.

§Example
use stereokit_rust::{maths::{Vec3, Matrix}, util::named_colors,
    framework::{Steppers, StepperState, StepperHandler},
    tools::{title::Title, screenshot::{ScreenshotViewer, SHOW_SCREENSHOT_WINDOW}}, };
use std::any::TypeId;

let mut steppers = Steppers::new(sk.get_sk_info_clone());

let mut title = Title::new("Steppers", Some(named_colors::BLUE), None, None);
steppers.send_event(StepperAction::add("Title_blue_ID1", title.clone()));
steppers.send_event(StepperAction::add_default::<ScreenshotViewer>("ScreenshotViewer_ID"));

test_steps!( // !!!! Get a proper main loop !!!!
    if iter == 0 {
        assert_eq!(steppers.get_stepper_handlers().len(), 0);
        assert_eq!(sk.get_steppers_count(), 0);
        sk.swap_steppers(&mut steppers);
    } else if iter == 1 {
        assert_eq!(steppers.get_stepper_handlers().len(), 0);
        assert_eq!(sk.get_steppers_count(), 2);
        sk.swap_steppers(&mut steppers);
    } else if iter == 3 {
        let steppers_handlers = steppers.get_stepper_handlers();
        assert_eq!(steppers_handlers.len(), 2);
        assert_eq!(steppers_handlers[0].get_id(), "Title_blue_ID1");
        assert_eq!(steppers_handlers[0].get_type_id(), TypeId::of::<Title>());
        assert_eq!(steppers_handlers[0].get_state(), StepperState::Running);

        assert_eq!(steppers_handlers[1].get_id(), "ScreenshotViewer_ID");
        assert_eq!(steppers_handlers[1].get_type_id(), TypeId::of::<ScreenshotViewer>());
        assert_eq!(steppers_handlers[1].get_state(), StepperState::Running);

        assert_eq!(sk.get_steppers_count(), 0);
    }
);
Source

pub fn shutdown(&mut self)

Run the shutdown code for all running steppers. On default Sk Steppers, this is called when pushing StepperAction::Quit( origin , reason) but if you have other inactive Steppers you may want to call this function to shutdown all of them. Do not confuse with Sk::shutdown that you must call when exiting the program.

see also Sk::quit

§Example
use stereokit_rust::{maths::{Vec3, Matrix}, util::named_colors,
    framework::{Steppers, StepperState, StepperHandler},
    tools::{title::Title, screenshot::{ScreenshotViewer, SHOW_SCREENSHOT_WINDOW}}, };
use std::any::TypeId;

let mut steppers = Steppers::new(sk.get_sk_info_clone());

let mut title = Title::new("Steppers", Some(named_colors::BLUE), None, None);
steppers.send_event(StepperAction::add("Title_blue_ID1", title.clone()));
steppers.send_event(StepperAction::add_default::<ScreenshotViewer>("ScreenshotViewer_ID"));

sk.swap_steppers(&mut steppers);

test_steps!( // !!!! Get a proper main loop !!!!
    if iter == 0 {
        assert_eq!(steppers.get_count(), 0);
        assert_eq!(sk.get_steppers_count(), 2);
        sk.swap_steppers(&mut steppers);
    } else if iter == 1 {
        assert_eq!(steppers.get_count(), 2);
        assert_eq!(sk.get_steppers_count(), 0);
        steppers.shutdown();
        sk.swap_steppers(&mut steppers);
    } else {
        assert_eq!(steppers.get_count(), 0);
        assert_eq!(sk.get_steppers_count(), 0);
    }
);
Source

pub fn get_count(&self) -> usize

The count of all ISteppers registered by this Steppers. This does not include Steppers that have been added, but are not yet initialized. Stepper initialization happens at the beginning of the frame, before the app’s Step.

see also Sk::get_steppers_count

§Example
use stereokit_rust::{maths::{Vec3, Matrix}, util::named_colors,
    framework::{Steppers, StepperState, StepperHandler},
    tools::{title::Title, screenshot::{ScreenshotViewer, SHOW_SCREENSHOT_WINDOW}}, };
use std::any::TypeId;

let mut steppers = Steppers::new(sk.get_sk_info_clone());

let mut title = Title::new("Steppers", Some(named_colors::BLUE), None, None);
steppers.send_event(StepperAction::add("Title_blue_ID1", title.clone()));
steppers.send_event(StepperAction::add_default::<ScreenshotViewer>("ScreenshotViewer_ID"));

test_steps!( // !!!! Get a proper main loop !!!!
    assert_eq!(steppers.get_stepper_handlers().len(),  steppers.get_count());
    if iter == 0 {
        assert_eq!(sk.get_steppers_count(), 0);
        sk.swap_steppers(&mut steppers);
    } else if iter == 1 {
        assert_eq!(sk.get_steppers_count(), 2);
        sk.swap_steppers(&mut steppers);
    } else if iter == 3 {
        assert_eq!(sk.get_steppers_count(), 0);
    }
);

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