Skip to main content

DeviceProfile

Struct DeviceProfile 

Source
pub struct DeviceProfile {
    pub id: String,
    pub name: String,
    pub platform: TargetPlatform,
    pub screen: Size,
    pub pixel_ratio: f32,
    pub screen_radius: f32,
    pub cutout: Cutout,
    pub portrait: DeviceInsets,
    pub landscape: DeviceInsets,
    pub frame: DeviceFrame,
}
Expand description

A device a desktop window can stand in for: its screen, the areas its system keeps, its keyboard, its platform and its outline.

Everything is in logical pixels and given for the device held upright (portrait); Orientation::Landscape is the device turned a quarter turn counter-clockwise, so that what was at the top of the screen — the cutout — is on the left.

Fields§

§id: String

What frus run -d and frus devices call it: lowercase, no spaces ("iphone-15").

§name: String

The name shown to people ("iPhone 15").

§platform: TargetPlatform

The platform whose conventions the application follows on it.

§screen: Size

The screen held upright, in logical pixels.

§pixel_ratio: f32

Physical pixels per logical pixel.

§screen_radius: f32

The radius of the screen’s own rounded corners; 0 for a square screen.

§cutout: Cutout

The part of the screen taken by the camera, held upright.

§portrait: DeviceInsets

The system’s areas and the keyboard, held upright.

§landscape: DeviceInsets

The system’s areas and the keyboard, turned on its side.

§frame: DeviceFrame

The outline drawn around the screen.

Implementations§

Source§

impl DeviceProfile

Source

pub fn screen_size(&self, orientation: Orientation) -> Size

The screen in orientation, in logical pixels.

Source

pub fn physical_size(&self, orientation: Orientation) -> Size

The screen in orientation, in physical pixels.

Source

pub fn insets_in(&self, orientation: Orientation) -> DeviceInsets

The system’s areas and the keyboard in orientation.

Source

pub fn window_insets( &self, orientation: Orientation, keyboard: bool, ) -> WindowInsets

The insets an application on this device is told about in orientation, with the soft keyboard up or down — split as a real device’s shell splits them.

Source

pub fn cutout_rect(&self, orientation: Orientation) -> Option<Rect>

Where the cutout is on the screen in orientation, in logical pixels from the screen’s top-left corner; None for a whole screen.

Turned on its side, the cutout is on the left edge, centred top to bottom.

Source

pub fn outer_size(&self, orientation: Orientation) -> Size

The whole device — screen and body — in orientation, in logical pixels.

Source

pub fn screen_rect(&self, orientation: Orientation) -> Rect

Where the screen sits inside outer_size in orientation.

Turned counter-clockwise, the top bezel is on the left and the left bezel at the bottom.

Source

pub fn find<'a>( profiles: &'a [DeviceProfile], wanted: &str, ) -> Option<&'a DeviceProfile>

The profile among profiles whose id or name is wanted, ignoring case.

Source

pub fn parse(spec: &str) -> Result<DeviceProfile, String>

A device a developer describes, as key=value pairs separated by ; (milestone 727). The keys are those of a project’s [[package.metadata.frus.devices]], which frus run hands over this way; a list is written a,b,c.

Required: id, platform (ios or android), width, height (logical, upright) and ratio. The rest has a default: name (the id), corner-radius (0), safe-area (top,right,bottom,left, none), landscape-safe-area (the upright one turned with the device), keyboard (two fifths of the height), landscape-keyboard (three fifths of the width), cutout (none, notch, island or hole) with cutout-size (width,height) and cutout-top. The outline is a plain body around the screen.

An unknown key is an error rather than ignored: a misspelt one would otherwise leave its default in place without a word.

Source

pub fn builtin() -> Vec<DeviceProfile>

The devices frus knows without being told: phones and a tablet for iOS, and a phone for Android.

The iOS screens, densities, cutouts and safe areas are the devices’ published figures; the Android phone’s are what Android reports for its shape, measured. The keyboard heights are typical ones — they change with the keyboard, the language and the suggestions bar — and the outlines are frus’s own drawing, not a picture of any device.

Trait Implementations§

Source§

impl Clone for DeviceProfile

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DeviceProfile

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for DeviceProfile

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DeviceProfile

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.