Skip to content
Tauri

dpi

Classes

LogicalPosition

A position represented in logical pixels.

Since

2.0.0

Constructors

new LogicalPosition()
new LogicalPosition(x, y): LogicalPosition
Parameters
ParameterType
xnumber
ynumber
Returns

LogicalPosition

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L208

new LogicalPosition()
new LogicalPosition(object): LogicalPosition
Parameters
ParameterType
objectobject
object.Logicalobject
object.Logical.xnumber
object.Logical.ynumber
Returns

LogicalPosition

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L209

new LogicalPosition()
new LogicalPosition(object): LogicalPosition
Parameters
ParameterType
objectobject
object.xnumber
object.ynumber
Returns

LogicalPosition

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L210

Properties

PropertyModifierTypeDefault valueDefined in
typereadonly"Logical"'Logical'Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L204
xpublicnumberundefinedSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L205
ypublicnumberundefinedSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L206

Methods

__TAURI_TO_IPC_KEY__()
__TAURI_TO_IPC_KEY__(): object
Returns

object

NameTypeDefined in
xnumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L252
ynumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L253

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L250

toJSON()
toJSON(): object
Returns

object

NameTypeDefined in
xnumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L252
ynumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L253

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L257

toPhysical()
toPhysical(scaleFactor): PhysicalPosition

Converts the logical position to a physical one.

Parameters
ParameterType
scaleFactornumber
Returns

PhysicalPosition

Example
import { LogicalPosition } from '@tauri-apps/api/dpi';
import { getCurrentWindow } from '@tauri-apps/api/window';
const appWindow = getCurrentWindow();
const factor = await appWindow.scaleFactor();
const position = new LogicalPosition(400, 500);
const physical = position.toPhysical(factor);
Since

2.0.0

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L246


LogicalSize

A size represented in logical pixels.

Since

2.0.0

Constructors

new LogicalSize()
new LogicalSize(width, height): LogicalSize
Parameters
ParameterType
widthnumber
heightnumber
Returns

LogicalSize

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L17

new LogicalSize()
new LogicalSize(object): LogicalSize
Parameters
ParameterType
objectobject
object.Logicalobject
object.Logical.heightnumber
object.Logical.widthnumber
Returns

LogicalSize

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L18

new LogicalSize()
new LogicalSize(object): LogicalSize
Parameters
ParameterType
objectobject
object.heightnumber
object.widthnumber
Returns

LogicalSize

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L19

Properties

PropertyModifierTypeDefault valueDefined in
heightpublicnumberundefinedSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L15
typereadonly"Logical"'Logical'Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L13
widthpublicnumberundefinedSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L14

Methods

__TAURI_TO_IPC_KEY__()
__TAURI_TO_IPC_KEY__(): object
Returns

object

NameTypeDefined in
heightnumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L62
widthnumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L61

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L59

toJSON()
toJSON(): object
Returns

object

NameTypeDefined in
heightnumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L62
widthnumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L61

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L66

toPhysical()
toPhysical(scaleFactor): PhysicalSize

Converts the logical size to a physical one.

Parameters
ParameterType
scaleFactornumber
Returns

PhysicalSize

Example
import { LogicalSize } from '@tauri-apps/api/dpi';
import { getCurrentWindow } from '@tauri-apps/api/window';
const appWindow = getCurrentWindow();
const factor = await appWindow.scaleFactor();
const size = new LogicalSize(400, 500);
const physical = size.toPhysical(factor);
Since

2.0.0

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L55


PhysicalPosition

A position represented in physical pixels.

Since

2.0.0

Constructors

new PhysicalPosition()
new PhysicalPosition(x, y): PhysicalPosition
Parameters
ParameterType
xnumber
ynumber
Returns

PhysicalPosition

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L273

new PhysicalPosition()
new PhysicalPosition(object): PhysicalPosition
Parameters
ParameterType
objectobject
object.Physicalobject
object.Physical.xnumber
object.Physical.ynumber
Returns

PhysicalPosition

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L274

new PhysicalPosition()
new PhysicalPosition(object): PhysicalPosition
Parameters
ParameterType
objectobject
object.xnumber
object.ynumber
Returns

PhysicalPosition

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L275

Properties

PropertyModifierTypeDefault valueDefined in
typereadonly"Physical"'Physical'Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L269
xpublicnumberundefinedSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L270
ypublicnumberundefinedSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L271

Methods

__TAURI_TO_IPC_KEY__()
__TAURI_TO_IPC_KEY__(): object
Returns

object

NameTypeDefined in
xnumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L317
ynumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L318

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L315

toJSON()
toJSON(): object
Returns

object

NameTypeDefined in
xnumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L317
ynumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L318

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L322

toLogical()
toLogical(scaleFactor): LogicalPosition

Converts the physical position to a logical one.

