From 238a4914d972f4122973b9d426ddce6bcea19aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Sat, 9 Jul 2016 16:26:28 +0200 Subject: [PATCH 1/8] Fix Skia SetFillRule Fixes #583 --- src/Skia/Avalonia.Skia/StreamGeometryImpl.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Skia/Avalonia.Skia/StreamGeometryImpl.cs b/src/Skia/Avalonia.Skia/StreamGeometryImpl.cs index 071c45c477..bde7a8ef9b 100644 --- a/src/Skia/Avalonia.Skia/StreamGeometryImpl.cs +++ b/src/Skia/Avalonia.Skia/StreamGeometryImpl.cs @@ -141,10 +141,8 @@ namespace Avalonia.Skia public void SetFillRule(FillRule fillRule) { - _geometryImpl.FillRule = fillRule; + _path.FillType = fillRule == FillRule.EvenOdd ? SKPathFillType.EvenOdd : SKPathFillType.Winding; } } - - public FillRule FillRule { get; set; } } } From cfd65240317e80a711b20683cf7f7284ab0b334e Mon Sep 17 00:00:00 2001 From: donandren Date: Tue, 12 Jul 2016 01:56:20 +0300 Subject: [PATCH 2/8] added failing unit test for issue #589 and #591 --- .../ListBoxTests.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs b/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs index 7e1347daf5..65d2e74d54 100644 --- a/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs @@ -234,6 +234,43 @@ namespace Avalonia.Controls.UnitTests target.Arrange(new Rect(0, 0, 100, 100)); } + [Fact] + public void ListBox_Set_SelectedItem_Should_Not_Crash_bug589_bug591() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var items = new[] { "Foo", "Bar", "Baz " }; + var target = new ListBox + { + Template = ListBoxTemplate() + }; + + Prepare(target); + + //emulate control is not in foreground or not visible + //also control can be child of parent with size 0,0 + //that's real case scenario although it looks bit unreal + target.Measure(new Size(0, 0)); + target.Arrange(new Rect(0, 0, 0, 0)); + + target.Items = items; + + //bug #591 in ItemVirtualizerSimple.cs:line 471 + //var container = generator.ContainerFromIndex(index); <- here container is null + //and NullReferenceException will be raised if LayoutManager is not null + //line 482 + //if (!new Rect(panel.Bounds.Size).Contains(container.Bounds)) <- this check will fail + + //bug #589 - currently this unit test is failing with + //IndexOutOfRangeException + // in CreateAndRemoveContainers() ItemVirtualizerSimple.cs:line 274 + //generator.Materialize(index, Items.ElementAt(index), memberSelector); <- index is -1 + target.SelectedItem = items.First(); + + Assert.Equal(items.First(), target.SelectedItem); + } + } + private class Item { public Item(string value) From 2e272ec4f5d563d2e327d2dc80609d197bbdec26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Sat, 16 Jul 2016 19:29:40 +0200 Subject: [PATCH 3/8] Added initial osx support to TravisCI build matrix --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bff594a46a..392beb90d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,7 @@ language: csharp +os: + - linux + - osx mono: - nightly solution: Avalonia.mono.sln @@ -6,7 +9,7 @@ before_install: - mkdir -p .nuget - wget -O .nuget/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe install: - - sudo apt-get install -y gtk-sharp2 + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install -y gtk-sharp2 ; fi - mono .nuget/nuget.exe restore Avalonia.mono.sln - mono .nuget/nuget.exe install xunit.runner.console -Version 2.1.0 -OutputDirectory testrunner script: From 282082a05ee188b59b9a46d6aa055fdfc78a5324 Mon Sep 17 00:00:00 2001 From: yusuf-gunaydin Date: Sun, 17 Jul 2016 18:03:12 +0300 Subject: [PATCH 4/8] Setter does not build the template if the target property derives from ITemplate. --- src/Avalonia.Styling/Styling/Setter.cs | 5 ++- .../Xaml/StyleTests.cs | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Styling/Styling/Setter.cs b/src/Avalonia.Styling/Styling/Setter.cs index 7f696a1f0a..d065b231ce 100644 --- a/src/Avalonia.Styling/Styling/Setter.cs +++ b/src/Avalonia.Styling/Styling/Setter.cs @@ -4,6 +4,7 @@ using System; using System.Reactive.Disposables; using System.Reactive.Subjects; +using System.Reflection; using Avalonia.Controls; using Avalonia.Data; using Avalonia.Metadata; @@ -98,8 +99,10 @@ namespace Avalonia.Styling if (binding == null) { var template = value as ITemplate; + bool isPropertyOfTypeITemplate = typeof(ITemplate).GetTypeInfo() + .IsAssignableFrom(Property.PropertyType.GetTypeInfo()); - if (template != null) + if (template != null && !isPropertyOfTypeITemplate) { var materialized = template.Build(); NameScope.SetNameScope((Visual)materialized, new NameScope()); diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs index b0451c951f..308a65dcd4 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs @@ -254,5 +254,36 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml Assert.Equal("Hello World!", ((TextBlock)target.Content).Text); } } + + [Fact] + public void Setter_Value_Is_Bound_Directly_If_The_Target_Type_Derives_From_ITemplate() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var xaml = @" + + + + + + +"; + + var loader = new AvaloniaXamlLoader(); + var window = (Window)loader.Load(xaml); + var target = window.Find("target"); + + Assert.NotNull(target.FocusAdorner); + } + } } } From 5ffdcf73da9bfa9ea062dbcb85eb50fccd86d587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Thu, 21 Jul 2016 08:30:47 +0200 Subject: [PATCH 5/8] Switch TravisCI to use mono latest instead of nightly This is related to this issue https://github.com/travis-ci/travis-ci/issues/6319, which is causing CI to fail installing mono runtime. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bff594a46a..5fbd9065f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: csharp mono: - - nightly + - latest solution: Avalonia.mono.sln before_install: - mkdir -p .nuget From dd728dae5b76aab80f12917b1a862f7da8ac3666 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 21 Jul 2016 14:34:13 -0600 Subject: [PATCH 6/8] Fix measuring to infinity when scrolled to end. When a virtualized list was scrolled to the bottom and then the list was measured with a size larger than needed to fit all items (in this case we use infinity) then the virtualizer tries to go backwards to add items at the top of the currently visible items by setting `step = -1`; however it didn't check whether the current index was < 0. Fixes #589. --- .../Presenters/ItemVirtualizerSimple.cs | 2 +- ...emsPresenterTests_Virtualization_Simple.cs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs b/src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs index a54e502033..bea9cb8a1a 100644 --- a/src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs +++ b/src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs @@ -252,7 +252,7 @@ namespace Avalonia.Controls.Presenters var index = NextIndex; var step = 1; - while (!panel.IsFull) + while (!panel.IsFull && index >= 0) { if (index >= ItemCount) { diff --git a/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs b/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs index 34b074d185..264c2b2e89 100644 --- a/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs +++ b/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs @@ -326,6 +326,27 @@ namespace Avalonia.Controls.UnitTests.Presenters Assert.Equal(expected, actual); } + [Fact] + public void Measuring_To_Infinity_When_Scrolled_To_End_Should_Not_Throw() + { + var target = CreateTarget(useAvaloniaList: true); + + target.ApplyTemplate(); + target.Measure(new Size(100, 100)); + target.Arrange(new Rect(0, 0, 100, 100)); + + ((ILogicalScrollable)target).Offset = new Vector(0, 10); + + // Check for issue #589: this should not throw. + target.Measure(Size.Infinity); + + var expected = Enumerable.Range(0, 20).Select(x => $"Item {x}").ToList(); + var items = (AvaloniaList)target.Items; + var actual = target.Panel.Children.Select(x => x.DataContext).ToList(); + + Assert.Equal(expected, actual); + } + [Fact] public void Replacing_Items_Should_Update_Containers() { From 1c88b3bd85d582b8883fa63b536620e3e8bcad4c Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 21 Jul 2016 14:40:51 -0600 Subject: [PATCH 7/8] Fix scrolling to item when size == 0,0 When virtualized presenter size == 0,0 no containers will be materialized so no container will be found. Fixes #591. --- .../Presenters/ItemVirtualizerSimple.cs | 2 +- ...ItemsPresenterTests_Virtualization_Simple.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs b/src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs index bea9cb8a1a..00d896925a 100644 --- a/src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs +++ b/src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs @@ -475,7 +475,7 @@ namespace Avalonia.Controls.Presenters // is only partially visible due to differing item sizes. If the container is only // partially visible, scroll again. Don't do this if there's no layout manager: // it means we're running a unit test. - if (layoutManager != null) + if (container != null && layoutManager != null) { layoutManager.ExecuteLayoutPass(); diff --git a/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs b/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs index 264c2b2e89..3ab5a928b4 100644 --- a/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs +++ b/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs @@ -505,6 +505,23 @@ namespace Avalonia.Controls.UnitTests.Presenters Assert.Equal(0, ((IVirtualizingPanel)target.Panel).PixelOffset); } + [Fact] + public void Scrolling_To_Item_In_Zero_Sized_Presenter_Doesnt_Throw() + { + using (UnitTestApplication.Start(TestServices.RealLayoutManager)) + { + var target = CreateTarget(itemCount: 10); + var items = (IList)target.Items; + + target.ApplyTemplate(); + target.Measure(Size.Empty); + target.Arrange(Rect.Empty); + + // Check for issue #591: this should not throw. + target.ScrollIntoView(items[0]); + } + } + public class Vertical { [Fact] From 6eaa5b74dc575987dc7fffde1e49fac4cb37bc6b Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 21 Jul 2016 14:42:14 -0600 Subject: [PATCH 8/8] Test has been refactored into 2 tests. Removed test that has been refactored into 2 separate tests. Thanks @donandren for finding those bugs! --- .../ListBoxTests.cs | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs b/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs index 65d2e74d54..7e1347daf5 100644 --- a/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs @@ -234,43 +234,6 @@ namespace Avalonia.Controls.UnitTests target.Arrange(new Rect(0, 0, 100, 100)); } - [Fact] - public void ListBox_Set_SelectedItem_Should_Not_Crash_bug589_bug591() - { - using (UnitTestApplication.Start(TestServices.StyledWindow)) - { - var items = new[] { "Foo", "Bar", "Baz " }; - var target = new ListBox - { - Template = ListBoxTemplate() - }; - - Prepare(target); - - //emulate control is not in foreground or not visible - //also control can be child of parent with size 0,0 - //that's real case scenario although it looks bit unreal - target.Measure(new Size(0, 0)); - target.Arrange(new Rect(0, 0, 0, 0)); - - target.Items = items; - - //bug #591 in ItemVirtualizerSimple.cs:line 471 - //var container = generator.ContainerFromIndex(index); <- here container is null - //and NullReferenceException will be raised if LayoutManager is not null - //line 482 - //if (!new Rect(panel.Bounds.Size).Contains(container.Bounds)) <- this check will fail - - //bug #589 - currently this unit test is failing with - //IndexOutOfRangeException - // in CreateAndRemoveContainers() ItemVirtualizerSimple.cs:line 274 - //generator.Materialize(index, Items.ElementAt(index), memberSelector); <- index is -1 - target.SelectedItem = items.First(); - - Assert.Equal(items.First(), target.SelectedItem); - } - } - private class Item { public Item(string value)