mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
fix #1795
This commit is contained in:
@@ -66,7 +66,7 @@ internal sealed partial class AnnouncementWebView2ContentProvider : DependencyOb
|
||||
}
|
||||
}
|
||||
|
||||
public RectInt32 InitializePosition(RectInt32 parentRect)
|
||||
public RectInt32 InitializePosition(RectInt32 parentRect, double parentDpi)
|
||||
{
|
||||
// Parent Window can never be so small
|
||||
// if (parentRect.Width < 96 || parentRect.Height < 96)
|
||||
|
||||
@@ -15,7 +15,7 @@ internal interface IWebView2ContentProvider
|
||||
|
||||
ValueTask InitializeAsync(IServiceProvider serviceProvider, CancellationToken token);
|
||||
|
||||
RectInt32 InitializePosition(RectInt32 parentRect);
|
||||
RectInt32 InitializePosition(RectInt32 parentRect, double parentDpi);
|
||||
|
||||
void Unload();
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.Graphics.Display;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
@@ -70,11 +71,11 @@ internal sealed partial class MiHoYoJSBridgeWebView2ContentProvider : Dependency
|
||||
jsBridge?.Detach();
|
||||
}
|
||||
|
||||
public RectInt32 InitializePosition(RectInt32 parentRect)
|
||||
public RectInt32 InitializePosition(RectInt32 parentRect, double parentDpi)
|
||||
{
|
||||
PointInt32 center = parentRect.GetPointInt32(PointInt32Kind.Center);
|
||||
RectInt32 target = new(center.X - 240, center.Y - 400, 450, 800);
|
||||
|
||||
SizeInt32 size = new SizeInt32(480, 800).Scale(parentDpi);
|
||||
RectInt32 target = RectInt32Convert.RectInt32(new(center.X - (size.Width / 2), center.Y - (size.Height / 2)), size);
|
||||
RectInt32 workArea = DisplayArea.GetFromRect(parentRect, DisplayAreaFallback.None).WorkArea;
|
||||
RectInt32 workAreaShrink = new(workArea.X + 48, workArea.Y + 48, workArea.Width - 96, workArea.Height - 96);
|
||||
|
||||
|
||||
@@ -60,7 +60,8 @@ internal sealed partial class WebView2Window : Microsoft.UI.Xaml.Window, IXamlWi
|
||||
EnableWindow(parentHWND, false);
|
||||
base.Activate();
|
||||
|
||||
AppWindow.MoveThenResize(contentProvider.InitializePosition(parentAppWindow.GetRect()));
|
||||
double dpi = Math.Round(GetDpiForWindow(parentHWND) / 96D, 2, MidpointRounding.AwayFromZero);
|
||||
AppWindow.MoveThenResize(contentProvider.InitializePosition(parentAppWindow.GetRect(), dpi));
|
||||
}
|
||||
|
||||
public void OnWindowClosed()
|
||||
|
||||
Reference in New Issue
Block a user