Parameters
ParameterType
scaleFactornumber
Returns

LogicalPosition

Example
import { PhysicalPosition } from '@tauri-apps/api/dpi';
import { getCurrentWindow } from '@tauri-apps/api/window';
const appWindow = getCurrentWindow();
const factor = await appWindow.scaleFactor();
const position = new PhysicalPosition(400, 500);
const physical = position.toLogical(factor);
Since

2.0.0

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L311


PhysicalSize

A size represented in physical pixels.

Since

2.0.0

Constructors

new PhysicalSize()
new PhysicalSize(width, height): PhysicalSize
Parameters
ParameterType
widthnumber
heightnumber
Returns

PhysicalSize

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L82

new PhysicalSize()
new PhysicalSize(object): PhysicalSize
Parameters
ParameterType
objectobject
object.Physicalobject
object.Physical.heightnumber
object.Physical.widthnumber
Returns

PhysicalSize

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L83

new PhysicalSize()
new PhysicalSize(object): PhysicalSize
Parameters
ParameterType
objectobject
object.heightnumber
object.widthnumber
Returns

PhysicalSize

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L84

Properties

PropertyModifierTypeDefault valueDefined in
heightpublicnumberundefinedSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L80
typereadonly"Physical"'Physical'Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L78
widthpublicnumberundefinedSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L79

Methods

__TAURI_TO_IPC_KEY__()
__TAURI_TO_IPC_KEY__(): object
Returns

object

NameTypeDefined in
heightnumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L123
widthnumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L122

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L120

toJSON()
toJSON(): object
Returns

object

NameTypeDefined in
heightnumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L123
widthnumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L122

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L127

toLogical()
toLogical(scaleFactor): LogicalSize

Converts the physical size to a logical one.

Parameters
ParameterType
scaleFactornumber
Returns

LogicalSize

Example
import { getCurrentWindow } from '@tauri-apps/api/window';
const appWindow = getCurrentWindow();
const factor = await appWindow.scaleFactor();
const size = await appWindow.innerSize(); // PhysicalSize
const logical = size.toLogical(factor);

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L116


Position

A position represented either in physical or in logical pixels.

This type is basically a union type of LogicalSize and PhysicalSize but comes in handy when using tauri::Position 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::Position

So instead of

import { invoke } from '@tauri-apps/api/core';
import { LogicalPosition, PhysicalPosition } from '@tauri-apps/api/dpi';
const position: LogicalPosition | PhysicalPosition = someFunction(); // where someFunction returns either LogicalPosition or PhysicalPosition
const validPosition = position instanceof LogicalPosition
? { Logical: { x: position.x, y: position.y } }
: { Physical: { x: position.x, y: position.y } }
await invoke("do_something_with_position", { position: validPosition });

You can just use Position

import { invoke } from '@tauri-apps/api/core';
import { LogicalPosition, PhysicalPosition, Position } from '@tauri-apps/api/dpi';
const position: LogicalPosition | PhysicalPosition = someFunction(); // where someFunction returns either LogicalPosition or PhysicalPosition
const validPosition = new Position(position);
await invoke("do_something_with_position", { position: validPosition });

Since

2.1.0

Constructors

new Position()
new Position(position): Position
Parameters
ParameterType
positionLogicalPosition | PhysicalPosition
Returns

Position

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L362

Properties

PropertyTypeDefined in
positionLogicalPosition | PhysicalPositionSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L360

Methods

__TAURI_TO_IPC_KEY__()
__TAURI_TO_IPC_KEY__(): object
Returns

object

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L378

toJSON()
toJSON(): object
Returns

object

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L387

toLogical()
toLogical(scaleFactor): LogicalPosition
Parameters
ParameterType
scaleFactornumber
Returns

LogicalPosition

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L366

toPhysical()
toPhysical(scaleFactor): PhysicalPosition
Parameters
ParameterType
scaleFactornumber
Returns

PhysicalPosition

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L372


Size

A size represented either in physical or in logical pixels.

This type is basically a union type of LogicalSize and 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 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

new Size()
new Size(size): Size
Parameters
ParameterType
sizeLogicalSize | PhysicalSize
Returns

Size

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L167

Properties

PropertyTypeDefined in
sizeLogicalSize | PhysicalSizeSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L165

Methods

__TAURI_TO_IPC_KEY__()
__TAURI_TO_IPC_KEY__(): object
Returns

object

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L183

toJSON()
toJSON(): object
Returns

object

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L192

toLogical()
toLogical(scaleFactor): LogicalSize
Parameters
ParameterType
scaleFactornumber
Returns

LogicalSize

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L171

toPhysical()
toPhysical(scaleFactor): PhysicalSize
Parameters
ParameterType
scaleFactornumber
Returns

PhysicalSize

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L177


© 2024 Tauri Contributors. CC-BY / MIT