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: StringWhat frus run -d and frus devices call it: lowercase, no spaces
("iphone-15").
name: StringThe name shown to people ("iPhone 15").
platform: TargetPlatformThe platform whose conventions the application follows on it.
screen: SizeThe screen held upright, in logical pixels.
pixel_ratio: f32Physical pixels per logical pixel.
screen_radius: f32The radius of the screen’s own rounded corners; 0 for a square screen.
cutout: CutoutThe part of the screen taken by the camera, held upright.
portrait: DeviceInsetsThe system’s areas and the keyboard, held upright.
landscape: DeviceInsetsThe system’s areas and the keyboard, turned on its side.
frame: DeviceFrameThe outline drawn around the screen.
Implementations§
Source§impl DeviceProfile
impl DeviceProfile
Sourcepub fn screen_size(&self, orientation: Orientation) -> Size
pub fn screen_size(&self, orientation: Orientation) -> Size
The screen in orientation, in logical pixels.
Sourcepub fn physical_size(&self, orientation: Orientation) -> Size
pub fn physical_size(&self, orientation: Orientation) -> Size
The screen in orientation, in physical pixels.
Sourcepub fn insets_in(&self, orientation: Orientation) -> DeviceInsets
pub fn insets_in(&self, orientation: Orientation) -> DeviceInsets
The system’s areas and the keyboard in orientation.
Sourcepub fn window_insets(
&self,
orientation: Orientation,
keyboard: bool,
) -> WindowInsets
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.
Sourcepub fn cutout_rect(&self, orientation: Orientation) -> Option<Rect>
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.
Sourcepub fn outer_size(&self, orientation: Orientation) -> Size
pub fn outer_size(&self, orientation: Orientation) -> Size
The whole device — screen and body — in orientation, in logical pixels.
Sourcepub fn screen_rect(&self, orientation: Orientation) -> Rect
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.
Sourcepub fn find<'a>(
profiles: &'a [DeviceProfile],
wanted: &str,
) -> Option<&'a DeviceProfile>
pub fn find<'a>( profiles: &'a [DeviceProfile], wanted: &str, ) -> Option<&'a DeviceProfile>
The profile among profiles whose id or name is wanted, ignoring case.
Sourcepub fn parse(spec: &str) -> Result<DeviceProfile, String>
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.
Sourcepub fn builtin() -> Vec<DeviceProfile>
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.