SkInfo

Struct SkInfo 

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

Non canonical structure whose purpose is to expose infos far from Sk

see also: Sk::get_sk_info_clone

§Examples

use stereokit_rust::sk::{Sk, SkSettings, AppMode, SkInfo};
use stereokit_rust::{system::LogLevel, ui::Ui, maths::Pose};

let sk_info = Some(sk.get_sk_info_clone());
let settings = SkInfo::settings_from(&sk_info);

if cfg!(feature = "test-xr-mode") {
    assert_eq!(settings.mode, AppMode::XR);
} else {
    assert_eq!(settings.mode, AppMode::Offscreen);
}

let system = SkInfo::system_from(&sk_info);
assert_eq!(system.get_display_width(), 0);

#[cfg(feature = "event-loop")]
{
    use stereokit_rust::tools::screenshot::{ScreenshotViewer, SHOW_SCREENSHOT_WINDOW};
    // send event
    SkInfo::send_event(&sk_info,
                   StepperAction::add_default::<ScreenshotViewer>("SCR_ID1"));
    
    // get event_loop_proxy clone to use in other threads
    let event_loop_proxy = SkInfo::event_loop_proxy_from(&sk_info);

    // get a closure, ready to send an event with a given value
    let show_screenshot = SkInfo::get_message_closure(sk_info,
                              "SCR_ID1", SHOW_SCREENSHOT_WINDOW);
    let mut window_pose = Pose::IDENTITY;
    test_steps!(// !!!! Get a proper main loop !!!!
        Ui::window_begin("Default Font", &mut window_pose, None, None, None);
        if Ui::button("Show screenshot", None) {
            show_screenshot("true".into())
        }
        Ui::window_end();
    );
}

Implementations§

Source§

impl SkInfo

Source

pub fn get_settings(&self) -> SkSettings

This is a copy of the settings that StereoKit was initialized with, so you can refer back to them a little easier. Some of these values will be different than provided, as StereoKit will resolve some default values based on the platform capabilities or internal preference. These are read only, and keep in mind that some settings are only requests! Check Sk::get_system and other properties for the current state of StereoKit. SkInfo::settings_from is more easy to use. https://stereokit.net/Pages/StereoKit/SK/Settings.html

Source

pub fn get_system(&self) -> SystemInfo

This structure contains information about the current system and its capabilities. There’s a lot of different MR devices, so it’s nice to have code for systems with particular characteristics! SkInfo::system_from is more easy to use. https://stereokit.net/Pages/StereoKit/SK/System.html

Source

pub fn get_event_loop_proxy(&self) -> Option<EventLoopProxy<StepperAction>>

Get an event_loop_proxy clone to send events. SkInfo::event_loop_proxy_from is more easy to use.

Source

pub fn settings_from(sk_info: &Option<Rc<RefCell<SkInfo>>>) -> SkSettings

This is a copy of the settings that StereoKit was initialized with, so you can refer back to them a little easier. Some of these values will be different than provided, as StereoKit will resolve some default values based on the platform capabilities or internal preference. These are read only, and keep in mind that some settings are only requests! Check SK.System and other properties for the current state of StereoKit. https://stereokit.net/Pages/StereoKit/SK/Settings.html

  • sk_info - The SkInfo smart pointer to get the settings from

see also Sk::get_settings

Source

pub fn system_from(sk_info: &Option<Rc<RefCell<SkInfo>>>) -> SystemInfo

This structure contains information about the current system and its capabilities. There’s a lot of different MR devices, so it’s nice to have code for systems with particular characteristics! https://stereokit.net/Pages/StereoKit/SK/System.html

  • sk_info - The SkInfo smart pointer to get the SystemInfo from.

see also Sk::get_system

Source

pub fn event_loop_proxy_from( sk_info: &Option<Rc<RefCell<SkInfo>>>, ) -> Option<EventLoopProxy<StepperAction>>

Get an event_loop_proxy clone to send events

  • sk_info - The SkInfo smart pointer to get the event_loop_proxy from.

see also Sk::get_sk_info_clone

§Examples
use stereokit_rust::sk::{Sk, SkSettings, AppMode, SkInfo, QuitReason};
use stereokit_rust::framework::SkClosures;
use std::thread;
use std::time::Duration;

let sk_info = Some(sk.get_sk_info_clone());
let event_loop_proxy = SkInfo::event_loop_proxy_from(&sk_info);

// Spawn a new thread to send an event after a delay
let handle = thread::spawn(move || {
    thread::sleep(Duration::from_millis(100));
    if let Some(proxy) = event_loop_proxy {
        proxy.send_event(StepperAction::quit("thread", "I'm done!")).unwrap();
    }
});

SkClosures::new(sk, |sk, token|  {
    // Only the thread can stop this test
    // model.draw(token, Matrix::IDENTITY, None, None);
})
.shutdown(|sk| {
    assert_eq!(sk.get_quit_reason(), QuitReason::User);
})
.run(event_loop);

// If we are here the thread has finished
handle.join().unwrap();
Source

pub fn send_event(sk_info: &Option<Rc<RefCell<SkInfo>>>, message: StepperAction)

Send a StepperAction to the event loop

  • sk_info - The SkInfo smart pointer to get the event loop proxy from
  • message - The StepperAction to send to the event loop

see also SkInfo::get_message_closure

Source

pub fn get_message_closure( sk_info: Option<Rc<RefCell<SkInfo>>>, id: impl AsRef<str>, key: &str, ) -> impl Fn(String)

Get a closure to send a message to the event loop from a given ID for a given key. This is useful for HandMenuRadial for example.

see also SkInfo::send_event see examples/demos/hand_menu_radial1.rs

Trait Implementations§

Source§

impl Debug for SkInfo

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for SkInfo

§

impl RefUnwindSafe for SkInfo

§

impl !Send for SkInfo

§

impl !Sync for SkInfo

§

impl Unpin for SkInfo

§

impl UnwindSafe for SkInfo

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