committed by
GitHub
45 changed files with 721 additions and 194 deletions
@ -1,21 +1,64 @@ |
|||
namespace Avalonia.Platform |
|||
using System; |
|||
|
|||
namespace Avalonia.Platform |
|||
{ |
|||
/// <summary>
|
|||
/// Represents a single display screen.
|
|||
/// </summary>
|
|||
public class Screen |
|||
{ |
|||
public double PixelDensity { get; } |
|||
/// <summary>
|
|||
/// Gets the scaling factor applied to the screen by the operating system.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Multiply this value by 100 to get a percentage.
|
|||
/// Both X and Y scaling factors are assumed uniform.
|
|||
/// </remarks>
|
|||
public double Scaling { get; } |
|||
|
|||
/// <inheritdoc cref="Scaling"/>
|
|||
[Obsolete("Use the Scaling property instead.")] |
|||
public double PixelDensity => Scaling; |
|||
|
|||
/// <summary>
|
|||
/// Gets the overall pixel-size of the screen.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// This generally is the raw pixel counts in both the X and Y direction.
|
|||
/// </remarks>
|
|||
public PixelRect Bounds { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the actual working-area pixel-size of the screen.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// This area may be smaller than <see href="Bounds"/> to account for notches and
|
|||
/// other block-out areas such as taskbars etc.
|
|||
/// </remarks>
|
|||
public PixelRect WorkingArea { get; } |
|||
|
|||
public bool Primary { get; } |
|||
|
|||
public Screen(double pixelDensity, PixelRect bounds, PixelRect workingArea, bool primary) |
|||
/// <summary>
|
|||
/// Gets a value indicating whether the screen is the primary one.
|
|||
/// </summary>
|
|||
public bool IsPrimary { get; } |
|||
|
|||
/// <inheritdoc cref="IsPrimary"/>
|
|||
[Obsolete("Use the IsPrimary property instead.")] |
|||
public bool Primary => IsPrimary; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Screen"/> class.
|
|||
/// </summary>
|
|||
/// <param name="scaling">The scaling factor applied to the screen by the operating system.</param>
|
|||
/// <param name="bounds">The overall pixel-size of the screen.</param>
|
|||
/// <param name="workingArea">The actual working-area pixel-size of the screen.</param>
|
|||
/// <param name="isPrimary">Whether the screen is the primary one.</param>
|
|||
public Screen(double scaling, PixelRect bounds, PixelRect workingArea, bool isPrimary) |
|||
{ |
|||
this.PixelDensity = pixelDensity; |
|||
this.Scaling = scaling; |
|||
this.Bounds = bounds; |
|||
this.WorkingArea = workingArea; |
|||
this.Primary = primary; |
|||
this.IsPrimary = isPrimary; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,34 @@ |
|||
using System.Linq; |
|||
using XamlX; |
|||
using XamlX.Ast; |
|||
using XamlX.Transform; |
|||
using XamlX.Transform.Transformers; |
|||
|
|||
namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers; |
|||
|
|||
internal class AvaloniaXamlIlSetterTargetTypeMetadataTransformer : IXamlAstTransformer |
|||
{ |
|||
public IXamlAstNode Transform(AstTransformationContext context, IXamlAstNode node) |
|||
{ |
|||
if (node is XamlAstObjectNode on |
|||
&& on.Children.FirstOrDefault(c => c is XamlAstXmlDirective |
|||
{ |
|||
Namespace: XamlNamespaces.Xaml2006, |
|||
Name: "SetterTargetType" |
|||
}) is { } typeDirective) |
|||
{ |
|||
var value = ((XamlAstXmlDirective)typeDirective).Values.Single(); |
|||
var type = value is XamlTypeExtensionNode typeNode ? typeNode.Value |
|||
: value is XamlAstTextNode tn ? TypeReferenceResolver.ResolveType(context, tn.Text, false, tn, true) |
|||
: null; |
|||
on.Children.Remove(typeDirective); |
|||
|
|||
if (type is null) |
|||
{ |
|||
throw new XamlParseException("Unable to resolve SetterTargetType type", typeDirective); |
|||
} |
|||
return new AvaloniaXamlIlTargetTypeMetadataNode(on, type, AvaloniaXamlIlTargetTypeMetadataNode.ScopeTypes.Style); |
|||
} |
|||
return node; |
|||
} |
|||
} |
|||
@ -1,5 +1,5 @@ |
|||
<Project> |
|||
<Project> |
|||
<PropertyGroup> |
|||
<EmccExtraLDFlags>$(EmccExtraLDFlags) --js-library="$(MSBuildThisFileDirectory)\interop.js"</EmccExtraLDFlags> |
|||
<EmccInitialHeapSize>16384000</EmccInitialHeapSize> <!-- must be a multiple of 64KiB, 1024000 * num MB, number grows --> |
|||
</PropertyGroup> |
|||
</Project> |
|||
|
|||
@ -0,0 +1,51 @@ |
|||
using Avalonia.Controls; |
|||
using Avalonia.Styling; |
|||
using Avalonia.UnitTests; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Markup.Xaml.UnitTests; |
|||
|
|||
public class SetterTests : XamlTestBase |
|||
{ |
|||
[Fact] |
|||
public void SetterTargetType_Should_Understand_xType_Extensions() |
|||
{ |
|||
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|||
{ |
|||
var xaml = @"
|
|||
<Animation xmlns='https://github.com/avaloniaui' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:SetterTargetType='{x:Type ContentControl}'>
|
|||
<KeyFrame> |
|||
<Setter Property='Content' Value='{Binding}'/> |
|||
</KeyFrame> |
|||
<KeyFrame> |
|||
<Setter Property='Content' Value='{Binding}'/> |
|||
</KeyFrame> |
|||
</Animation>";
|
|||
var animation = (Animation.Animation)AvaloniaRuntimeXamlLoader.Load(xaml); |
|||
var setter = (Setter)animation.Children[0].Setters[0]; |
|||
|
|||
Assert.Equal(typeof(ContentControl), setter.Property.OwnerType); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void SetterTargetType_Should_Understand_Type_From_Xmlns() |
|||
{ |
|||
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|||
{ |
|||
var xaml = @"
|
|||
<av:Animation xmlns:av='https://github.com/avaloniaui' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:SetterTargetType='av:ContentControl'>
|
|||
<av:KeyFrame> |
|||
<av:Setter Property='Content' Value='{av:Binding}'/> |
|||
</av:KeyFrame> |
|||
<av:KeyFrame> |
|||
<av:Setter Property='Content' Value='{av:Binding}'/> |
|||
</av:KeyFrame> |
|||
</av:Animation>";
|
|||
var animation = (Animation.Animation)AvaloniaRuntimeXamlLoader.Load(xaml); |
|||
var setter = (Setter)animation.Children[0].Setters[0]; |
|||
|
|||
Assert.Equal(typeof(ContentControl), setter.Property.OwnerType); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue