Browse Source

Merge branch 'master' into alloc-boxing

pull/3066/head
Dariusz Komosiński 7 years ago
committed by GitHub
parent
commit
4245bf5d66
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/Avalonia.Animation/DisposeAnimationInstanceSubject.cs
  2. 19
      src/Avalonia.Base/PriorityLevel.cs
  3. 4
      src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
  4. 15
      src/Avalonia.Visuals/Media/PathMarkupParser.cs
  5. 37
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs
  6. 29
      tests/Avalonia.Visuals.UnitTests/Media/PathMarkupParserTests.cs

16
src/Avalonia.Animation/DisposeAnimationInstanceSubject.cs

@ -2,14 +2,7 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using Avalonia.Animation.Animators; using Avalonia.Animation.Animators;
using Avalonia.Animation.Utils;
using Avalonia.Collections;
using Avalonia.Data;
using Avalonia.Reactive;
namespace Avalonia.Animation namespace Avalonia.Animation
{ {
@ -46,6 +39,7 @@ namespace Avalonia.Animation
public void OnError(Exception error) public void OnError(Exception error)
{ {
_lastInstance?.Dispose(); _lastInstance?.Dispose();
_lastInstance = null;
} }
void IObserver<bool>.OnNext(bool matchVal) void IObserver<bool>.OnNext(bool matchVal)
@ -53,12 +47,18 @@ namespace Avalonia.Animation
if (matchVal != _lastMatch) if (matchVal != _lastMatch)
{ {
_lastInstance?.Dispose(); _lastInstance?.Dispose();
if (matchVal) if (matchVal)
{ {
_lastInstance = _animator.Run(_animation, _control, _clock, _onComplete); _lastInstance = _animator.Run(_animation, _control, _clock, _onComplete);
} }
else
{
_lastInstance = null;
}
_lastMatch = matchVal; _lastMatch = matchVal;
} }
} }
} }
} }

19
src/Avalonia.Base/PriorityLevel.cs

@ -3,7 +3,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reactive.Disposables; using System.Diagnostics;
using System.Threading;
using Avalonia.Data; using Avalonia.Data;
namespace Avalonia namespace Avalonia
@ -181,9 +182,9 @@ namespace Avalonia
private sealed class RemoveBindingDisposable : IDisposable private sealed class RemoveBindingDisposable : IDisposable
{ {
private readonly LinkedListNode<PriorityBindingEntry> _binding;
private readonly LinkedList<PriorityBindingEntry> _bindings; private readonly LinkedList<PriorityBindingEntry> _bindings;
private readonly PriorityLevel _priorityLevel; private readonly PriorityLevel _priorityLevel;
private LinkedListNode<PriorityBindingEntry> _binding;
public RemoveBindingDisposable( public RemoveBindingDisposable(
LinkedListNode<PriorityBindingEntry> binding, LinkedListNode<PriorityBindingEntry> binding,
@ -197,11 +198,21 @@ namespace Avalonia
public void Dispose() public void Dispose()
{ {
PriorityBindingEntry entry = _binding.Value; LinkedListNode<PriorityBindingEntry> binding = Interlocked.Exchange(ref _binding, null);
if (binding == null)
{
// Some system is trying to remove binding twice.
Debug.Assert(false);
return;
}
PriorityBindingEntry entry = binding.Value;
if (!entry.HasCompleted) if (!entry.HasCompleted)
{ {
_bindings.Remove(_binding); _bindings.Remove(binding);
entry.Dispose(); entry.Dispose();

4
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

@ -1088,7 +1088,9 @@ namespace Avalonia.Controls.Primitives
} }
else else
{ {
SelectedIndex = _updateSelectedIndex != int.MinValue ? _updateSelectedIndex : 0; SelectedIndex = _updateSelectedIndex != int.MinValue ?
_updateSelectedIndex :
AlwaysSelected ? 0 : -1;
} }
} }
} }

15
src/Avalonia.Visuals/Media/PathMarkupParser.cs

@ -32,6 +32,7 @@ namespace Avalonia.Media
private IGeometryContext _geometryContext; private IGeometryContext _geometryContext;
private Point _currentPoint; private Point _currentPoint;
private Point? _beginFigurePoint;
private Point? _previousControlPoint; private Point? _previousControlPoint;
private bool _isOpen; private bool _isOpen;
private bool _isDisposed; private bool _isDisposed;
@ -180,6 +181,8 @@ namespace Avalonia.Media
_geometryContext.BeginFigure(_currentPoint); _geometryContext.BeginFigure(_currentPoint);
_beginFigurePoint = _currentPoint;
_isOpen = true; _isOpen = true;
} }
@ -212,6 +215,12 @@ namespace Avalonia.Media
if (_isOpen) if (_isOpen)
{ {
_geometryContext.EndFigure(true); _geometryContext.EndFigure(true);
if (_beginFigurePoint != null)
{
_currentPoint = _beginFigurePoint.Value;
_beginFigurePoint = null;
}
} }
_previousControlPoint = null; _previousControlPoint = null;
@ -233,12 +242,6 @@ namespace Avalonia.Media
{ {
span = ReadSeparator(span); span = ReadSeparator(span);
AddLine(ref span, relative); AddLine(ref span, relative);
if (!relative)
{
_currentPoint = currentPoint;
CreateFigure();
}
} }
} }

