Skip to content

Commit

Permalink
feat: Implement AppWindow Move and Resize on WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Aug 5, 2024
1 parent d6e241f commit 6abcdd8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ partial class NativeWindowFactory

private static INativeWindowWrapper? CreateWindowPlatform(Microsoft.UI.Xaml.Window window, XamlRoot xamlRoot)
{
NativeWindowWrapper.Instance.SetXamlRoot(xamlRoot);
NativeWindowWrapper.Instance.SetWindow(window, xamlRoot);
return NativeWindowWrapper.Instance;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ internal static partial class NativeMethods

[JSImport("globalThis.Uno.UI.WindowManager.current.setWindowTitle")]
internal static partial void SetWindowTitle(string title);

[JSImport("globalThis.Uno.UI.WindowManager.current.resizeWindow")]
internal static partial void ResizeWindow(int width, int height);

[JSImport("globalThis.Uno.UI.WindowManager.current.moveWindow")]
internal static partial void MoveWindow(int x, int y);
}
}
9 changes: 6 additions & 3 deletions src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.wasm.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Runtime.InteropServices.JavaScript;
using Uno.Disposables;
using Uno.Foundation.Logging;
using Windows.Foundation;
using Windows.Graphics;
using Windows.Graphics.Display;
using Windows.UI.Core;
using static __Uno.UI.Xaml.Controls.NativeWindowWrapper;
Expand Down Expand Up @@ -40,7 +39,7 @@ private void DispatchDpiChanged() =>

internal void OnNativeActivated(CoreWindowActivationState state) => ActivationState = state;

internal void OnNativeVisibilityChanged(bool visible) => Visible = visible;
internal void OnNativeVisibilityChanged(bool visible) => IsVisible = visible;

internal void RaiseNativeSizeChanged(double width, double height)
{
Expand Down Expand Up @@ -69,4 +68,8 @@ protected override IDisposable ApplyFullScreenPresenter()
SetFullScreenMode(true);
return Disposable.Create(() => SetFullScreenMode(false));
}

public override void Move(PointInt32 position) => NativeMethods.MoveWindow(position.X, position.Y);

public override void Resize(SizeInt32 size) => NativeMethods.ResizeWindow(size.Width, size.Height);
}
12 changes: 10 additions & 2 deletions src/Uno.UI/ts/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ namespace Uno.UI {
if (element) {
element.parentElement.removeChild(element);
}

let bootstrapperLoaders = document.getElementsByClassName(WindowManager.unoPersistentLoaderClassName);
if (bootstrapperLoaders.length > 0) {
let bootstrapperLoader = bootstrapperLoaders[0] as HTMLElement;
Expand Down Expand Up @@ -1743,7 +1743,7 @@ namespace Uno.UI {

public getIsOverflowing(elementId: number): boolean {
const element = this.getView(elementId) as HTMLElement;

return element.clientWidth < element.scrollWidth || element.clientHeight < element.scrollHeight;
}

Expand All @@ -1752,6 +1752,14 @@ namespace Uno.UI {

element.setAttribute("tabindex", isFocusable ? "0" : "-1");
}

public resizeWindow(width: number, height: number) {
window.resizeTo(width, height);
}

public moveWindow(x: number, y: number) {
window.moveTo(x, y);
}
}

if (typeof define === "function") {
Expand Down

0 comments on commit 6abcdd8

Please sign in to comment.