committed by
GitHub
110 changed files with 1075 additions and 1568 deletions
@ -1,7 +1,7 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="HarfBuzzSharp" Version="2.8.2" /> |
|||
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="HarfBuzzSharp.NativeAssets.Linux" Version="2.8.2" /> |
|||
<PackageReference Condition="'$(IncludeWasmSkia)' == 'true'" Include="HarfBuzzSharp.NativeAssets.WebAssembly" Version="2.8.2" /> |
|||
<PackageReference Include="HarfBuzzSharp" Version="2.8.2.1-preview.108" /> |
|||
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="HarfBuzzSharp.NativeAssets.Linux" Version="2.8.2.1-preview.108" /> |
|||
<PackageReference Condition="'$(IncludeWasmSkia)' == 'true'" Include="HarfBuzzSharp.NativeAssets.WebAssembly" Version="2.8.2.1-preview.108" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
@ -1,5 +1,5 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="ReactiveUI" Version="13.2.10" /> |
|||
<PackageReference Include="ReactiveUI" Version="18.3.1" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
@ -1,7 +1,7 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<ItemGroup> |
|||
<PackageReference Include="SkiaSharp" Version="2.88.1-preview.1" /> |
|||
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="SkiaSharp.NativeAssets.Linux" Version="2.88.1-preview.1" /> |
|||
<PackageReference Condition="'$(IncludeWasmSkia)' == 'true'" Include="SkiaSharp.NativeAssets.WebAssembly" Version="2.88.1-preview.1" /> |
|||
<PackageReference Include="SkiaSharp" Version="2.88.1-preview.108" /> |
|||
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="SkiaSharp.NativeAssets.Linux" Version="2.88.1-preview.108" /> |
|||
<PackageReference Condition="'$(IncludeWasmSkia)' == 'true'" Include="SkiaSharp.NativeAssets.WebAssembly" Version="2.88.1-preview.108" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
@ -1,134 +1,141 @@ |
|||
<UserControl |
|||
xmlns="https://github.com/avaloniaui" |
|||
<UserControl |
|||
xmlns="https://github.com/avaloniaui" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
x:Class="RenderDemo.Pages.DrawingPage"> |
|||
<UserControl.Styles> |
|||
<Style> |
|||
<Style.Resources> |
|||
<DrawingGroup x:Key="Bulb"> |
|||
<DrawingGroup.Transform> |
|||
<MatrixTransform Matrix="1,0,0,1,0,-1028.4" /> |
|||
</DrawingGroup.Transform> |
|||
<DrawingGroup> |
|||
<DrawingGroup.Transform> |
|||
<MatrixTransform Matrix="1,0,0,1.25,-10,1031.4" /> |
|||
</DrawingGroup.Transform> |
|||
<GeometryDrawing Brush="#FF7F8C8D" |
|||
Geometry="F1 M24,14 A2,2,0,1,1,20,14 A2,2,0,1,1,24,14 z" /> |
|||
</DrawingGroup> |
|||
<GeometryDrawing Brush="#FFF39C12" |
|||
Geometry="F1 M12,1030.4 C8.134,1030.4 5,1033.6 5,1037.6 5,1040.7 8.125,1043.5 9,1045.4 9.875,1047.2 9,1050.4 9,1050.4 L12,1049.9 15,1050.4 C15,1050.4 14.125,1047.2 15,1045.4 15.875,1043.5 19,1040.7 19,1037.6 19,1033.6 15.866,1030.4 12,1030.4 z" /> |
|||
<GeometryDrawing Brush="#FFF1C40F" |
|||
Geometry="F1 M12,1030.4 C15.866,1030.4 19,1033.6 19,1037.6 19,1040.7 15.875,1043.5 15,1045.4 14.125,1047.2 15,1050.4 15,1050.4 L12,1049.9 12,1030.4 z" /> |
|||
<GeometryDrawing Brush="#FFE67E22" |
|||
Geometry="F1 M9,1036.4 L8,1037.4 12,1049.4 16,1037.4 15,1036.4 14,1037.4 13,1036.4 12,1037.4 11,1036.4 10,1037.4 9,1036.4 z M9,1037.4 L10,1038.4 10.5,1037.9 11,1037.4 11.5,1037.9 12,1038.4 12.5,1037.9 13,1037.4 13.5,1037.9 14,1038.4 15,1037.4 15.438,1037.8 12,1048.1 8.5625,1037.8 9,1037.4 z" /> |
|||
<DrawingGroup> |
|||
<DrawingGroup.Transform> |
|||
<MatrixTransform Matrix="1,0,0,1,9,1045.4" /> |
|||
</DrawingGroup.Transform> |
|||
<GeometryDrawing Brush="#FFBDC3C7"> |
|||
<GeometryDrawing.Geometry> |
|||
<RectangleGeometry Rect="0,0,6,5" /> |
|||
</GeometryDrawing.Geometry> |
|||
</GeometryDrawing> |
|||
</DrawingGroup> |
|||
<GeometryDrawing Brush="#FF95A5A6" |
|||
Geometry="F1 M9,1045.4 L9,1050.4 12,1050.4 12,1049.4 15,1049.4 15,1048.4 12,1048.4 12,1047.4 15,1047.4 15,1046.4 12,1046.4 12,1045.4 9,1045.4 z" /> |
|||
<GeometryDrawing Brush="#FF7F8C8D" |
|||
Geometry="F1 M9,1046.4 L9,1047.4 12,1047.4 12,1046.4 9,1046.4 z M9,1048.4 L9,1049.4 12,1049.4 12,1048.4 9,1048.4 z" /> |
|||
</DrawingGroup> |
|||
</Style.Resources> |
|||
</Style> |
|||
</UserControl.Styles> |
|||
<Grid RowDefinitions="Auto,Auto,Auto" |
|||
ColumnDefinitions="Auto,Auto,Auto,Auto"> |
|||
<TextBlock Text="None" |
|||
Margin="3" /> |
|||
<Border Grid.Column="0" |
|||
Grid.Row="1" |
|||
VerticalAlignment="Top" |
|||
HorizontalAlignment="Left" |
|||
BorderThickness="1" |
|||
BorderBrush="Gray" |
|||
Margin="5"> |
|||
<DrawingPresenter Drawing="{DynamicResource Bulb}" /> |
|||
</Border> |
|||
<TextBlock Text="Fill" |
|||
Margin="3" |
|||
Grid.Column="1" /> |
|||
<Border Grid.Column="1" |
|||
Grid.Row="1" |
|||
VerticalAlignment="Top" |
|||
HorizontalAlignment="Left" |
|||
BorderThickness="1" |
|||
BorderBrush="Gray" |
|||
Margin="5"> |
|||
<DrawingPresenter Drawing="{DynamicResource Bulb}" |
|||
Width="100" |
|||
Height="50" |
|||
Stretch="Fill" /> |
|||
</Border> |
|||
<TextBlock Text="Uniform" |
|||
Margin="3" |
|||
Grid.Column="2" /> |
|||
<Border Grid.Column="2" |
|||
Grid.Row="1" |
|||
VerticalAlignment="Top" |
|||
HorizontalAlignment="Left" |
|||
BorderThickness="1" |
|||
BorderBrush="Gray" |
|||
Margin="5"> |
|||
<DrawingPresenter Drawing="{DynamicResource Bulb}" |
|||
Width="100" |
|||
Height="50" |
|||
Stretch="Uniform" /> |
|||
</Border> |
|||
<TextBlock Text="UniformToFill" |
|||
Margin="3" |
|||
Grid.Column="3" /> |
|||
<Border Grid.Column="3" |
|||
Grid.Row="1" |
|||
VerticalAlignment="Top" |
|||
HorizontalAlignment="Left" |
|||
BorderThickness="1" |
|||
BorderBrush="Gray" |
|||
Margin="5"> |
|||
<DrawingPresenter Drawing="{DynamicResource Bulb}" |
|||
Width="100" |
|||
Height="50" |
|||
Stretch="UniformToFill" /> |
|||
</Border> |
|||
<UserControl.Styles> |
|||
<Style> |
|||
<Style.Resources> |
|||
<DrawingGroup x:Key="Bulb"> |
|||
<DrawingGroup.Transform> |
|||
<MatrixTransform Matrix="1,0,0,1,0,-1028.4" /> |
|||
</DrawingGroup.Transform> |
|||
<DrawingGroup> |
|||
<DrawingGroup.Transform> |
|||
<MatrixTransform Matrix="1,0,0,1.25,-10,1031.4" /> |
|||
</DrawingGroup.Transform> |
|||
<GeometryDrawing Brush="#FF7F8C8D" |
|||
Geometry="F1 M24,14 A2,2,0,1,1,20,14 A2,2,0,1,1,24,14 z" /> |
|||
</DrawingGroup> |
|||
<GeometryDrawing Brush="#FFF39C12" |
|||
Geometry="F1 M12,1030.4 C8.134,1030.4 5,1033.6 5,1037.6 5,1040.7 8.125,1043.5 9,1045.4 9.875,1047.2 9,1050.4 9,1050.4 L12,1049.9 15,1050.4 C15,1050.4 14.125,1047.2 15,1045.4 15.875,1043.5 19,1040.7 19,1037.6 19,1033.6 15.866,1030.4 12,1030.4 z" /> |
|||
<GeometryDrawing Brush="#FFF1C40F" |
|||
Geometry="F1 M12,1030.4 C15.866,1030.4 19,1033.6 19,1037.6 19,1040.7 15.875,1043.5 15,1045.4 14.125,1047.2 15,1050.4 15,1050.4 L12,1049.9 12,1030.4 z" /> |
|||
<GeometryDrawing Brush="#FFE67E22" |
|||
Geometry="F1 M9,1036.4 L8,1037.4 12,1049.4 16,1037.4 15,1036.4 14,1037.4 13,1036.4 12,1037.4 11,1036.4 10,1037.4 9,1036.4 z M9,1037.4 L10,1038.4 10.5,1037.9 11,1037.4 11.5,1037.9 12,1038.4 12.5,1037.9 13,1037.4 13.5,1037.9 14,1038.4 15,1037.4 15.438,1037.8 12,1048.1 8.5625,1037.8 9,1037.4 z" /> |
|||
<DrawingGroup> |
|||
<DrawingGroup.Transform> |
|||
<MatrixTransform Matrix="1,0,0,1,9,1045.4" /> |
|||
</DrawingGroup.Transform> |
|||
<GeometryDrawing Brush="#FFBDC3C7"> |
|||
<GeometryDrawing.Geometry> |
|||
<RectangleGeometry Rect="0,0,6,5" /> |
|||
</GeometryDrawing.Geometry> |
|||
</GeometryDrawing> |
|||
</DrawingGroup> |
|||
<GeometryDrawing Brush="#FF95A5A6" |
|||
Geometry="F1 M9,1045.4 L9,1050.4 12,1050.4 12,1049.4 15,1049.4 15,1048.4 12,1048.4 12,1047.4 15,1047.4 15,1046.4 12,1046.4 12,1045.4 9,1045.4 z" /> |
|||
<GeometryDrawing Brush="#FF7F8C8D" |
|||
Geometry="F1 M9,1046.4 L9,1047.4 12,1047.4 12,1046.4 9,1046.4 z M9,1048.4 L9,1049.4 12,1049.4 12,1048.4 9,1048.4 z" /> |
|||
</DrawingGroup> |
|||
</Style.Resources> |
|||
</Style> |
|||
</UserControl.Styles> |
|||
<Grid RowDefinitions="Auto,Auto,Auto" |
|||
ColumnDefinitions="Auto,Auto,Auto,Auto"> |
|||
<TextBlock Text="None" |
|||
Margin="3" /> |
|||
<Border Grid.Column="0" |
|||
Grid.Row="1" |
|||
VerticalAlignment="Top" |
|||
HorizontalAlignment="Left" |
|||
BorderThickness="1" |
|||
BorderBrush="Gray" |
|||
Margin="5"> |
|||
<Image> |
|||
<Image.Source> |
|||
<DrawingImage Drawing="{DynamicResource Bulb}" /> |
|||
</Image.Source> |
|||
</Image> |
|||
</Border> |
|||
<TextBlock Text="Fill" |
|||
Margin="3" |
|||
Grid.Column="1" /> |
|||
<Border Grid.Column="1" |
|||
Grid.Row="1" |
|||
VerticalAlignment="Top" |
|||
HorizontalAlignment="Left" |
|||
BorderThickness="1" |
|||
BorderBrush="Gray" |
|||
Margin="5"> |
|||
<Image Width="100" Height="50" Stretch="Fill"> |
|||
<Image.Source> |
|||
<DrawingImage Drawing="{DynamicResource Bulb}" /> |
|||
</Image.Source> |
|||
</Image> |
|||
</Border> |
|||
<TextBlock Text="Uniform" |
|||
Margin="3" |
|||
Grid.Column="2" /> |
|||
<Border Grid.Column="2" |
|||
Grid.Row="1" |
|||
VerticalAlignment="Top" |
|||
HorizontalAlignment="Left" |
|||
BorderThickness="1" |
|||
BorderBrush="Gray" |
|||
Margin="5"> |
|||
<Image Width="100" Height="50" Stretch="Uniform"> |
|||
<Image.Source> |
|||
<DrawingImage Drawing="{DynamicResource Bulb}" /> |
|||
</Image.Source> |
|||
</Image> |
|||
</Border> |
|||
<TextBlock Text="UniformToFill" |
|||
Margin="3" |
|||
Grid.Column="3" /> |
|||
<Border Grid.Column="3" |
|||
Grid.Row="1" |
|||
VerticalAlignment="Top" |
|||
HorizontalAlignment="Left" |
|||
BorderThickness="1" |
|||
BorderBrush="Gray" |
|||
Margin="5"> |
|||
<Image Width="100" Height="50" Stretch="UniformToFill"> |
|||
<Image.Source> |
|||
<DrawingImage Drawing="{DynamicResource Bulb}" /> |
|||
</Image.Source> |
|||
</Image> |
|||
</Border> |
|||
|
|||
<!-- For comparison --> |
|||
<!-- For comparison --> |
|||
|
|||
<Ellipse Grid.Row="2" |
|||
Grid.Column="0" |
|||
Width="100" |
|||
Height="50" |
|||
Stretch="None" |
|||
Fill="Blue" |
|||
Margin="5"/> |
|||
<Ellipse Grid.Row="2" |
|||
Grid.Column="1" |
|||
Width="100" |
|||
Height="50" |
|||
Stretch="Fill" |
|||
Fill="Blue" |
|||
Margin="5" /> |
|||
<Ellipse Grid.Row="2" |
|||
Grid.Column="2" |
|||
Width="100" |
|||
Height="50" |
|||
Stretch="Uniform" |
|||
Fill="Blue" |
|||
Margin="5" /> |
|||
<Ellipse Grid.Row="2" |
|||
Grid.Column="3" |
|||
Width="100" |
|||
Height="50" |
|||
Stretch="UniformToFill" |
|||
Fill="Blue" |
|||
Margin="5" /> |
|||
<Ellipse Grid.Row="2" |
|||
Grid.Column="0" |
|||
Width="100" |
|||
Height="50" |
|||
Stretch="None" |
|||
Fill="Blue" |
|||
Margin="5"/> |
|||
<Ellipse Grid.Row="2" |
|||
Grid.Column="1" |
|||
Width="100" |
|||
Height="50" |
|||
Stretch="Fill" |
|||
Fill="Blue" |
|||
Margin="5" /> |
|||
<Ellipse Grid.Row="2" |
|||
Grid.Column="2" |
|||
Width="100" |
|||
Height="50" |
|||
Stretch="Uniform" |
|||
Fill="Blue" |
|||
Margin="5" /> |
|||
<Ellipse Grid.Row="2" |
|||
Grid.Column="3" |
|||
Width="100" |
|||
Height="50" |
|||
Stretch="UniformToFill" |
|||
Fill="Blue" |
|||
Margin="5" /> |
|||
|
|||
</Grid> |
|||
</UserControl> |
|||
</Grid> |
|||
</UserControl> |
|||
|
|||
@ -1,193 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
|
|||
namespace Avalonia.Utilities |
|||
{ |
|||
/// <summary>
|
|||
/// Manages subscriptions to events using weak listeners.
|
|||
/// </summary>
|
|||
public static class WeakSubscriptionManager |
|||
{ |
|||
/// <summary>
|
|||
/// Subscribes to an event on an object using a weak subscription.
|
|||
/// </summary>
|
|||
/// <typeparam name="TTarget">The type of the target.</typeparam>
|
|||
/// <typeparam name="TEventArgs">The type of the event arguments.</typeparam>
|
|||
/// <param name="target">The event source.</param>
|
|||
/// <param name="eventName">The name of the event.</param>
|
|||
/// <param name="subscriber">The subscriber.</param>
|
|||
[Obsolete("Use WeakEvent")] |
|||
public static void Subscribe<TTarget, TEventArgs>(TTarget target, string eventName, IWeakSubscriber<TEventArgs> subscriber) |
|||
where TEventArgs : EventArgs |
|||
{ |
|||
_ = target ?? throw new ArgumentNullException(nameof(target)); |
|||
|
|||
var dic = SubscriptionTypeStorage<TEventArgs>.Subscribers.GetOrCreateValue(target); |
|||
|
|||
if (!dic.TryGetValue(eventName, out var sub)) |
|||
{ |
|||
dic[eventName] = sub = new Subscription<TEventArgs>(dic, typeof(TTarget), target, eventName); |
|||
} |
|||
|
|||
sub.Add(new WeakReference<IWeakSubscriber<TEventArgs>>(subscriber)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Unsubscribes from an event.
|
|||
/// </summary>
|
|||
/// <typeparam name="T">The type of the event arguments.</typeparam>
|
|||
/// <param name="target">The event source.</param>
|
|||
/// <param name="eventName">The name of the event.</param>
|
|||
/// <param name="subscriber">The subscriber.</param>
|
|||
public static void Unsubscribe<T>(object target, string eventName, IWeakSubscriber<T> subscriber) |
|||
where T : EventArgs |
|||
{ |
|||
if (SubscriptionTypeStorage<T>.Subscribers.TryGetValue(target, out var dic)) |
|||
{ |
|||
if (dic.TryGetValue(eventName, out var sub)) |
|||
{ |
|||
sub.Remove(subscriber); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private static class SubscriptionTypeStorage<T> |
|||
where T : EventArgs |
|||
{ |
|||
public static readonly ConditionalWeakTable<object, SubscriptionDic<T>> Subscribers |
|||
= new ConditionalWeakTable<object, SubscriptionDic<T>>(); |
|||
} |
|||
|
|||
private class SubscriptionDic<T> : Dictionary<string, Subscription<T>> |
|||
where T : EventArgs |
|||
{ |
|||
} |
|||
|
|||
private static readonly Dictionary<Type, Dictionary<string, EventInfo>> Accessors |
|||
= new Dictionary<Type, Dictionary<string, EventInfo>>(); |
|||
|
|||
private class Subscription<T> where T : EventArgs |
|||
{ |
|||
private readonly EventInfo _info; |
|||
private readonly SubscriptionDic<T> _sdic; |
|||
private readonly object _target; |
|||
private readonly string _eventName; |
|||
private readonly Delegate _delegate; |
|||
|
|||
private WeakReference<IWeakSubscriber<T>>?[] _data = new WeakReference<IWeakSubscriber<T>>?[16]; |
|||
private int _count = 0; |
|||
|
|||
public Subscription(SubscriptionDic<T> sdic, Type targetType, object target, string eventName) |
|||
{ |
|||
_sdic = sdic; |
|||
_target = target; |
|||
_eventName = eventName; |
|||
if (!Accessors.TryGetValue(targetType, out var evDic)) |
|||
Accessors[targetType] = evDic = new Dictionary<string, EventInfo>(); |
|||
|
|||
if (evDic.TryGetValue(eventName, out var info)) |
|||
{ |
|||
_info = info; |
|||
} |
|||
else |
|||
{ |
|||
var ev = targetType.GetRuntimeEvents().FirstOrDefault(x => x.Name == eventName); |
|||
|
|||
if (ev == null) |
|||
{ |
|||
throw new ArgumentException( |
|||
$"The event {eventName} was not found on {target.GetType()}."); |
|||
} |
|||
|
|||
evDic[eventName] = _info = ev; |
|||
} |
|||
|
|||
var del = new Action<object, T>(OnEvent); |
|||
_delegate = del.GetMethodInfo().CreateDelegate(_info.EventHandlerType!, del.Target); |
|||
_info.AddMethod!.Invoke(target, new[] { _delegate }); |
|||
} |
|||
|
|||
void Destroy() |
|||
{ |
|||
_info.RemoveMethod!.Invoke(_target, new[] { _delegate }); |
|||
_sdic.Remove(_eventName); |
|||
} |
|||
|
|||
public void Add(WeakReference<IWeakSubscriber<T>> s) |
|||
{ |
|||
if (_count == _data.Length) |
|||
{ |
|||
//Extend capacity
|
|||
var ndata = new WeakReference<IWeakSubscriber<T>>?[_data.Length*2]; |
|||
Array.Copy(_data, ndata, _data.Length); |
|||
_data = ndata; |
|||
} |
|||
_data[_count] = s!; |
|||
_count++; |
|||
} |
|||
|
|||
public void Remove(IWeakSubscriber<T> s) |
|||
{ |
|||
var removed = false; |
|||
|
|||
for (int c = 0; c < _count; ++c) |
|||
{ |
|||
var reference = _data[c]; |
|||
IWeakSubscriber<T>? instance; |
|||
|
|||
if (reference != null && reference.TryGetTarget(out instance) && instance == s) |
|||
{ |
|||
_data[c] = null; |
|||
removed = true; |
|||
} |
|||
} |
|||
|
|||
if (removed) |
|||
{ |
|||
Compact(); |
|||
} |
|||
} |
|||
|
|||
void Compact() |
|||
{ |
|||
int empty = -1; |
|||
for (int c = 0; c < _count; c++) |
|||
{ |
|||
var r = _data[c]; |
|||
//Mark current index as first empty
|
|||
if (r == null && empty == -1) |
|||
empty = c; |
|||
//If current element isn't null and we have an empty one
|
|||
if (r != null && empty != -1) |
|||
{ |
|||
_data[c] = null; |
|||
_data[empty] = r; |
|||
empty++; |
|||
} |
|||
} |
|||
if (empty != -1) |
|||
_count = empty; |
|||
if (_count == 0) |
|||
Destroy(); |
|||
} |
|||
|
|||
void OnEvent(object sender, T eventArgs) |
|||
{ |
|||
var needCompact = false; |
|||
for(var c=0; c<_count; c++) |
|||
{ |
|||
var r = _data[c]; |
|||
if (r?.TryGetTarget(out var sub) == true) |
|||
sub!.OnEvent(sender, eventArgs); |
|||
else |
|||
needCompact = true; |
|||
} |
|||
if (needCompact) |
|||
Compact(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,19 +0,0 @@ |
|||
using System; |
|||
|
|||
namespace Avalonia.VisualTree |
|||
{ |
|||
/// <summary>
|
|||
/// Interface for controls that host their own separate visual tree, such as popups.
|
|||
/// </summary>
|
|||
[Obsolete] |
|||
public interface IVisualTreeHost |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the root of the hosted visual tree.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The root of the hosted visual tree.
|
|||
/// </value>
|
|||
IVisual? Root { get; } |
|||
} |
|||
} |
|||
@ -1,61 +0,0 @@ |
|||
using System; |
|||
using Avalonia.Controls.Shapes; |
|||
using Avalonia.Media; |
|||
using Avalonia.Metadata; |
|||
|
|||
namespace Avalonia.Controls |
|||
{ |
|||
[Obsolete("Use Image control with DrawingImage source")] |
|||
public class DrawingPresenter : Control |
|||
{ |
|||
static DrawingPresenter() |
|||
{ |
|||
AffectsMeasure<DrawingPresenter>(DrawingProperty); |
|||
AffectsRender<DrawingPresenter>(DrawingProperty); |
|||
} |
|||
|
|||
public static readonly StyledProperty<Drawing> DrawingProperty = |
|||
AvaloniaProperty.Register<DrawingPresenter, Drawing>(nameof(Drawing)); |
|||
|
|||
public static readonly StyledProperty<Stretch> StretchProperty = |
|||
AvaloniaProperty.Register<DrawingPresenter, Stretch>(nameof(Stretch), Stretch.Uniform); |
|||
|
|||
[Content] |
|||
public Drawing Drawing |
|||
{ |
|||
get => GetValue(DrawingProperty); |
|||
set => SetValue(DrawingProperty, value); |
|||
} |
|||
|
|||
public Stretch Stretch |
|||
{ |
|||
get => GetValue(StretchProperty); |
|||
set => SetValue(StretchProperty, value); |
|||
} |
|||
|
|||
private Matrix _transform = Matrix.Identity; |
|||
|
|||
protected override Size MeasureOverride(Size availableSize) |
|||
{ |
|||
if (Drawing == null) return new Size(); |
|||
|
|||
var (size, transform) = Shape.CalculateSizeAndTransform(availableSize, Drawing.GetBounds(), Stretch); |
|||
|
|||
_transform = transform; |
|||
|
|||
return size; |
|||
} |
|||
|
|||
public override void Render(DrawingContext context) |
|||
{ |
|||
if (Drawing != null) |
|||
{ |
|||
using (context.PushPreTransform(_transform)) |
|||
using (context.PushClip(new Rect(Bounds.Size))) |
|||
{ |
|||
Drawing.Draw(context); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,16 +1,7 @@ |
|||
using System; |
|||
|
|||
namespace Avalonia.Controls |
|||
namespace Avalonia.Controls |
|||
{ |
|||
|
|||
[Obsolete("This class exists to maintain backwards compatibility with existing code. Use NativeMenuItemSeparator instead")] |
|||
public class NativeMenuItemSeperator : NativeMenuItemSeparator |
|||
{ |
|||
} |
|||
|
|||
public class NativeMenuItemSeparator : NativeMenuItemBase |
|||
{ |
|||
[Obsolete("This is a temporary hack to make our MenuItem recognize this as a separator, don't use", true)] |
|||
public string Header => "-"; |
|||
|
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,97 @@ |
|||
using System; |
|||
using Avalonia.Media; |
|||
using Avalonia.Utilities; |
|||
|
|||
namespace Avalonia.Controls.Shapes |
|||
{ |
|||
/// <summary>
|
|||
/// Represents a circular or elliptical sector (a pie-shaped closed region of a circle or ellipse).
|
|||
/// </summary>
|
|||
public class Sector : Shape |
|||
{ |
|||
/// <summary>
|
|||
/// Defines the <see cref="StartAngle"/> property.
|
|||
/// </summary>
|
|||
public static readonly StyledProperty<double> StartAngleProperty = |
|||
AvaloniaProperty.Register<Sector, double>(nameof(StartAngle), 0.0d); |
|||
|
|||
/// <summary>
|
|||
/// Defines the <see cref="SweepAngle"/> property.
|
|||
/// </summary>
|
|||
public static readonly StyledProperty<double> SweepAngleProperty = |
|||
AvaloniaProperty.Register<Sector, double>(nameof(SweepAngle), 0.0d); |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the angle at which the sector's arc starts, in degrees.
|
|||
/// </summary>
|
|||
public double StartAngle |
|||
{ |
|||
get => GetValue(StartAngleProperty); |
|||
set => SetValue(StartAngleProperty, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the angle, in degrees, added to the <see cref="StartAngle"/> defining where the sector's arc ends.
|
|||
/// A positive value is clockwise, negative is counter-clockwise.
|
|||
/// </summary>
|
|||
public double SweepAngle |
|||
{ |
|||
get => GetValue(SweepAngleProperty); |
|||
set => SetValue(SweepAngleProperty, value); |
|||
} |
|||
|
|||
static Sector() |
|||
{ |
|||
StrokeThicknessProperty.OverrideDefaultValue<Sector>(1.0d); |
|||
AffectsGeometry<Sector>( |
|||
BoundsProperty, |
|||
StrokeThicknessProperty, |
|||
StartAngleProperty, |
|||
SweepAngleProperty); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override Geometry? CreateDefiningGeometry() |
|||
{ |
|||
Rect rect = new Rect(Bounds.Size); |
|||
Rect deflatedRect = rect.Deflate(StrokeThickness * 0.5d); |
|||
|
|||
if (SweepAngle >= 360.0d || SweepAngle <= -360.0d) |
|||
{ |
|||
return new EllipseGeometry(deflatedRect); |
|||
} |
|||
|
|||
if (SweepAngle == 0.0d) |
|||
{ |
|||
return new StreamGeometry(); |
|||
} |
|||
|
|||
(double startAngle, double endAngle) = MathUtilities.GetMinMaxFromDelta( |
|||
MathUtilities.Deg2Rad(StartAngle), |
|||
MathUtilities.Deg2Rad(SweepAngle)); |
|||
|
|||
Point centre = new Point(rect.Width * 0.5d, rect.Height * 0.5d); |
|||
double radiusX = deflatedRect.Width * 0.5d; |
|||
double radiusY = deflatedRect.Height * 0.5d; |
|||
Point startCurvePoint = MathUtilities.GetEllipsePoint(centre, radiusX, radiusY, startAngle); |
|||
Point endCurvePoint = MathUtilities.GetEllipsePoint(centre, radiusX, radiusY, endAngle); |
|||
Size size = new Size(radiusX, radiusY); |
|||
|
|||
var streamGeometry = new StreamGeometry(); |
|||
using (StreamGeometryContext context = streamGeometry.Open()) |
|||
{ |
|||
context.BeginFigure(startCurvePoint, false); |
|||
context.ArcTo( |
|||
endCurvePoint, |
|||
size, |
|||
rotationAngle: 0.0d, |
|||
isLargeArc: Math.Abs(SweepAngle) > 180.0d, |
|||
SweepDirection.Clockwise); |
|||
context.LineTo(centre); |
|||
context.EndFigure(true); |
|||
} |
|||
|
|||
return streamGeometry; |
|||
} |
|||
} |
|||
} |
|||
@ -1 +1 @@ |
|||
Subproject commit a4e6be2d1407abec4f35fcb208848830ce513ead |
|||
Subproject commit c1c0594ec2c35b08988183b1a5b3e34dfa19179d |
|||
@ -1,155 +0,0 @@ |
|||
using System.Linq; |
|||
using Avalonia.Collections; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Base.UnitTests.Collections |
|||
{ |
|||
public class AvaloniaListExtenionsTests |
|||
{ |
|||
#pragma warning disable CS0618 // Type or member is obsolete
|
|||
[Fact] |
|||
public void CreateDerivedList_Creates_Initial_Items() |
|||
{ |
|||
var source = new AvaloniaList<int>(new[] { 0, 1, 2, 3 }); |
|||
|
|||
var target = source.CreateDerivedList(x => new Wrapper(x)); |
|||
var result = target.Select(x => x.Value).ToList(); |
|||
|
|||
Assert.Equal(source, result); |
|||
} |
|||
|
|||
[Fact] |
|||
public void CreateDerivedList_Handles_Add() |
|||
{ |
|||
var source = new AvaloniaList<int>(new[] { 0, 1, 2, 3 }); |
|||
var target = source.CreateDerivedList(x => new Wrapper(x)); |
|||
|
|||
source.Add(4); |
|||
|
|||
var result = target.Select(x => x.Value).ToList(); |
|||
|
|||
Assert.Equal(source, result); |
|||
} |
|||
|
|||
[Fact] |
|||
public void CreateDerivedList_Handles_Insert() |
|||
{ |
|||
var source = new AvaloniaList<int>(new[] { 0, 1, 2, 3 }); |
|||
var target = source.CreateDerivedList(x => new Wrapper(x)); |
|||
|
|||
source.Insert(1, 4); |
|||
|
|||
var result = target.Select(x => x.Value).ToList(); |
|||
|
|||
Assert.Equal(source, result); |
|||
} |
|||
|
|||
[Fact] |
|||
public void CreateDerivedList_Handles_Remove() |
|||
{ |
|||
var source = new AvaloniaList<int>(new[] { 0, 1, 2, 3 }); |
|||
var target = source.CreateDerivedList(x => new Wrapper(x)); |
|||
|
|||
source.Remove(2); |
|||
|
|||
var result = target.Select(x => x.Value).ToList(); |
|||
|
|||
Assert.Equal(source, result); |
|||
} |
|||
|
|||
[Fact] |
|||
public void CreateDerivedList_Handles_RemoveRange() |
|||
{ |
|||
var source = new AvaloniaList<int>(new[] { 0, 1, 2, 3 }); |
|||
var target = source.CreateDerivedList(x => new Wrapper(x)); |
|||
|
|||
source.RemoveRange(1, 2); |
|||
|
|||
var result = target.Select(x => x.Value).ToList(); |
|||
|
|||
Assert.Equal(source, result); |
|||
} |
|||
|
|||
[Fact] |
|||
public void CreateDerivedList_Handles_Move() |
|||
{ |
|||
var source = new AvaloniaList<int>(new[] { 0, 1, 2, 3 }); |
|||
var target = source.CreateDerivedList(x => new Wrapper(x)); |
|||
|
|||
source.Move(2, 0); |
|||
|
|||
var result = target.Select(x => x.Value).ToList(); |
|||
|
|||
Assert.Equal(source, result); |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData(0, 2, 3)] |
|||
[InlineData(0, 2, 4)] |
|||
[InlineData(0, 2, 5)] |
|||
[InlineData(0, 4, 4)] |
|||
[InlineData(1, 2, 0)] |
|||
[InlineData(1, 2, 4)] |
|||
[InlineData(1, 2, 5)] |
|||
[InlineData(1, 4, 0)] |
|||
[InlineData(2, 2, 0)] |
|||
[InlineData(2, 2, 1)] |
|||
[InlineData(2, 2, 3)] |
|||
[InlineData(2, 2, 4)] |
|||
[InlineData(2, 2, 5)] |
|||
[InlineData(4, 2, 0)] |
|||
[InlineData(4, 2, 1)] |
|||
[InlineData(4, 2, 3)] |
|||
[InlineData(5, 1, 0)] |
|||
[InlineData(5, 1, 3)] |
|||
public void CreateDerivedList_Handles_MoveRange(int oldIndex, int count, int newIndex) |
|||
{ |
|||
var source = new AvaloniaList<int>(new[] { 0, 1, 2, 3, 4, 5 }); |
|||
var target = source.CreateDerivedList(x => new Wrapper(x)); |
|||
|
|||
source.MoveRange(oldIndex, count, newIndex); |
|||
|
|||
var result = target.Select(x => x.Value).ToList(); |
|||
|
|||
Assert.Equal(source, result); |
|||
} |
|||
|
|||
[Fact] |
|||
public void CreateDerivedList_Handles_Replace() |
|||
{ |
|||
var source = new AvaloniaList<int>(new[] { 0, 1, 2, 3 }); |
|||
var target = source.CreateDerivedList(x => new Wrapper(x)); |
|||
|
|||
source[1] = 4; |
|||
|
|||
var result = target.Select(x => x.Value).ToList(); |
|||
|
|||
Assert.Equal(source, result); |
|||
} |
|||
|
|||
[Fact] |
|||
public void CreateDerivedList_Handles_Clear() |
|||
{ |
|||
var source = new AvaloniaList<int>(new[] { 0, 1, 2, 3 }); |
|||
var target = source.CreateDerivedList(x => new Wrapper(x)); |
|||
|
|||
source.Clear(); |
|||
|
|||
var result = target.Select(x => x.Value).ToList(); |
|||
|
|||
Assert.Equal(source, result); |
|||
} |
|||
#pragma warning restore CS0618 // Type or member is obsolete
|
|||
|
|||
|
|||
private class Wrapper |
|||
{ |
|||
public Wrapper(int value) |
|||
{ |
|||
Value = value; |
|||
} |
|||
|
|||
public int Value { get; } |
|||
} |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue