This commit is contained in:
DismissedLight
2024-07-06 10:38:58 +08:00
parent 1cd6aad518
commit e230d7a3ef
4 changed files with 8 additions and 6 deletions

View File

@@ -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)

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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()