pub struct Device {
pub mobile_device: bool,
pub mobile_forced: bool,
pub orientation: Orientation,
pub orientation_forced: Option<Orientation>,
pub screen_size: Vec2,
}Expand description
Tracks device characteristics (mobile detection, orientation and screen size) used to drive responsive layout decisions.
Fields§
§mobile_device: booltrue when the running platform is detected as a mobile device.
mobile_forced: boolUser/debug override forcing mobile behaviour regardless of detection.
orientation: OrientationOrientation derived from the most recently observed screen size.
orientation_forced: Option<Orientation>Override that pins the reported orientation when set.
screen_size: Vec2Most recently observed screen size, in points.
Implementations§
Source§impl Device
impl Device
Sourcepub fn set_screen_size(&mut self, rect: &Rect)
pub fn set_screen_size(&mut self, rect: &Rect)
Record the current screen size from rect and re-derive the orientation,
classifying narrow or sub-540px-wide areas as portrait.
Sourcepub fn orientation(&self) -> Orientation
pub fn orientation(&self) -> Orientation
Returns the effective orientation, preferring a forced override when set and otherwise the orientation derived from the screen size.
Sourcepub fn is_mobile(&self) -> bool
pub fn is_mobile(&self) -> bool
Returns true if the device is detected as mobile or has been forced
into mobile mode.
Sourcepub fn toggle_portrait(&mut self)
pub fn toggle_portrait(&mut self)
Toggle a forced portrait orientation: enables it when no override is set, otherwise clears the override and reverts to auto-detection.
Sourcepub fn toggle_mobile(&mut self)
pub fn toggle_mobile(&mut self)
Toggle the forced-mobile override on or off.
Sourcepub fn is_single_pane(&self) -> bool
pub fn is_single_pane(&self) -> bool
Returns true when the UI should collapse to a single pane, such as on
mobile (real or forced), in portrait orientation, or inside a Chrome
extension popup.
Sourcepub fn is_desktop(&self) -> bool
pub fn is_desktop(&self) -> bool
Returns true when the device should use a multi-pane desktop layout
(i.e. the inverse of Device::is_single_pane).
Sourcepub fn force_orientation(&mut self, orientation: Option<Orientation>)
pub fn force_orientation(&mut self, orientation: Option<Orientation>)
Force the reported orientation to a specific value, or pass None to
resume using the orientation derived from the screen size.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Device
impl RefUnwindSafe for Device
impl Send for Device
impl Sync for Device
impl Unpin for Device
impl UnsafeUnpin for Device
impl UnwindSafe for Device
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.