37
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

@ -109,6 +109,43 @@ namespace Avalonia.Controls.UnitTests.Primitives
Assert.True(items[1].IsSelected); Assert.True(items[1].IsSelected);
} }
[Fact]
public void SelectedIndex_Should_Be_Minus_1_After_Initialize()
{
var items = new[]
{
new Item(),
new Item(),
};
var target = new ListBox();
target.BeginInit();
target.Items = items;
target.Template = Template();
target.EndInit();
Assert.Equal(-1, target.SelectedIndex);
}
[Fact]
public void SelectedIndex_Should_Be_0_After_Initialize_With_AlwaysSelected()
{
var items = new[]
{
new Item(),
new Item(),
};
var target = new ListBox();
target.BeginInit();
target.SelectionMode = SelectionMode.Single | SelectionMode.AlwaysSelected;
target.Items = items;
target.Template = Template();
target.EndInit();
Assert.Equal(0, target.SelectedIndex);
}
[Fact] [Fact]
public void Setting_SelectedIndex_During_Initialize_Should_Select_Item_When_AlwaysSelected_Is_Used() public void Setting_SelectedIndex_During_Initialize_Should_Select_Item_When_AlwaysSelected_Is_Used()
{ {

29
tests/Avalonia.Visuals.UnitTests/Media/PathMarkupParserTests.cs

@ -100,9 +100,7 @@ namespace Avalonia.Visuals.UnitTests.Media
Assert.Equal(new Point(10, 10), lineSegment.Point); Assert.Equal(new Point(10, 10), lineSegment.Point);
figure = pathGeometry.Figures[1]; segment = figure.Segments[1];
segment = figure.Segments[0];
Assert.IsType<LineSegment>(segment); Assert.IsType<LineSegment>(segment);
@ -235,5 +233,30 @@ namespace Avalonia.Visuals.UnitTests.Media
Assert.Throws<InvalidDataException>(() => parser.Parse(pathData)); Assert.Throws<InvalidDataException>(() => parser.Parse(pathData));
} }
} }
[Fact]
public void CloseFigure_Should_Move_CurrentPoint_To_CreateFigurePoint()
{
var pathGeometry = new PathGeometry();
using (var context = new PathGeometryContext(pathGeometry))
using (var parser = new PathMarkupParser(context))
{
parser.Parse("M10,10L100,100Z m10,10");
Assert.Equal(2, pathGeometry.Figures.Count);
var figure = pathGeometry.Figures[0];
Assert.Equal(new Point(10, 10), figure.StartPoint);
Assert.Equal(true, figure.IsClosed);
Assert.Equal(new Point(100, 100), ((LineSegment)figure.Segments[0]).Point);
figure = pathGeometry.Figures[1];
Assert.Equal(new Point(20, 20), figure.StartPoint);
}
}
} }
} }

Loading…
Cancel
Save