Skip to content

Commit

Permalink
feat: Adding new AppWindow APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Aug 5, 2024
1 parent 8b52742 commit c543197
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public bool IsShownInSwitchers
}
#endif
// Skipping already declared property Id
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public bool IsVisible
{
Expand All @@ -44,7 +44,7 @@ public bool IsVisible
}
}
#endif
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.Graphics.PointInt32 Position
{
Expand All @@ -55,7 +55,7 @@ public bool IsVisible
}
#endif
// Skipping already declared property Presenter
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.Graphics.SizeInt32 Size
{
Expand All @@ -76,7 +76,7 @@ public bool IsVisible
}
}
#endif
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Microsoft.UI.Dispatching.DispatcherQueue DispatcherQueue
{
Expand Down
50 changes: 46 additions & 4 deletions src/Uno.UWP/Microsoft/UI/Windowing/AppWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
using Microsoft.UI.Windowing.Native;
using Windows.UI.ViewManagement;
using MUXWindowId = Microsoft.UI.WindowId;
using Windows.Graphics;
using Microsoft.UI.Dispatching;

namespace Microsoft.UI.Windowing;

/// <summary>
/// Represents a system-managed container for the content of an app.
/// </summary>
#if HAS_UNO_WINUI
public
#else
Expand All @@ -28,6 +33,8 @@ internal AppWindow()
{
Id = new(Interlocked.Increment(ref _windowIdIterator));

TitleBar = new(this);

_windowIdMap[Id] = this;
ApplicationView.GetOrCreateForWindowId(Id);
}
Expand All @@ -39,6 +46,43 @@ internal AppWindow()
/// </summary>
public AppWindowTitleBar TitleBar { get; } = new AppWindowTitleBar();

/// Gets the current size of the window's client area in client coordinates.
/// </summary>
public SizeInt32 ClientSize => _nativeAppWindow.ClientSize;

/// <summary>
/// Gets the dispatcher queue associated with the app window.
/// </summary>
public DispatcherQueue DispatcherQueue => _nativeAppWindow.DispatcherQueue;

/// <summary>
/// Gets the identifier for the app window.
/// </summary>
public MUXWindowId Id { get; }

/// <summary>
/// Gets a value that indicates whether the window is shown.
/// </summary>
public bool IsVisible => _nativeAppWindow.IsVisible;

/// <summary>
/// Gets the current position of the window in screen coordinates.
/// </summary>
public PointInt32 Position => _nativeAppWindow.Position;

/// <summary>
/// Gets the currently applied presenter for the app window.
/// </summary>
public AppWindowPresenter Presenter => _presenter;

/// <summary>
/// Gets the current size of the window in screen coordinates.
/// </summary>
public SizeInt32 Size => _nativeAppWindow.Size;

/// <summary>
/// Gets or sets the displayed title of the app window.
/// </summary>
public string Title
{
get => _nativeAppWindow is not null ? _nativeAppWindow.Title : _titleCache;
Expand All @@ -53,6 +97,8 @@ public string Title
}
}

public AppWindowTitleBar TitleBar { get; }

internal void SetNativeWindow(INativeAppWindow nativeAppWindow)
{
if (nativeAppWindow is null)
Expand All @@ -78,10 +124,6 @@ internal void SetNativeWindow(INativeAppWindow nativeAppWindow)

internal static MUXWindowId MainWindowId { get; } = new(1);

public MUXWindowId Id { get; }

public AppWindowPresenter Presenter => _presenter;

public static AppWindow GetFromWindowId(MUXWindowId windowId)
{
if (!_windowIdMap.TryGetValue(windowId, out var appWindow))
Expand Down
22 changes: 22 additions & 0 deletions src/Uno.UWP/Microsoft/UI/Windowing/Native/INativeAppWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,35 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Windowing;
using Windows.Graphics;

namespace Microsoft.UI.Windowing.Native;

internal interface INativeAppWindow
{
string Title { get; set; }

bool IsVisible { get; }

PointInt32 Position { get; }

SizeInt32 Size { get; }

SizeInt32 ClientSize { get; }

DispatcherQueue DispatcherQueue { get; }

void Destroy();

void Hide();

void Move(PointInt32 position);

void Resize(SizeInt32 size);

void Show(bool activateWindow);

void SetPresenter(AppWindowPresenter presenter);
}

0 comments on commit c543197

Please sign in to comment.