mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-01-31 00:35:19 +01:00
feat(api): add {LogicalPosition,LogicalSize}.toPhysical method (#11031)
closes #11008
This commit is contained in:
6
.changes/api-to-physical.md
Normal file
6
.changes/api-to-physical.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@tauri-apps/api": "patch:feat"
|
||||
---
|
||||
|
||||
Add `toPhysical` method on `LogicalPositon` and `LogicalSize` classes.
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -16,6 +16,23 @@ class LogicalSize {
|
||||
this.width = width
|
||||
this.height = height
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the logical size to a physical one.
|
||||
* @example
|
||||
* ```typescript
|
||||
* 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
|
||||
*/
|
||||
toPhysical(scaleFactor: number): PhysicalSize {
|
||||
return new PhysicalSize(this.width * scaleFactor, this.height * scaleFactor)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +60,7 @@ class PhysicalSize {
|
||||
* const size = await appWindow.innerSize();
|
||||
* const logical = size.toLogical(factor);
|
||||
* ```
|
||||
* */
|
||||
*/
|
||||
toLogical(scaleFactor: number): LogicalSize {
|
||||
return new LogicalSize(this.width / scaleFactor, this.height / scaleFactor)
|
||||
}
|
||||
@@ -63,6 +80,23 @@ class LogicalPosition {
|
||||
this.x = x
|
||||
this.y = y
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the logical position to a physical one.
|
||||
* @example
|
||||
* ```typescript
|
||||
* 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
|
||||
*/
|
||||
toPhysical(scaleFactor: number): PhysicalPosition {
|
||||
return new PhysicalPosition(this.x * scaleFactor, this.x * scaleFactor)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +124,7 @@ class PhysicalPosition {
|
||||
* const position = await appWindow.innerPosition();
|
||||
* const logical = position.toLogical(factor);
|
||||
* ```
|
||||
* */
|
||||
*/
|
||||
toLogical(scaleFactor: number): LogicalPosition {
|
||||
return new LogicalPosition(this.x / scaleFactor, this.y / scaleFactor)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user