Artyom
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
77 additions and
2 deletions
-
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
-
src/Avalonia.Visuals/Rendering/DeferredRenderer.cs
-
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs
-
tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests.cs
|
|
|
@ -380,6 +380,7 @@ namespace Avalonia.Controls.Primitives |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
case NotifyCollectionChangedAction.Move: |
|
|
|
case NotifyCollectionChangedAction.Reset: |
|
|
|
SelectedIndex = IndexOf(Items, SelectedItem); |
|
|
|
break; |
|
|
|
|
|
|
|
@ -528,6 +528,8 @@ namespace Avalonia.Rendering |
|
|
|
oldScene?.Dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
_dirty.Clear(); |
|
|
|
|
|
|
|
if (SceneInvalidated != null) |
|
|
|
{ |
|
|
|
var rect = new Rect(); |
|
|
|
@ -540,10 +542,9 @@ namespace Avalonia.Rendering |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
System.Diagnostics.Debug.WriteLine("Invalidated " + rect); |
|
|
|
SceneInvalidated(this, new SceneInvalidatedEventArgs((IRenderRoot)_root, rect)); |
|
|
|
} |
|
|
|
|
|
|
|
_dirty.Clear(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
|
|
|
|
@ -341,6 +341,33 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
Assert.Equal(-1, target.SelectedIndex); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Moving_Selected_Item_Should_Update_Selection() |
|
|
|
{ |
|
|
|
var items = new AvaloniaList<Item> |
|
|
|
{ |
|
|
|
new Item(), |
|
|
|
new Item(), |
|
|
|
}; |
|
|
|
|
|
|
|
var target = new SelectingItemsControl |
|
|
|
{ |
|
|
|
Items = items, |
|
|
|
Template = Template(), |
|
|
|
}; |
|
|
|
|
|
|
|
target.ApplyTemplate(); |
|
|
|
target.SelectedIndex = 0; |
|
|
|
|
|
|
|
Assert.Equal(items[0], target.SelectedItem); |
|
|
|
Assert.Equal(0, target.SelectedIndex); |
|
|
|
|
|
|
|
items.Move(0, 1); |
|
|
|
|
|
|
|
Assert.Equal(items[1], target.SelectedItem); |
|
|
|
Assert.Equal(1, target.SelectedIndex); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Resetting_Items_Collection_Should_Clear_Selection() |
|
|
|
{ |
|
|
|
|
|
|
|
@ -325,6 +325,52 @@ namespace Avalonia.Visuals.UnitTests.Rendering |
|
|
|
context.Verify(x => x.DrawImage(borderLayer, 0.5, It.IsAny<Rect>(), It.IsAny<Rect>(), BitmapInterpolationMode.Default)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Can_Dirty_Control_In_SceneInvalidated() |
|
|
|
{ |
|
|
|
Border border1; |
|
|
|
Border border2; |
|
|
|
var root = new TestRoot |
|
|
|
{ |
|
|
|
Width = 100, |
|
|
|
Height = 100, |
|
|
|
Child = new StackPanel |
|
|
|
{ |
|
|
|
Children = |
|
|
|
{ |
|
|
|
(border1 = new Border |
|
|
|
{ |
|
|
|
Background = Brushes.Red, |
|
|
|
Child = new Canvas(), |
|
|
|
}), |
|
|
|
(border2 = new Border |
|
|
|
{ |
|
|
|
Background = Brushes.Red, |
|
|
|
Child = new Canvas(), |
|
|
|
}), |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
root.Measure(Size.Infinity); |
|
|
|
root.Arrange(new Rect(root.DesiredSize)); |
|
|
|
|
|
|
|
var target = CreateTargetAndRunFrame(root); |
|
|
|
var invalidated = false; |
|
|
|
|
|
|
|
target.SceneInvalidated += (s, e) => |
|
|
|
{ |
|
|
|
invalidated = true; |
|
|
|
target.AddDirty(border2); |
|
|
|
}; |
|
|
|
|
|
|
|
target.AddDirty(border1); |
|
|
|
target.Paint(new Rect(root.DesiredSize)); |
|
|
|
|
|
|
|
Assert.True(invalidated); |
|
|
|
Assert.True(((IRenderLoopTask)target).NeedsUpdate); |
|
|
|
} |
|
|
|
|
|
|
|
private DeferredRenderer CreateTargetAndRunFrame( |
|
|
|
TestRoot root, |
|
|
|
Mock<IRenderTimer> timer = null, |
|
|
|
|