Skip to content

Commit

Permalink
feat: implement CoreWindows.Bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
iury committed Jun 6, 2022
1 parent 7f11995 commit 41b21a3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
27 changes: 27 additions & 0 deletions src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_CoreWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
using Windows.UI.Xaml;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Windows.UI.ViewManagement;

namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml
{
[TestClass]
public class Given_CoreWindow
{
#if !WINDOWS_UWP
[TestMethod]
[RunsOnUIThread]
public void CoreWindow_Bounds_Implemented()
{
var w = new Windows.UI.Xaml.Window();
var vb = ApplicationView.GetForCurrentView().VisibleBounds;
var SUT = w.CoreWindow.Bounds;

Assert.AreEqual(vb.Width, SUT.Width);
Assert.AreEqual(vb.Height, SUT.Height);
}
#endif
}
}
10 changes: 0 additions & 10 deletions src/Uno.UWP/Generated/3.0.0.0/Windows.UI.Core/CoreWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ public object AutomationHostProvider
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.Foundation.Rect Bounds
{
get
{
throw new global::System.NotImplementedException("The member Rect CoreWindow.Bounds is not implemented in Uno.");
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.Foundation.Collections.IPropertySet CustomProperties
{
get
Expand Down
16 changes: 15 additions & 1 deletion src/Uno.UWP/UI/Core/CoreWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Windows.System;
using Windows.UI.Input;
using Uno.Foundation.Logging;
using Windows.UI.ViewManagement;

namespace Windows.UI.Core
{
Expand Down Expand Up @@ -52,6 +53,10 @@ private CoreWindow()

internal static CoreWindow? Main { get; private set; }

/// <summary>
/// Gets a Rect value containing the height and width of the application window in units of effective (view) pixels.
/// </summary>
public Rect Bounds { get; private set; }
/// <summary>
/// Gets the event dispatcher for the window.
/// </summary>
Expand Down Expand Up @@ -125,7 +130,16 @@ internal void OnActivated(WindowActivatedEventArgs args)
}

internal void OnSizeChanged(WindowSizeChangedEventArgs windowSizeChangedEventArgs)
=> SizeChanged?.Invoke(this, windowSizeChangedEventArgs);
{
//Windows.Bounds doesn't implemment X an Y Windows Origin as well.
var newBounds = new Rect(0,0,windowSizeChangedEventArgs.Size.Width, windowSizeChangedEventArgs.Size.Height);
if (newBounds != Bounds)
{
Bounds = newBounds;
}

SizeChanged?.Invoke(this, windowSizeChangedEventArgs);
}

internal interface IPointerEventArgs
{
Expand Down

0 comments on commit 41b21a3

Please sign in to comment.