mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-21 04:49:46 +08:00
♻️ 调整窗口大小&放缩计算逻辑
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//! @file src/client/utils.rs
|
||||
//! @desc 结合屏幕分辨率获取窗口大小
|
||||
//! @since Beta v0.7.6
|
||||
//! @since Beta v0.7.9
|
||||
|
||||
use tauri::{AppHandle, Manager, Monitor};
|
||||
|
||||
@@ -14,19 +14,9 @@ pub fn get_window_size2(monitor: Monitor, width: f64, height: f64) -> (f64, f64)
|
||||
let monitor_size = monitor.size();
|
||||
let monitor_width = monitor_size.width as f64;
|
||||
let monitor_height = monitor_size.height as f64;
|
||||
let monitor_scale = monitor.scale_factor();
|
||||
let width_scale = monitor_width / 1920.0;
|
||||
let height_scale = monitor_height / 1080.0;
|
||||
let mut get_width: f64 = 0.0;
|
||||
let mut get_height: f64 = 0.0;
|
||||
// 忽略未使用
|
||||
println!("{} {}", get_width, get_height);
|
||||
get_width = (width * width_scale / monitor_scale).round();
|
||||
get_height = (height * height_scale / monitor_scale).round();
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
get_width = (width * width_scale).round();
|
||||
get_height = (height * height_scale).round();
|
||||
}
|
||||
let get_width = (width * width_scale).round();
|
||||
let get_height = (height * height_scale).round();
|
||||
(get_width, get_height)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file utils/TGWindow.ts
|
||||
* @description 窗口创建相关工具函数
|
||||
* @since Beta v0.7.6
|
||||
* @since Beta v0.7.9
|
||||
*/
|
||||
|
||||
import type { RenderCard } from "@comp/app/t-postcard.vue";
|
||||
@@ -10,7 +10,6 @@ import { core, webviewWindow, window as TauriWindow } from "@tauri-apps/api";
|
||||
import { PhysicalSize } from "@tauri-apps/api/dpi";
|
||||
import { currentMonitor, WindowOptions } from "@tauri-apps/api/window";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import { type } from "@tauri-apps/plugin-os";
|
||||
|
||||
import TGLogger from "./TGLogger.js";
|
||||
|
||||
@@ -103,7 +102,7 @@ export function getWindowSize(label: string): PhysicalSize {
|
||||
|
||||
/**
|
||||
* @description 窗口适配
|
||||
* @since Beta v0.7.6
|
||||
* @since Beta v0.7.9
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
export async function resizeWindow(): Promise<void> {
|
||||
@@ -117,13 +116,10 @@ export async function resizeWindow(): Promise<void> {
|
||||
const designSize = getWindowSize(windowCur.label);
|
||||
const widthScale = screen.size.width / 1920;
|
||||
const heightScale = screen.size.height / 1080;
|
||||
let targetWidth = Math.round((designSize.width * widthScale) / screen.scaleFactor);
|
||||
let targetHeight = Math.round((designSize.height * heightScale) / screen.scaleFactor);
|
||||
if (type() === "macos") {
|
||||
targetWidth = Math.round(designSize.width * widthScale);
|
||||
targetHeight = Math.round(designSize.height * heightScale);
|
||||
}
|
||||
const targetWidth = Math.round(designSize.width * widthScale);
|
||||
const targetHeight = Math.round(designSize.height * heightScale);
|
||||
await windowCur.setSize(new PhysicalSize(targetWidth, targetHeight));
|
||||
await windowCur.setZoom((1 / screen.scaleFactor) * Math.min(widthScale, heightScale));
|
||||
const targetZoom = Math.min(widthScale, heightScale) / screen.scaleFactor;
|
||||
await windowCur.setZoom(targetZoom);
|
||||
await windowCur.setFocus();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user