Skip to content

Commit

Permalink
feat: Add basic support for ContentSite and ContentSiteView
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Apr 22, 2024
1 parent e356253 commit 05dffe7
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 24 deletions.
14 changes: 7 additions & 7 deletions src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Content/ContentSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#pragma warning disable 114 // new keyword hiding
namespace Microsoft.UI.Content
{
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented]
#endif
public partial class ContentSite : global::System.IDisposable, global::Microsoft.UI.IClosableNotifier
{
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
internal ContentSite()
{
}
Expand All @@ -27,7 +27,7 @@ public bool ShouldApplyRasterizationScale
}
}
#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 float ParentScale
{
Expand All @@ -41,7 +41,7 @@ public float ParentScale
}
}
#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 float OverrideScale
{
Expand Down Expand Up @@ -69,7 +69,7 @@ public float OverrideScale
}
}
#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 bool IsSiteVisible
{
Expand Down Expand Up @@ -165,7 +165,7 @@ public bool IsConnected
}
}
#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 float RasterizationScale
{
Expand All @@ -185,7 +185,7 @@ public float RasterizationScale
}
}
#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.Content.ContentSiteView View
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#pragma warning disable 114 // new keyword hiding
namespace Microsoft.UI.Content
{
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented]
#endif
public partial class ContentSiteView
{
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
internal ContentSiteView()
{
}
Expand Down Expand Up @@ -83,7 +83,7 @@ public bool IsSiteEnabled
}
}
#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 bool IsSiteVisible
{
Expand All @@ -103,7 +103,7 @@ public bool IsSiteVisible
}
}
#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 float OverrideScale
{
Expand All @@ -113,7 +113,7 @@ public float OverrideScale
}
}
#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 float ParentScale
{
Expand All @@ -123,7 +123,7 @@ public float ParentScale
}
}
#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 float RasterizationScale
{
Expand Down
11 changes: 6 additions & 5 deletions src/Uno.UI/UI/Content/ContentIsland.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.UI;
using Microsoft.UI.Composition;
using Uno;
using Uno.UI.Content;
using Uno.UI.Hosting;
using Uno.UI.Xaml.Controls;
using Windows.Foundation;
Expand All @@ -16,22 +17,22 @@ public partial class ContentIsland
: IDisposable, IClosableNotifier, ICompositionSupportsSystemBackdrop
#endif
{
private readonly INativeWindowWrapper _nativeWindowWrapper;
private readonly ContentSiteView _contentSiteView;

internal ContentIsland(INativeWindowWrapper nativeWindowWrapper)
internal ContentIsland(ContentSiteView contentSiteView)
{
_nativeWindowWrapper = nativeWindowWrapper;
_contentSiteView = contentSiteView ?? throw new ArgumentNullException(nameof(contentSiteView));
}

/// <summary>
/// Gets the local dots per inch (dpi) of a Microsoft.UI.Composition.ICompositionSurface.
/// </summary>
public float RasterizationScale => _nativeWindowWrapper.RasterizationScale;
public float RasterizationScale => _contentSiteView.RasterizationScale;

/// <summary>
/// Gets whether the associated ContentSite is visible.
/// </summary>
public bool IsSiteVisible => _nativeWindowWrapper.Visible;
public bool IsSiteVisible => _contentSiteView.IsSiteVisible;

/// <summary>
/// Occurs when a state property for this ContentIsland changes.
Expand Down
39 changes: 39 additions & 0 deletions src/Uno.UI/UI/Content/ContentSite.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;

namespace Microsoft.UI.Content;

/// <summary>
/// Provides a host environment for a ContentIsland.
/// </summary>
public partial class ContentSite
#if HAS_UNO_WINUI // These interfaces are not currently implemented and the Generated partial does not exist in UWP build.
: IDisposable, IClosableNotifier
#endif
{
internal ContentSite() => View = new(this);

/// <summary>
/// Gets or sets whether this ContentSite is visible.
/// </summary>
public bool IsSiteVisible { get; set; }

/// <summary>
/// Gets or sets the parent default scaling factor for this ContentSite.
/// </summary>
public float ParentScale { get; set; } = 1f;

/// <summary>
/// Gets or sets the scaling factor to use for this ContentSite, which overrides the ParentScale.
/// </summary>
public float OverrideScale { get; set; } = 1f;

/// <summary>
/// Gets the computed local DPI for this ContentSite.
/// </summary>
public float RasterizationScale => OverrideScale * ParentScale;

/// <summary>
/// Gets the ContentSiteView associated with this ContentSite.
/// </summary>
public ContentSiteView View { get; }
}
41 changes: 41 additions & 0 deletions src/Uno.UI/UI/Content/ContentSiteView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;

namespace Microsoft.UI.Content;

/// <summary>
/// Provides access to a read-only view of ContentSite properties.
/// </summary>
/// <remarks>
/// This object exposes the most recent values from a ContentSite,
/// it is not a snapshot in time.
/// </remarks>
public partial class ContentSiteView
{
private readonly ContentSite _contentSite;

internal ContentSiteView(ContentSite contentSite)
{
_contentSite = contentSite ?? throw new ArgumentNullException(nameof(contentSite));
}

/// <summary>
/// Gets the IsSiteVisible state reported by the ContentSite.
/// </summary>
public bool IsSiteVisible => _contentSite.IsSiteVisible;

/// <summary>
/// Gets the default scaling factor of the parent for a single ContentSite.
/// </summary>
public float ParentScale => _contentSite.ParentScale;

/// <summary>
/// Gets the override scaling factor for a single ContentSite, ignoring the default scaling factor of the parent.
/// </summary>
public float OverrideScale => _contentSite.OverrideScale;

/// <summary>
/// Gets the computed local DPI for the associated ContentSite,
/// which is computed from the OverrideScale and ParentScale.
/// </summary>
public float RasterizationScale => _contentSite.RasterizationScale;
}

This file was deleted.

0 comments on commit 05dffe7

Please sign in to comment.