Size

external class Size(source)

A size represented either in physical or in logical pixels.

This type is basically a union type of {@linkcode LogicalSize} and {@linkcode PhysicalSize} but comes in handy when using tauri::Size in Rust as an argument to a command, as this class automatically serializes into a valid format so it can be deserialized correctly into tauri::Size

So instead of

import { invoke } from '@tauri-apps/api/core';
import { LogicalSize, PhysicalSize } from '@tauri-apps/api/dpi';

const size: LogicalSize | PhysicalSize = someFunction(); // where someFunction returns either LogicalSize or PhysicalSize
const validSize = size instanceof LogicalSize
? { Logical: { width: size.width, height: size.height } }
: { Physical: { width: size.width, height: size.height } }
await invoke("do_something_with_size", { size: validSize });

You can just use {@linkcode Size}

import { invoke } from '@tauri-apps/api/core';
import { LogicalSize, PhysicalSize, Size } from '@tauri-apps/api/dpi';

const size: LogicalSize | PhysicalSize = someFunction(); // where someFunction returns either LogicalSize or PhysicalSize
const validSize = new Size(size);
await invoke("do_something_with_size", { size: validSize });

Since

2.1.0

Constructors

Link copied to clipboard
constructor(size: LogicalSize)
constructor(size: PhysicalSize)

Properties

Link copied to clipboard
var size: Any

Functions

Link copied to clipboard
Link copied to clipboard
fun toLogical(scaleFactor: Double): LogicalSize
Link copied to clipboard
fun toPhysical(scaleFactor: Double): PhysicalSize