use super::*;
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct Gyroscope {
inner: Sensor,
}
impl FromVal for Gyroscope {
fn from_val(v: &Any) -> Self {
Gyroscope {
inner: Sensor::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for Gyroscope {
type Target = Sensor;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for Gyroscope {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for Gyroscope {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for Gyroscope {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<Gyroscope> for Any {
fn from(s: Gyroscope) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&Gyroscope> for Any {
fn from(s: &Gyroscope) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(Gyroscope);
impl Gyroscope {
pub fn x(&self) -> f64 {
self.inner.get("x").as_::<f64>()
}
}
impl Gyroscope {
pub fn y(&self) -> f64 {
self.inner.get("y").as_::<f64>()
}
}
impl Gyroscope {
pub fn z(&self) -> f64 {
self.inner.get("z").as_::<f64>()
}
}
impl Gyroscope {
pub fn new() -> Gyroscope {
Self {
inner: Any::global("Gyroscope").new(&[]).as_::<Sensor>(),
}
}
}
impl Gyroscope {
pub fn new_with_sensor_options(sensor_options: &GyroscopeSensorOptions) -> Gyroscope {
Self {
inner: Any::global("Gyroscope")
.new(&[sensor_options.into()])
.as_::<Sensor>(),
}
}
}