Derive Macro IStepper

Source
#[derive(IStepper)]
Expand description

Derive the IStepper trait for a struct which must implement:

  • Fields:
    • id: StepperId,
    • sk_info: Option<Rc<RefCell<SkInfo>>>,
    • Optional when the stepper should initialize on more than one step : initialize_completed: bool
    • Optional when you want to implement an active/inactive flag: enabled: bool
    • Optional when the stepper should shutdown some stuffs : shutdown_completed: bool
  • Functions:
    • IStepper::initialize calls fn start(&mut self) -> bool where you can abort the initialization by returning false:
    • Optional if field initialize_completed is present IStepper::initialize_done calls fn start_completed(&mut self) -> bool where you can tell the initialization is done:
    • IStepper::step calls fn check_event(&mut self, _key: &str, _value: &str) where you can check the event report:
    • IStepper::step calls fn draw(&mut self, token: &MainThreadToken) after check_event where you can draw your UI:
    • Optional if field shutdown_completed is present IStepper::shutdown and IStepper::shutdown_done call fn close(&mut self, triggering:bool) -> bool where you can close your resources.

§Examples

use stereokit_rust::{prelude::*, material::Material, maths::{Matrix, Quat, Vec3},
                     mesh::Mesh, util::{named_colors, Time}};
#[derive(IStepper)]
pub struct MyStepper {
    id: StepperId,
    sk_info: Option<Rc<RefCell<SkInfo>>>,

    transform: Matrix,
    round_cube: Mesh,
    material: Material,
}
impl Default for MyStepper {
    fn default() -> Self {
        Self {
            id: "MyStepper".to_string(),
            sk_info: None,

            transform: Matrix::IDENTITY,
            round_cube: Mesh::generate_rounded_cube(Vec3::ONE / 5.0, 0.2, Some(16)),
            material: Material::pbr().copy(),
        }
    }
}
impl MyStepper {
    fn start(&mut self) -> bool {
        self.transform = Matrix::r([0.0, 10.0 * Time::get_stepf(), 0.0]);
        self.material.color_tint(named_colors::BLUE);
        true
    }
    fn check_event(&mut self, _id: &StepperId, _key: &str, _value: &str) {}
    fn draw(&mut self, token: &MainThreadToken) {
        self.round_cube.draw(token, &self.material, self.transform, None, None);
    }
}

see also the example CStepper in the examples/demos/c_stepper.rs