|
@@ -63,17 +63,35 @@ class LogicalSize {
|
|
|
* import { invoke } from '@tauri-apps/api/core';
|
|
|
*
|
|
|
* const size = new LogicalSize(400, 500);
|
|
|
- * await invoke("do_something_with_size", { size: size.toJSON() })
|
|
|
+ * await invoke("do_something_with_size", { size: size.toIPC() })
|
|
|
* ```
|
|
|
*
|
|
|
* @since 2.0.0
|
|
|
*/
|
|
|
- toJSON() {
|
|
|
+ toIPC() {
|
|
|
return {
|
|
|
width: this.width,
|
|
|
height: this.height
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Converts this size into JSON value, that can be deserialized
|
|
|
+ * correctly on the Rust side using `tauri::LogicalSize` struct.
|
|
|
+ * @example
|
|
|
+ * ```typescript
|
|
|
+ * import { LogicalSize } from '@tauri-apps/api/dpi';
|
|
|
+ * import { invoke } from '@tauri-apps/api/core';
|
|
|
+ *
|
|
|
+ * const size = new LogicalSize(400, 500);
|
|
|
+ * await invoke("do_something_with_size", { size: size.toJSON() })
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * @since 2.0.0
|
|
|
+ */
|
|
|
+ toJSON() {
|
|
|
+ return this.toIPC()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -133,19 +151,35 @@ class PhysicalSize {
|
|
|
* import { invoke } from '@tauri-apps/api/core';
|
|
|
*
|
|
|
* const size = new PhysicalSize(400, 500);
|
|
|
- * await invoke("do_something_with_size", { size: size.toJSON() })
|
|
|
+ * await invoke("do_something_with_size", { size: size.toIPC() })
|
|
|
* ```
|
|
|
*
|
|
|
* @since 2.0.0
|
|
|
*/
|
|
|
- toJSON() {
|
|
|
+ toIPC() {
|
|
|
return {
|
|
|
- Physical: {
|
|
|
- width: this.width,
|
|
|
- height: this.height
|
|
|
- }
|
|
|
+ width: this.width,
|
|
|
+ height: this.height
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Converts this size into JSON value, that can be deserialized
|
|
|
+ * correctly on the Rust side using `tauri::PhysicalSize` struct.
|
|
|
+ * @example
|
|
|
+ * ```typescript
|
|
|
+ * import { PhysicalSize } from '@tauri-apps/api/dpi';
|
|
|
+ * import { invoke } from '@tauri-apps/api/core';
|
|
|
+ *
|
|
|
+ * const size = new PhysicalSize(400, 500);
|
|
|
+ * await invoke("do_something_with_size", { size: size.toJSON() })
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * @since 2.0.0
|
|
|
+ */
|
|
|
+ toJSON() {
|
|
|
+ return this.toIPC()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -209,19 +243,35 @@ class LogicalPosition {
|
|
|
* import { invoke } from '@tauri-apps/api/core';
|
|
|
*
|
|
|
* const position = new LogicalPosition(400, 500);
|
|
|
- * await invoke("do_something_with_position", { size: size.toJSON() })
|
|
|
+ * await invoke("do_something_with_position", { position: position.toIPC() })
|
|
|
* ```
|
|
|
*
|
|
|
* @since 2.0.0
|
|
|
*/
|
|
|
- toJSON() {
|
|
|
+ toIPC() {
|
|
|
return {
|
|
|
- Logical: {
|
|
|
- x: this.x,
|
|
|
- y: this.y
|
|
|
- }
|
|
|
+ x: this.x,
|
|
|
+ y: this.y
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Converts this position into JSON value, that can be deserialized
|
|
|
+ * correctly on the Rust side using `tauri::LogicalPosition` struct.
|
|
|
+ * @example
|
|
|
+ * ```typescript
|
|
|
+ * import { LogicalPosition } from '@tauri-apps/api/dpi';
|
|
|
+ * import { invoke } from '@tauri-apps/api/core';
|
|
|
+ *
|
|
|
+ * const position = new LogicalPosition(400, 500);
|
|
|
+ * await invoke("do_something_with_position", { position: position.toJSON() })
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * @since 2.0.0
|
|
|
+ */
|
|
|
+ toJSON() {
|
|
|
+ return this.toIPC()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -258,42 +308,42 @@ class PhysicalPosition {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Converts the physical position to a logical one.
|
|
|
+ * Converts this position into IPC-compatible value, so it can be
|
|
|
+ * deserialized correctly on the Rust side using `tauri::PhysicalPosition` struct.
|
|
|
* @example
|
|
|
* ```typescript
|
|
|
- * import { getCurrentWindow } from '@tauri-apps/api/window';
|
|
|
+ * import { PhysicalPosition } from '@tauri-apps/api/dpi';
|
|
|
+ * import { invoke } from '@tauri-apps/api/core';
|
|
|
*
|
|
|
- * const appWindow = getCurrentWindow();
|
|
|
- * const factor = await appWindow.scaleFactor();
|
|
|
- * const position = await appWindow.innerPosition(); // PhysicalPosition
|
|
|
- * const logical = position.toLogical(factor);
|
|
|
+ * const position = new PhysicalPosition(400, 500);
|
|
|
+ * await invoke("do_something_with_position", { position: position.toIPC() })
|
|
|
* ```
|
|
|
+ *
|
|
|
+ * @since 2.0.0
|
|
|
*/
|
|
|
- toLogical(scaleFactor: number): LogicalPosition {
|
|
|
- return new LogicalPosition(this.x / scaleFactor, this.y / scaleFactor)
|
|
|
+ toIPC() {
|
|
|
+ return {
|
|
|
+ x: this.x,
|
|
|
+ y: this.y
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Converts this position into IPC-compatible value, so it can be
|
|
|
- * deserialized correctly on the Rust side using `tauri::PhysicalPosition` struct.
|
|
|
+ * Converts this position into JSON value, that can be deserialized
|
|
|
+ * correctly on the Rust side using `tauri::PhysicalPosition` struct.
|
|
|
* @example
|
|
|
* ```typescript
|
|
|
* import { PhysicalPosition } from '@tauri-apps/api/dpi';
|
|
|
* import { invoke } from '@tauri-apps/api/core';
|
|
|
*
|
|
|
* const position = new PhysicalPosition(400, 500);
|
|
|
- * await invoke("do_something_with_position", { size: size.toJSON() })
|
|
|
+ * await invoke("do_something_with_position", { position: position.toJSON() })
|
|
|
* ```
|
|
|
*
|
|
|
* @since 2.0.0
|
|
|
*/
|
|
|
toJSON() {
|
|
|
- return {
|
|
|
- Physical: {
|
|
|
- x: this.x,
|
|
|
- y: this.y
|
|
|
- }
|
|
|
- }
|
|
|
+ return this.toIPC()
|
|
|
}
|
|
|
}
|
|
|
|