From f65ae1918f882e47cd04f14643a89b306f891ef2 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Sun, 10 Dec 2017 16:10:58 -0600 Subject: [PATCH 01/18] Change TransformedBounds to a direct property on Visual (exposed on IVisual) instead of using an attached property in BoundsTracker. --- .../Primitives/AdornerLayer.cs | 4 +- .../Rendering/ImmediateRenderer.cs | 9 ++-- .../Rendering/SceneGraph/SceneBuilder.cs | 12 ++--- src/Avalonia.Visuals/Visual.cs | 17 +++++++ .../VisualTree/BoundsTracker.cs | 51 ------------------- src/Avalonia.Visuals/VisualTree/IVisual.cs | 5 ++ ...ckerTests.cs => TransformedBoundsTests.cs} | 4 +- 7 files changed, 31 insertions(+), 71 deletions(-) delete mode 100644 src/Avalonia.Visuals/VisualTree/BoundsTracker.cs rename tests/Avalonia.Visuals.UnitTests/VisualTree/{BoundsTrackerTests.cs => TransformedBoundsTests.cs} (93%) diff --git a/src/Avalonia.Controls/Primitives/AdornerLayer.cs b/src/Avalonia.Controls/Primitives/AdornerLayer.cs index d7862881fb..a469f09867 100644 --- a/src/Avalonia.Controls/Primitives/AdornerLayer.cs +++ b/src/Avalonia.Controls/Primitives/AdornerLayer.cs @@ -18,8 +18,6 @@ namespace Avalonia.Controls.Primitives private static readonly AttachedProperty s_adornedElementInfoProperty = AvaloniaProperty.RegisterAttached("AdornedElementInfo"); - private readonly BoundsTracker _tracker = new BoundsTracker(); - static AdornerLayer() { AdornedElementProperty.Changed.Subscribe(AdornedElementChanged); @@ -118,7 +116,7 @@ namespace Avalonia.Controls.Primitives adorner.SetValue(s_adornedElementInfoProperty, info); } - info.Subscription = _tracker.Track(adorned).Subscribe(x => + info.Subscription = adorned.GetObservable(TransformedBoundsProperty).Subscribe(x => { info.Bounds = x; InvalidateArrange(); diff --git a/src/Avalonia.Visuals/Rendering/ImmediateRenderer.cs b/src/Avalonia.Visuals/Rendering/ImmediateRenderer.cs index 84313f0906..e830d5c313 100644 --- a/src/Avalonia.Visuals/Rendering/ImmediateRenderer.cs +++ b/src/Avalonia.Visuals/Rendering/ImmediateRenderer.cs @@ -169,7 +169,7 @@ namespace Avalonia.Rendering { foreach (var e in visual.GetSelfAndVisualDescendants()) { - BoundsTracker.SetTransformedBounds((Visual)visual, null); + visual.TransformedBounds = null; } } @@ -197,7 +197,7 @@ namespace Avalonia.Rendering if (filter?.Invoke(visual) != false) { - bool containsPoint = BoundsTracker.GetTransformedBounds((Visual)visual)?.Contains(p) == true; + bool containsPoint = visual.TransformedBounds?.Contains(p) == true; if ((containsPoint || !visual.ClipToBounds) && visual.VisualChildren.Count > 0) { @@ -257,10 +257,7 @@ namespace Avalonia.Rendering new TransformedBounds(bounds, new Rect(), context.CurrentContainerTransform); #pragma warning restore 0618 - if (visual is Visual) - { - BoundsTracker.SetTransformedBounds((Visual)visual, transformed); - } + visual.TransformedBounds = transformed; foreach (var child in visual.VisualChildren.OrderBy(x => x, ZIndexComparer.Instance)) { diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs index 8f4f487e08..41ff802164 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs @@ -209,11 +209,8 @@ namespace Avalonia.Rendering.SceneGraph } catch { } - if (visual is Visual) - { - var transformed = new TransformedBounds(new Rect(visual.Bounds.Size), clip, node.Transform); - BoundsTracker.SetTransformedBounds((Visual)visual, transformed); - } + var transformed = new TransformedBounds(new Rect(visual.Bounds.Size), clip, node.Transform); + visual.TransformedBounds = transformed; if (forceRecurse) { @@ -279,10 +276,7 @@ namespace Avalonia.Rendering.SceneGraph scene.Layers[node.LayerRoot].Dirty.Add(node.Bounds); - if (node.Visual is Visual v) - { - BoundsTracker.SetTransformedBounds(v, null); - } + node.Visual.TransformedBounds = null; foreach (VisualNode child in node.Children) { diff --git a/src/Avalonia.Visuals/Visual.cs b/src/Avalonia.Visuals/Visual.cs index 3662fe50be..5f3861a51a 100644 --- a/src/Avalonia.Visuals/Visual.cs +++ b/src/Avalonia.Visuals/Visual.cs @@ -32,6 +32,11 @@ namespace Avalonia public static readonly DirectProperty BoundsProperty = AvaloniaProperty.RegisterDirect(nameof(Bounds), o => o.Bounds); + public static readonly DirectProperty TransformedBoundsProperty = + AvaloniaProperty.RegisterDirect( + nameof(TransformedBounds), + o => o.TransformedBounds); + /// /// Defines the property. /// @@ -87,6 +92,7 @@ namespace Avalonia AvaloniaProperty.Register(nameof(ZIndex)); private Rect _bounds; + private TransformedBounds? _transformedBounds; private IRenderRoot _visualRoot; private IVisual _visualParent; @@ -135,6 +141,11 @@ namespace Avalonia protected set { SetAndRaise(BoundsProperty, ref _bounds, value); } } + /// + /// Gets the bounds of the control relative to the window, accounting for rendering transforms. + /// + public TransformedBounds? TransformedBounds => _transformedBounds; + /// /// Gets a value indicating whether the control should be clipped to its bounds. /// @@ -253,6 +264,12 @@ namespace Avalonia /// Gets the root of the visual tree, if the control is attached to a visual tree. /// IRenderRoot IVisual.VisualRoot => VisualRoot; + + TransformedBounds? IVisual.TransformedBounds + { + get { return _transformedBounds; } + set { SetAndRaise(TransformedBoundsProperty, ref _transformedBounds, value); } + } /// /// Invalidates the visual and queues a repaint. diff --git a/src/Avalonia.Visuals/VisualTree/BoundsTracker.cs b/src/Avalonia.Visuals/VisualTree/BoundsTracker.cs deleted file mode 100644 index 42c4e3c98e..0000000000 --- a/src/Avalonia.Visuals/VisualTree/BoundsTracker.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) The Avalonia Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -using System; - -namespace Avalonia.VisualTree -{ - /// - /// Tracks the bounds of a control. - /// - /// - /// This class is used to track a controls's bounds for hit testing. - /// TODO: This shouldn't be implemented as an attached property: it would be more performant - /// to just store bounds in some sort of central repository. - /// - public class BoundsTracker - { - /// - /// Defines the TransformedBounds attached property. - /// - private static AttachedProperty TransformedBoundsProperty = - AvaloniaProperty.RegisterAttached("TransformedBounds"); - - /// - /// Starts tracking the specified visual. - /// - /// The visual. - /// An observable that returns the tracked bounds. - public IObservable Track(Visual visual) - { - return visual.GetObservable(TransformedBoundsProperty); - } - - /// - /// Sets the transformed bounds of the visual. - /// - /// The visual. - /// The transformed bounds. - internal static void SetTransformedBounds(Visual visual, TransformedBounds? value) - { - visual.SetValue(TransformedBoundsProperty, value); - } - - /// - /// Gets the transformed bounds of the visual. - /// - /// The visual. - /// The transformed bounds or null if the visual is not visible. - public static TransformedBounds? GetTransformedBounds(Visual visual) => visual.GetValue(TransformedBoundsProperty); - } -} diff --git a/src/Avalonia.Visuals/VisualTree/IVisual.cs b/src/Avalonia.Visuals/VisualTree/IVisual.cs index 2047996c3e..278a802597 100644 --- a/src/Avalonia.Visuals/VisualTree/IVisual.cs +++ b/src/Avalonia.Visuals/VisualTree/IVisual.cs @@ -36,6 +36,11 @@ namespace Avalonia.VisualTree /// Rect Bounds { get; } + /// + /// Gets the bounds of the control relative to the window, accounting for rendering transforms. + /// + TransformedBounds? TransformedBounds { get; set; } + /// /// Gets a value indicating whether the control should be clipped to its bounds. /// diff --git a/tests/Avalonia.Visuals.UnitTests/VisualTree/BoundsTrackerTests.cs b/tests/Avalonia.Visuals.UnitTests/VisualTree/TransformedBoundsTests.cs similarity index 93% rename from tests/Avalonia.Visuals.UnitTests/VisualTree/BoundsTrackerTests.cs rename to tests/Avalonia.Visuals.UnitTests/VisualTree/TransformedBoundsTests.cs index ea3a1cdd78..aabaac902d 100644 --- a/tests/Avalonia.Visuals.UnitTests/VisualTree/BoundsTrackerTests.cs +++ b/tests/Avalonia.Visuals.UnitTests/VisualTree/TransformedBoundsTests.cs @@ -17,7 +17,7 @@ using Avalonia.Platform; namespace Avalonia.Visuals.UnitTests.VisualTree { - public class BoundsTrackerTests + public class TransformedBoundsTests { [Fact] public void Should_Track_Bounds() @@ -46,7 +46,7 @@ namespace Avalonia.Visuals.UnitTests.VisualTree tree.Arrange(new Rect(0, 0, 100, 100)); ImmediateRenderer.Render(tree, context); - var track = target.Track(control); + var track = control.GetObservable(Visual.TransformedBoundsProperty); var results = new List(); track.Subscribe(results.Add); From 39d5ac957fe99913b765d36d5d8d379389cc0dc3 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Sun, 10 Dec 2017 16:28:29 -0600 Subject: [PATCH 02/18] Fix test. --- .../VisualTree/TransformedBoundsTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Avalonia.Visuals.UnitTests/VisualTree/TransformedBoundsTests.cs b/tests/Avalonia.Visuals.UnitTests/VisualTree/TransformedBoundsTests.cs index aabaac902d..7bc0b72bef 100644 --- a/tests/Avalonia.Visuals.UnitTests/VisualTree/TransformedBoundsTests.cs +++ b/tests/Avalonia.Visuals.UnitTests/VisualTree/TransformedBoundsTests.cs @@ -24,7 +24,6 @@ namespace Avalonia.Visuals.UnitTests.VisualTree { using (UnitTestApplication.Start(TestServices.StyledWindow)) { - var target = new BoundsTracker(); var control = default(Rectangle); var tree = new Decorator { From 60a04fbd24e1d90f721d82481b6aaefe9d3ede1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro?= Date: Sun, 31 Dec 2017 19:33:04 +0000 Subject: [PATCH 03/18] Fixed ToggleButton.IsChecked default value. --- src/Avalonia.Controls/Primitives/ToggleButton.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Avalonia.Controls/Primitives/ToggleButton.cs b/src/Avalonia.Controls/Primitives/ToggleButton.cs index 7d500975f0..dc9b70ab8c 100644 --- a/src/Avalonia.Controls/Primitives/ToggleButton.cs +++ b/src/Avalonia.Controls/Primitives/ToggleButton.cs @@ -14,6 +14,7 @@ namespace Avalonia.Controls.Primitives nameof(IsChecked), o => o.IsChecked, (o, v) => o.IsChecked = v, + unsetValue: false, defaultBindingMode: BindingMode.TwoWay); public static readonly StyledProperty IsThreeStateProperty = From 7cccc6bda01d47d2d26bfbcd27806740d1dad90d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro?= Date: Mon, 1 Jan 2018 21:51:55 +0000 Subject: [PATCH 04/18] Use nameof where possible. --- src/Avalonia.Controls/Carousel.cs | 2 +- src/Avalonia.Controls/ColumnDefinition.cs | 6 +++--- src/Avalonia.Controls/DropDown.cs | 2 +- .../Primitives/HeaderedContentControl.cs | 2 +- .../Primitives/TemplatedControl.cs | 2 +- src/Avalonia.Controls/Primitives/Thumb.cs | 6 +++--- src/Avalonia.Controls/RowDefinition.cs | 6 +++--- src/Avalonia.Controls/Shapes/Line.cs | 4 ++-- src/Avalonia.Controls/Shapes/Path.cs | 2 +- src/Avalonia.Controls/Shapes/Shape.cs | 8 ++++---- src/Avalonia.Controls/TextBox.cs | 10 +++++----- .../Views/ControlDetailsView.cs | 2 +- src/Avalonia.HtmlRenderer/HtmlControl.cs | 16 ++++++++-------- src/Avalonia.Input/InputElement.cs | 18 +++++++++--------- src/Avalonia.Input/KeyBinding.cs | 6 +++--- src/Avalonia.Visuals/Media/Geometry.cs | 2 +- src/Avalonia.Visuals/Media/ImageBrush.cs | 2 +- src/Avalonia.Visuals/Media/MatrixTransform.cs | 2 +- src/Avalonia.Visuals/Media/RotateTransform.cs | 2 +- .../Media/TranslateTransform.cs | 4 ++-- src/Avalonia.Visuals/Media/VisualBrush.cs | 2 +- .../AvaloniaObjectTests_Direct.cs | 6 +++--- .../AvaloniaObjectTests_GetSubject.cs | 2 +- .../DirectPropertyTests.cs | 2 +- ...ExpressionObserverTests_AttachedProperty.cs | 2 +- .../Data/BindingTests.cs | 2 +- .../Xaml/NonControl.cs | 6 +++--- tests/Avalonia.Styling.UnitTests/StyleTests.cs | 2 +- 28 files changed, 64 insertions(+), 64 deletions(-) diff --git a/src/Avalonia.Controls/Carousel.cs b/src/Avalonia.Controls/Carousel.cs index 71446c627f..e7c934091a 100644 --- a/src/Avalonia.Controls/Carousel.cs +++ b/src/Avalonia.Controls/Carousel.cs @@ -24,7 +24,7 @@ namespace Avalonia.Controls /// Defines the property. /// public static readonly StyledProperty TransitionProperty = - AvaloniaProperty.Register("Transition"); + AvaloniaProperty.Register(nameof(Transition)); /// /// The default value of for diff --git a/src/Avalonia.Controls/ColumnDefinition.cs b/src/Avalonia.Controls/ColumnDefinition.cs index 36fadd0f05..a6b34f8a16 100644 --- a/src/Avalonia.Controls/ColumnDefinition.cs +++ b/src/Avalonia.Controls/ColumnDefinition.cs @@ -12,19 +12,19 @@ namespace Avalonia.Controls /// Defines the property. /// public static readonly StyledProperty MaxWidthProperty = - AvaloniaProperty.Register("MaxWidth", double.PositiveInfinity); + AvaloniaProperty.Register(nameof(MaxWidth), double.PositiveInfinity); /// /// Defines the property. /// public static readonly StyledProperty MinWidthProperty = - AvaloniaProperty.Register("MinWidth"); + AvaloniaProperty.Register(nameof(MinWidth)); /// /// Defines the property. /// public static readonly StyledProperty WidthProperty = - AvaloniaProperty.Register("Width", new GridLength(1, GridUnitType.Star)); + AvaloniaProperty.Register(nameof(Width), new GridLength(1, GridUnitType.Star)); /// /// Initializes a new instance of the class. diff --git a/src/Avalonia.Controls/DropDown.cs b/src/Avalonia.Controls/DropDown.cs index 6b27c479ba..a7ea2da4a4 100644 --- a/src/Avalonia.Controls/DropDown.cs +++ b/src/Avalonia.Controls/DropDown.cs @@ -38,7 +38,7 @@ namespace Avalonia.Controls /// Defines the property. /// public static readonly DirectProperty SelectionBoxItemProperty = - AvaloniaProperty.RegisterDirect("SelectionBoxItem", o => o.SelectionBoxItem); + AvaloniaProperty.RegisterDirect(nameof(SelectionBoxItem), o => o.SelectionBoxItem); private bool _isDropDownOpen; private Popup _popup; diff --git a/src/Avalonia.Controls/Primitives/HeaderedContentControl.cs b/src/Avalonia.Controls/Primitives/HeaderedContentControl.cs index a2de1fbf0e..d67ebfd489 100644 --- a/src/Avalonia.Controls/Primitives/HeaderedContentControl.cs +++ b/src/Avalonia.Controls/Primitives/HeaderedContentControl.cs @@ -12,7 +12,7 @@ namespace Avalonia.Controls.Primitives /// Defines the property. /// public static readonly StyledProperty HeaderProperty = - AvaloniaProperty.Register("Header"); + AvaloniaProperty.Register(nameof(Header)); /// /// Gets or sets the header content. diff --git a/src/Avalonia.Controls/Primitives/TemplatedControl.cs b/src/Avalonia.Controls/Primitives/TemplatedControl.cs index 1ddfb97c14..6deef7c7b9 100644 --- a/src/Avalonia.Controls/Primitives/TemplatedControl.cs +++ b/src/Avalonia.Controls/Primitives/TemplatedControl.cs @@ -75,7 +75,7 @@ namespace Avalonia.Controls.Primitives /// Defines the property. /// public static readonly StyledProperty TemplateProperty = - AvaloniaProperty.Register("Template"); + AvaloniaProperty.Register(nameof(Template)); /// /// Defines the IsTemplateFocusTarget attached property. diff --git a/src/Avalonia.Controls/Primitives/Thumb.cs b/src/Avalonia.Controls/Primitives/Thumb.cs index 065b1aedbe..da4dc63d1e 100644 --- a/src/Avalonia.Controls/Primitives/Thumb.cs +++ b/src/Avalonia.Controls/Primitives/Thumb.cs @@ -11,13 +11,13 @@ namespace Avalonia.Controls.Primitives public class Thumb : TemplatedControl { public static readonly RoutedEvent DragStartedEvent = - RoutedEvent.Register("DragStarted", RoutingStrategies.Bubble); + RoutedEvent.Register(nameof(DragStarted), RoutingStrategies.Bubble); public static readonly RoutedEvent DragDeltaEvent = - RoutedEvent.Register("DragDelta", RoutingStrategies.Bubble); + RoutedEvent.Register(nameof(DragDelta), RoutingStrategies.Bubble); public static readonly RoutedEvent DragCompletedEvent = - RoutedEvent.Register("DragCompleted", RoutingStrategies.Bubble); + RoutedEvent.Register(nameof(DragCompleted), RoutingStrategies.Bubble); private Point? _lastPoint; diff --git a/src/Avalonia.Controls/RowDefinition.cs b/src/Avalonia.Controls/RowDefinition.cs index 265cede17f..7307843417 100644 --- a/src/Avalonia.Controls/RowDefinition.cs +++ b/src/Avalonia.Controls/RowDefinition.cs @@ -12,19 +12,19 @@ namespace Avalonia.Controls /// Defines the property. /// public static readonly StyledProperty MaxHeightProperty = - AvaloniaProperty.Register("MaxHeight", double.PositiveInfinity); + AvaloniaProperty.Register(nameof(MaxHeight), double.PositiveInfinity); /// /// Defines the property. /// public static readonly StyledProperty MinHeightProperty = - AvaloniaProperty.Register("MinHeight"); + AvaloniaProperty.Register(nameof(MinHeight)); /// /// Defines the property. /// public static readonly StyledProperty HeightProperty = - AvaloniaProperty.Register("Height", new GridLength(1, GridUnitType.Star)); + AvaloniaProperty.Register(nameof(Height), new GridLength(1, GridUnitType.Star)); /// /// Initializes a new instance of the class. diff --git a/src/Avalonia.Controls/Shapes/Line.cs b/src/Avalonia.Controls/Shapes/Line.cs index 922597e5bf..b06fe40710 100644 --- a/src/Avalonia.Controls/Shapes/Line.cs +++ b/src/Avalonia.Controls/Shapes/Line.cs @@ -8,10 +8,10 @@ namespace Avalonia.Controls.Shapes public class Line : Shape { public static readonly StyledProperty StartPointProperty = - AvaloniaProperty.Register("StartPoint"); + AvaloniaProperty.Register(nameof(StartPoint)); public static readonly StyledProperty EndPointProperty = - AvaloniaProperty.Register("EndPoint"); + AvaloniaProperty.Register(nameof(EndPoint)); static Line() { diff --git a/src/Avalonia.Controls/Shapes/Path.cs b/src/Avalonia.Controls/Shapes/Path.cs index a337e7c6de..08bed79b3a 100644 --- a/src/Avalonia.Controls/Shapes/Path.cs +++ b/src/Avalonia.Controls/Shapes/Path.cs @@ -9,7 +9,7 @@ namespace Avalonia.Controls.Shapes public class Path : Shape { public static readonly StyledProperty DataProperty = - AvaloniaProperty.Register("Data"); + AvaloniaProperty.Register(nameof(Data)); static Path() { diff --git a/src/Avalonia.Controls/Shapes/Shape.cs b/src/Avalonia.Controls/Shapes/Shape.cs index 73b89ca4b7..2ea681891d 100644 --- a/src/Avalonia.Controls/Shapes/Shape.cs +++ b/src/Avalonia.Controls/Shapes/Shape.cs @@ -12,19 +12,19 @@ namespace Avalonia.Controls.Shapes public abstract class Shape : Control { public static readonly StyledProperty FillProperty = - AvaloniaProperty.Register("Fill"); + AvaloniaProperty.Register(nameof(Fill)); public static readonly StyledProperty StretchProperty = - AvaloniaProperty.Register("Stretch"); + AvaloniaProperty.Register(nameof(Stretch)); public static readonly StyledProperty StrokeProperty = - AvaloniaProperty.Register("Stroke"); + AvaloniaProperty.Register(nameof(Stroke)); public static readonly StyledProperty> StrokeDashArrayProperty = AvaloniaProperty.Register>("StrokeDashArray"); public static readonly StyledProperty StrokeThicknessProperty = - AvaloniaProperty.Register("StrokeThickness"); + AvaloniaProperty.Register(nameof(StrokeThickness)); private Matrix _transform = Matrix.Identity; private Geometry _definingGeometry; diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 36ef8d05c3..1a663ed3b6 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -21,13 +21,13 @@ namespace Avalonia.Controls public class TextBox : TemplatedControl, UndoRedoHelper.IUndoRedoHost { public static readonly StyledProperty AcceptsReturnProperty = - AvaloniaProperty.Register("AcceptsReturn"); + AvaloniaProperty.Register(nameof(AcceptsReturn)); public static readonly StyledProperty AcceptsTabProperty = - AvaloniaProperty.Register("AcceptsTab"); + AvaloniaProperty.Register(nameof(AcceptsTab)); public static readonly DirectProperty CanScrollHorizontallyProperty = - AvaloniaProperty.RegisterDirect("CanScrollHorizontally", o => o.CanScrollHorizontally); + AvaloniaProperty.RegisterDirect(nameof(CanScrollHorizontally), o => o.CanScrollHorizontally); public static readonly DirectProperty CaretIndexProperty = AvaloniaProperty.RegisterDirect( @@ -69,10 +69,10 @@ namespace Avalonia.Controls TextBlock.TextWrappingProperty.AddOwner(); public static readonly StyledProperty WatermarkProperty = - AvaloniaProperty.Register("Watermark"); + AvaloniaProperty.Register(nameof(Watermark)); public static readonly StyledProperty UseFloatingWatermarkProperty = - AvaloniaProperty.Register("UseFloatingWatermark"); + AvaloniaProperty.Register(nameof(UseFloatingWatermark)); struct UndoRedoState : IEquatable { diff --git a/src/Avalonia.Diagnostics/Views/ControlDetailsView.cs b/src/Avalonia.Diagnostics/Views/ControlDetailsView.cs index e58818d31d..381b2e04b4 100644 --- a/src/Avalonia.Diagnostics/Views/ControlDetailsView.cs +++ b/src/Avalonia.Diagnostics/Views/ControlDetailsView.cs @@ -14,7 +14,7 @@ namespace Avalonia.Diagnostics.Views internal class ControlDetailsView : UserControl { private static readonly StyledProperty ViewModelProperty = - AvaloniaProperty.Register("ViewModel"); + AvaloniaProperty.Register(nameof(ViewModel)); private SimpleGrid _grid; public ControlDetailsView() diff --git a/src/Avalonia.HtmlRenderer/HtmlControl.cs b/src/Avalonia.HtmlRenderer/HtmlControl.cs index 0051f6427b..94b2d56f5f 100644 --- a/src/Avalonia.HtmlRenderer/HtmlControl.cs +++ b/src/Avalonia.HtmlRenderer/HtmlControl.cs @@ -74,29 +74,29 @@ namespace Avalonia.Controls.Html protected Point _lastScrollOffset; public static readonly AvaloniaProperty AvoidImagesLateLoadingProperty = - PropertyHelper.Register("AvoidImagesLateLoading", false, OnAvaloniaProperty_valueChanged); + PropertyHelper.Register(nameof(AvoidImagesLateLoading), false, OnAvaloniaProperty_valueChanged); public static readonly AvaloniaProperty IsSelectionEnabledProperty = - PropertyHelper.Register("IsSelectionEnabled", true, OnAvaloniaProperty_valueChanged); + PropertyHelper.Register(nameof(IsSelectionEnabled), true, OnAvaloniaProperty_valueChanged); public static readonly AvaloniaProperty IsContextMenuEnabledProperty = - PropertyHelper.Register("IsContextMenuEnabled", true, OnAvaloniaProperty_valueChanged); + PropertyHelper.Register(nameof(IsContextMenuEnabled), true, OnAvaloniaProperty_valueChanged); public static readonly AvaloniaProperty BaseStylesheetProperty = - PropertyHelper.Register("BaseStylesheet", null, OnAvaloniaProperty_valueChanged); + PropertyHelper.Register(nameof(BaseStylesheet), null, OnAvaloniaProperty_valueChanged); public static readonly AvaloniaProperty TextProperty = - PropertyHelper.Register("Text", null, OnAvaloniaProperty_valueChanged); + PropertyHelper.Register(nameof(Text), null, OnAvaloniaProperty_valueChanged); public static readonly StyledProperty BackgroundProperty = Border.BackgroundProperty.AddOwner(); public static readonly AvaloniaProperty BorderThicknessProperty = - AvaloniaProperty.Register("BorderThickness", new Thickness(0)); + AvaloniaProperty.Register(nameof(BorderThickness), new Thickness(0)); public static readonly AvaloniaProperty BorderBrushProperty = - AvaloniaProperty.Register("BorderBrush"); + AvaloniaProperty.Register(nameof(BorderBrush)); public static readonly AvaloniaProperty PaddingProperty = - AvaloniaProperty.Register("Padding", new Thickness(0)); + AvaloniaProperty.Register(nameof(Padding), new Thickness(0)); public static readonly RoutedEvent LoadCompleteEvent = RoutedEvent.Register("LoadComplete", RoutingStrategies.Bubble, typeof(HtmlControl)); diff --git a/src/Avalonia.Input/InputElement.cs b/src/Avalonia.Input/InputElement.cs index 6385f7197b..8ac49df4cd 100644 --- a/src/Avalonia.Input/InputElement.cs +++ b/src/Avalonia.Input/InputElement.cs @@ -31,43 +31,43 @@ namespace Avalonia.Input /// Defines the property. /// public static readonly StyledProperty IsEnabledCoreProperty = - AvaloniaProperty.Register("IsEnabledCore", true); + AvaloniaProperty.Register(nameof(IsEnabledCore), true); /// /// Gets or sets associated mouse cursor. /// public static readonly StyledProperty CursorProperty = - AvaloniaProperty.Register("Cursor", null, true); + AvaloniaProperty.Register(nameof(Cursor), null, true); /// /// Defines the property. /// public static readonly DirectProperty IsFocusedProperty = - AvaloniaProperty.RegisterDirect("IsFocused", o => o.IsFocused); + AvaloniaProperty.RegisterDirect(nameof(IsFocused), o => o.IsFocused); /// /// Defines the property. /// public static readonly StyledProperty IsHitTestVisibleProperty = - AvaloniaProperty.Register("IsHitTestVisible", true); + AvaloniaProperty.Register(nameof(IsHitTestVisible), true); /// /// Defines the property. /// public static readonly DirectProperty IsPointerOverProperty = - AvaloniaProperty.RegisterDirect("IsPointerOver", o => o.IsPointerOver); + AvaloniaProperty.RegisterDirect(nameof(IsPointerOver), o => o.IsPointerOver); /// /// Defines the event. /// public static readonly RoutedEvent GotFocusEvent = - RoutedEvent.Register("GotFocus", RoutingStrategies.Bubble); + RoutedEvent.Register(nameof(GotFocus), RoutingStrategies.Bubble); /// /// Defines the event. /// public static readonly RoutedEvent LostFocusEvent = - RoutedEvent.Register("LostFocus", RoutingStrategies.Bubble); + RoutedEvent.Register(nameof(LostFocus), RoutingStrategies.Bubble); /// /// Defines the event. @@ -97,13 +97,13 @@ namespace Avalonia.Input /// Defines the event. /// public static readonly RoutedEvent PointerEnterEvent = - RoutedEvent.Register("PointerEnter", RoutingStrategies.Direct); + RoutedEvent.Register(nameof(PointerEnter), RoutingStrategies.Direct); /// /// Defines the event. /// public static readonly RoutedEvent PointerLeaveEvent = - RoutedEvent.Register("PointerLeave", RoutingStrategies.Direct); + RoutedEvent.Register(nameof(PointerLeave), RoutingStrategies.Direct); /// /// Defines the event. diff --git a/src/Avalonia.Input/KeyBinding.cs b/src/Avalonia.Input/KeyBinding.cs index a14f87beb1..035b6978f4 100644 --- a/src/Avalonia.Input/KeyBinding.cs +++ b/src/Avalonia.Input/KeyBinding.cs @@ -10,7 +10,7 @@ namespace Avalonia.Input public class KeyBinding : AvaloniaObject { public static readonly StyledProperty CommandProperty = - AvaloniaProperty.Register("Command"); + AvaloniaProperty.Register(nameof(Command)); public ICommand Command { @@ -19,7 +19,7 @@ namespace Avalonia.Input } public static readonly StyledProperty CommandParameterProperty = - AvaloniaProperty.Register("CommandParameter"); + AvaloniaProperty.Register(nameof(CommandParameter)); public object CommandParameter { @@ -28,7 +28,7 @@ namespace Avalonia.Input } public static readonly StyledProperty GestureProperty = - AvaloniaProperty.Register("Gesture"); + AvaloniaProperty.Register(nameof(Gesture)); public KeyGesture Gesture { diff --git a/src/Avalonia.Visuals/Media/Geometry.cs b/src/Avalonia.Visuals/Media/Geometry.cs index 591c7d0468..d27626bcc1 100644 --- a/src/Avalonia.Visuals/Media/Geometry.cs +++ b/src/Avalonia.Visuals/Media/Geometry.cs @@ -15,7 +15,7 @@ namespace Avalonia.Media /// Defines the property. /// public static readonly StyledProperty TransformProperty = - AvaloniaProperty.Register("Transform"); + AvaloniaProperty.Register(nameof(Transform)); /// /// Initializes static members of the class. diff --git a/src/Avalonia.Visuals/Media/ImageBrush.cs b/src/Avalonia.Visuals/Media/ImageBrush.cs index 69b98fd35c..fa491ed3e1 100644 --- a/src/Avalonia.Visuals/Media/ImageBrush.cs +++ b/src/Avalonia.Visuals/Media/ImageBrush.cs @@ -14,7 +14,7 @@ namespace Avalonia.Media /// Defines the property. /// public static readonly StyledProperty SourceProperty = - AvaloniaProperty.Register("Source"); + AvaloniaProperty.Register(nameof(Source)); /// /// Initializes a new instance of the class. diff --git a/src/Avalonia.Visuals/Media/MatrixTransform.cs b/src/Avalonia.Visuals/Media/MatrixTransform.cs index 1507720305..247a26dac1 100644 --- a/src/Avalonia.Visuals/Media/MatrixTransform.cs +++ b/src/Avalonia.Visuals/Media/MatrixTransform.cs @@ -15,7 +15,7 @@ namespace Avalonia.Media /// Defines the property. /// public static readonly StyledProperty MatrixProperty = - AvaloniaProperty.Register("Matrix", Matrix.Identity); + AvaloniaProperty.Register(nameof(Matrix), Matrix.Identity); /// /// Initializes a new instance of the class. diff --git a/src/Avalonia.Visuals/Media/RotateTransform.cs b/src/Avalonia.Visuals/Media/RotateTransform.cs index 41f2335ced..4fe615a6df 100644 --- a/src/Avalonia.Visuals/Media/RotateTransform.cs +++ b/src/Avalonia.Visuals/Media/RotateTransform.cs @@ -15,7 +15,7 @@ namespace Avalonia.Media /// Defines the property. /// public static readonly StyledProperty AngleProperty = - AvaloniaProperty.Register("Angle"); + AvaloniaProperty.Register(nameof(Angle)); /// /// Initializes a new instance of the class. diff --git a/src/Avalonia.Visuals/Media/TranslateTransform.cs b/src/Avalonia.Visuals/Media/TranslateTransform.cs index 0c9ca5debc..b66ca7939c 100644 --- a/src/Avalonia.Visuals/Media/TranslateTransform.cs +++ b/src/Avalonia.Visuals/Media/TranslateTransform.cs @@ -15,13 +15,13 @@ namespace Avalonia.Media /// Defines the property. /// public static readonly StyledProperty XProperty = - AvaloniaProperty.Register("X"); + AvaloniaProperty.Register(nameof(X)); /// /// Defines the property. /// public static readonly StyledProperty YProperty = - AvaloniaProperty.Register("Y"); + AvaloniaProperty.Register(nameof(Y)); /// /// Initializes a new instance of the class. diff --git a/src/Avalonia.Visuals/Media/VisualBrush.cs b/src/Avalonia.Visuals/Media/VisualBrush.cs index a6d2b8ae8f..435f4ba1b1 100644 --- a/src/Avalonia.Visuals/Media/VisualBrush.cs +++ b/src/Avalonia.Visuals/Media/VisualBrush.cs @@ -14,7 +14,7 @@ namespace Avalonia.Media /// Defines the property. /// public static readonly StyledProperty VisualProperty = - AvaloniaProperty.Register("Visual"); + AvaloniaProperty.Register(nameof(Visual)); /// /// Initializes a new instance of the class. diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs index f415d845ce..5cc5bae8b0 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs @@ -506,17 +506,17 @@ namespace Avalonia.Base.UnitTests { public static readonly DirectProperty FooProperty = AvaloniaProperty.RegisterDirect( - "Foo", + nameof(Foo), o => o.Foo, (o, v) => o.Foo = v, unsetValue: "unset"); public static readonly DirectProperty BarProperty = - AvaloniaProperty.RegisterDirect("Bar", o => o.Bar); + AvaloniaProperty.RegisterDirect(nameof(Bar), o => o.Bar); public static readonly DirectProperty BazProperty = AvaloniaProperty.RegisterDirect( - "Bar", + nameof(Baz), o => o.Baz, (o, v) => o.Baz = v, unsetValue: -1); diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_GetSubject.cs b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_GetSubject.cs index ec872e7cc0..bb6df0e4fb 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_GetSubject.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_GetSubject.cs @@ -37,7 +37,7 @@ namespace Avalonia.Base.UnitTests private class Class1 : AvaloniaObject { public static readonly StyledProperty FooProperty = - AvaloniaProperty.Register("Foo", "foodefault"); + AvaloniaProperty.Register(nameof(Foo), "foodefault"); public string Foo { diff --git a/tests/Avalonia.Base.UnitTests/DirectPropertyTests.cs b/tests/Avalonia.Base.UnitTests/DirectPropertyTests.cs index 84ff492512..fe7186e417 100644 --- a/tests/Avalonia.Base.UnitTests/DirectPropertyTests.cs +++ b/tests/Avalonia.Base.UnitTests/DirectPropertyTests.cs @@ -85,7 +85,7 @@ namespace Avalonia.Base.UnitTests private class Class1 : AvaloniaObject { public static readonly DirectProperty FooProperty = - AvaloniaProperty.RegisterDirect("Foo", o => o.Foo, (o, v) => o.Foo = v); + AvaloniaProperty.RegisterDirect(nameof(Foo), o => o.Foo, (o, v) => o.Foo = v); private string _foo = "foo"; diff --git a/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_AttachedProperty.cs b/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_AttachedProperty.cs index a8069cb75c..5ddff63a0c 100644 --- a/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_AttachedProperty.cs +++ b/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_AttachedProperty.cs @@ -136,7 +136,7 @@ namespace Avalonia.Markup.UnitTests.Data private class Class1 : AvaloniaObject { public static readonly StyledProperty NextProperty = - AvaloniaProperty.Register("Next"); + AvaloniaProperty.Register(nameof(Next)); public Class1 Next { diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests.cs index 71c5385c23..c6f89e07a6 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests.cs @@ -558,7 +558,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Data private class InheritanceTest : Decorator { public static readonly StyledProperty BazProperty = - AvaloniaProperty.Register("Baz", defaultValue: 6, inherits: true); + AvaloniaProperty.Register(nameof(Baz), defaultValue: 6, inherits: true); public int Baz { diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/NonControl.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/NonControl.cs index 7562084072..7a728203e6 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/NonControl.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/NonControl.cs @@ -8,10 +8,10 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml public class NonControl : AvaloniaObject { public static readonly StyledProperty ControlProperty = - AvaloniaProperty.Register("Control"); + AvaloniaProperty.Register(nameof(Control)); public static readonly StyledProperty StringProperty = - AvaloniaProperty.Register("String"); + AvaloniaProperty.Register(nameof(String)); //No getter or setter Avalonia property public static readonly StyledProperty FooProperty = @@ -19,7 +19,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml //getter only Avalonia property public static readonly StyledProperty BarProperty = - AvaloniaProperty.Register("Bar"); + AvaloniaProperty.Register(nameof(Bar)); public Control Control { diff --git a/tests/Avalonia.Styling.UnitTests/StyleTests.cs b/tests/Avalonia.Styling.UnitTests/StyleTests.cs index d9756ebc4b..a7c559668b 100644 --- a/tests/Avalonia.Styling.UnitTests/StyleTests.cs +++ b/tests/Avalonia.Styling.UnitTests/StyleTests.cs @@ -170,7 +170,7 @@ namespace Avalonia.Styling.UnitTests private class Class1 : Control { public static readonly StyledProperty FooProperty = - AvaloniaProperty.Register("Foo", "foodefault"); + AvaloniaProperty.Register(nameof(Foo), "foodefault"); public string Foo { From 64ed0761c75713f0d0e0548ef53af3f394daa5dd Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sun, 14 Jan 2018 22:41:21 +0100 Subject: [PATCH 05/18] Rename Dispatcher invoke methods. `InvokeAsync` -> `Post` `InvokeTaskAsync` -> `InvokeAsync` --- samples/Previewer/MainWindow.xaml.cs | 4 ++-- samples/RemoteTest/Program.cs | 4 ++-- src/Avalonia.Base/AvaloniaObject.cs | 2 +- src/Avalonia.Base/PriorityBindingEntry.cs | 4 ++-- src/Avalonia.Base/Threading/AvaloniaScheduler.cs | 2 +- .../Threading/AvaloniaSynchronizationContext.cs | 4 ++-- src/Avalonia.Base/Threading/Dispatcher.cs | 4 ++-- src/Avalonia.Base/Threading/IDispatcher.cs | 4 ++-- src/Avalonia.Controls/Presenters/TextPresenter.cs | 2 +- src/Avalonia.Controls/Remote/RemoteWidget.cs | 2 +- .../Remote/Server/RemoteServerTopLevelImpl.cs | 10 +++++----- src/Avalonia.Controls/TreeView.cs | 2 +- .../Remote/PreviewerWindowImpl.cs | 2 +- .../Remote/RemoteDesignerEntryPoint.cs | 2 +- src/Avalonia.Layout/LayoutManager.cs | 2 +- src/Avalonia.Visuals/Rendering/DeferredRenderer.cs | 2 +- src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs | 2 +- .../FramebufferToplevelImpl.cs | 2 +- .../LinuxFramebufferPlatform.cs | 2 +- src/OSX/Avalonia.MonoMac/TopLevelImpl.cs | 2 +- tests/Avalonia.UnitTests/ImmediateDispatcher.cs | 4 ++-- .../Rendering/DeferredRendererTests.cs | 4 ++-- 22 files changed, 34 insertions(+), 34 deletions(-) diff --git a/samples/Previewer/MainWindow.xaml.cs b/samples/Previewer/MainWindow.xaml.cs index c72b1f7e55..8eabf44bc3 100644 --- a/samples/Previewer/MainWindow.xaml.cs +++ b/samples/Previewer/MainWindow.xaml.cs @@ -39,7 +39,7 @@ namespace Previewer })); new BsonTcpTransport().Listen(IPAddress.Loopback, 25000, t => { - Dispatcher.UIThread.InvokeAsync(() => + Dispatcher.UIThread.Post(() => { if (_connection != null) { @@ -61,7 +61,7 @@ namespace Previewer private void OnMessage(IAvaloniaRemoteTransportConnection transport, object obj) { - Dispatcher.UIThread.InvokeAsync(() => + Dispatcher.UIThread.Post(() => { if (transport != _connection) return; diff --git a/samples/RemoteTest/Program.cs b/samples/RemoteTest/Program.cs index dce168c7ea..f518e77143 100644 --- a/samples/RemoteTest/Program.cs +++ b/samples/RemoteTest/Program.cs @@ -25,7 +25,7 @@ namespace RemoteTest var transport = new BsonTcpTransport(); transport.Listen(IPAddress.Loopback, port, sc => { - Dispatcher.UIThread.InvokeAsync(() => + Dispatcher.UIThread.Post(() => { new RemoteServer(sc).Content = new MainView(); }); @@ -34,7 +34,7 @@ namespace RemoteTest var cts = new CancellationTokenSource(); transport.Connect(IPAddress.Loopback, port).ContinueWith(t => { - Dispatcher.UIThread.InvokeAsync(() => + Dispatcher.UIThread.Post(() => { var window = new Window() { diff --git a/src/Avalonia.Base/AvaloniaObject.cs b/src/Avalonia.Base/AvaloniaObject.cs index 17e6ea8f0f..a46d567d28 100644 --- a/src/Avalonia.Base/AvaloniaObject.cs +++ b/src/Avalonia.Base/AvaloniaObject.cs @@ -774,7 +774,7 @@ namespace Avalonia } else { - Dispatcher.UIThread.InvokeAsync(Set); + Dispatcher.UIThread.Post(Set); } } diff --git a/src/Avalonia.Base/PriorityBindingEntry.cs b/src/Avalonia.Base/PriorityBindingEntry.cs index b44b845f25..570bfe03dc 100644 --- a/src/Avalonia.Base/PriorityBindingEntry.cs +++ b/src/Avalonia.Base/PriorityBindingEntry.cs @@ -123,7 +123,7 @@ namespace Avalonia } else { - Dispatcher.UIThread.InvokeAsync(Signal); + Dispatcher.UIThread.Post(Signal); } } @@ -135,7 +135,7 @@ namespace Avalonia } else { - Dispatcher.UIThread.InvokeAsync(() => _owner.Completed(this)); + Dispatcher.UIThread.Post(() => _owner.Completed(this)); } } } diff --git a/src/Avalonia.Base/Threading/AvaloniaScheduler.cs b/src/Avalonia.Base/Threading/AvaloniaScheduler.cs index f9d67470c1..46529f0a5a 100644 --- a/src/Avalonia.Base/Threading/AvaloniaScheduler.cs +++ b/src/Avalonia.Base/Threading/AvaloniaScheduler.cs @@ -33,7 +33,7 @@ namespace Avalonia.Threading if (!Dispatcher.UIThread.CheckAccess()) { var cancellation = new CancellationDisposable(); - Dispatcher.UIThread.InvokeAsync(() => + Dispatcher.UIThread.Post(() => { if (!cancellation.Token.IsCancellationRequested) { diff --git a/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs b/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs index 7a0249f876..6af5ab63cf 100644 --- a/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs +++ b/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs @@ -36,7 +36,7 @@ namespace Avalonia.Threading /// public override void Post(SendOrPostCallback d, object state) { - Dispatcher.UIThread.InvokeAsync(() => d(state), DispatcherPriority.Send); + Dispatcher.UIThread.Post(() => d(state), DispatcherPriority.Send); } /// @@ -45,7 +45,7 @@ namespace Avalonia.Threading if (Dispatcher.UIThread.CheckAccess()) d(state); else - Dispatcher.UIThread.InvokeTaskAsync(() => d(state), DispatcherPriority.Send).Wait(); + Dispatcher.UIThread.InvokeAsync(() => d(state), DispatcherPriority.Send).Wait(); } } } \ No newline at end of file diff --git a/src/Avalonia.Base/Threading/Dispatcher.cs b/src/Avalonia.Base/Threading/Dispatcher.cs index 4a096fc326..7d29a4f969 100644 --- a/src/Avalonia.Base/Threading/Dispatcher.cs +++ b/src/Avalonia.Base/Threading/Dispatcher.cs @@ -79,13 +79,13 @@ namespace Avalonia.Threading public void RunJobs(DispatcherPriority minimumPriority) => _jobRunner.RunJobs(minimumPriority); /// - public Task InvokeTaskAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal) + public Task InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal) { return _jobRunner?.InvokeAsync(action, priority); } /// - public void InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal) + public void Post(Action action, DispatcherPriority priority = DispatcherPriority.Normal) { _jobRunner?.Post(action, priority); } diff --git a/src/Avalonia.Base/Threading/IDispatcher.cs b/src/Avalonia.Base/Threading/IDispatcher.cs index 6301015a9a..4009dcdeab 100644 --- a/src/Avalonia.Base/Threading/IDispatcher.cs +++ b/src/Avalonia.Base/Threading/IDispatcher.cs @@ -25,7 +25,7 @@ namespace Avalonia.Threading /// The method. /// The priority with which to invoke the method. /// A task that can be used to track the method's execution. - void InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal); + void Post(Action action, DispatcherPriority priority = DispatcherPriority.Normal); /// /// Post action that will be invoked on main thread @@ -34,6 +34,6 @@ namespace Avalonia.Threading /// The priority with which to invoke the method. // TODO: The naming of this method is confusing: the Async suffix usually means return a task. // Remove this and rename InvokeTaskAsync as InvokeAsync. See #816. - Task InvokeTaskAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal); + Task InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal); } } \ No newline at end of file diff --git a/src/Avalonia.Controls/Presenters/TextPresenter.cs b/src/Avalonia.Controls/Presenters/TextPresenter.cs index 5f6b3ad4c8..d2d4151e3d 100644 --- a/src/Avalonia.Controls/Presenters/TextPresenter.cs +++ b/src/Avalonia.Controls/Presenters/TextPresenter.cs @@ -191,7 +191,7 @@ namespace Avalonia.Controls.Presenters // The measure is currently invalid so there's no point trying to bring the // current char into view until a measure has been carried out as the scroll // viewer extents may not be up-to-date. - Dispatcher.UIThread.InvokeAsync( + Dispatcher.UIThread.Post( () => { var rect = FormattedText.HitTestTextPosition(caretIndex); diff --git a/src/Avalonia.Controls/Remote/RemoteWidget.cs b/src/Avalonia.Controls/Remote/RemoteWidget.cs index c05aeaf970..83360a0010 100644 --- a/src/Avalonia.Controls/Remote/RemoteWidget.cs +++ b/src/Avalonia.Controls/Remote/RemoteWidget.cs @@ -18,7 +18,7 @@ namespace Avalonia.Controls.Remote public RemoteWidget(IAvaloniaRemoteTransportConnection connection) { _connection = connection; - _connection.OnMessage += (t, msg) => Dispatcher.UIThread.InvokeAsync(() => OnMessage(msg)); + _connection.OnMessage += (t, msg) => Dispatcher.UIThread.Post(() => OnMessage(msg)); _connection.Send(new ClientSupportedPixelFormatsMessage { Formats = new[] diff --git a/src/Avalonia.Controls/Remote/Server/RemoteServerTopLevelImpl.cs b/src/Avalonia.Controls/Remote/Server/RemoteServerTopLevelImpl.cs index c2e6a200f9..cf4cec9268 100644 --- a/src/Avalonia.Controls/Remote/Server/RemoteServerTopLevelImpl.cs +++ b/src/Avalonia.Controls/Remote/Server/RemoteServerTopLevelImpl.cs @@ -46,16 +46,16 @@ namespace Avalonia.Controls.Remote.Server { _lastReceivedFrame = lastFrame.SequenceId; } - Dispatcher.UIThread.InvokeAsync(RenderIfNeeded); + Dispatcher.UIThread.Post(RenderIfNeeded); } if (obj is ClientSupportedPixelFormatsMessage supportedFormats) { lock (_lock) _supportedFormats = supportedFormats.Formats; - Dispatcher.UIThread.InvokeAsync(RenderIfNeeded); + Dispatcher.UIThread.Post(RenderIfNeeded); } if (obj is MeasureViewportMessage measure) - Dispatcher.UIThread.InvokeAsync(() => + Dispatcher.UIThread.Post(() => { var m = Measure(new Size(measure.Width, measure.Height)); _transport.Send(new MeasureViewportMessage @@ -69,7 +69,7 @@ namespace Avalonia.Controls.Remote.Server lock (_lock) { if (_pendingAllocation == null) - Dispatcher.UIThread.InvokeAsync(() => + Dispatcher.UIThread.Post(() => { ClientViewportAllocatedMessage allocation; lock (_lock) @@ -168,7 +168,7 @@ namespace Avalonia.Controls.Remote.Server public override void Invalidate(Rect rect) { _invalidated = true; - Dispatcher.UIThread.InvokeAsync(RenderIfNeeded); + Dispatcher.UIThread.Post(RenderIfNeeded); } public override IMouseDevice MouseDevice { get; } = new MouseDevice(); diff --git a/src/Avalonia.Controls/TreeView.cs b/src/Avalonia.Controls/TreeView.cs index fa3ecdedef..2e1c011685 100644 --- a/src/Avalonia.Controls/TreeView.cs +++ b/src/Avalonia.Controls/TreeView.cs @@ -250,7 +250,7 @@ namespace Avalonia.Controls if (AutoScrollToSelectedItem) { - Dispatcher.UIThread.InvokeAsync(container.ContainerControl.BringIntoView); + Dispatcher.UIThread.Post(container.ContainerControl.BringIntoView); } break; diff --git a/src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs b/src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs index 535dfd700b..3c7ef86d5d 100644 --- a/src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs +++ b/src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs @@ -49,7 +49,7 @@ namespace Avalonia.DesignerSupport.Remote // In previewer mode we completely ignore client-side viewport size if (obj is ClientViewportAllocatedMessage alloc) { - Dispatcher.UIThread.InvokeAsync(() => SetDpi(new Vector(alloc.DpiX, alloc.DpiY))); + Dispatcher.UIThread.Post(() => SetDpi(new Vector(alloc.DpiX, alloc.DpiY))); return; } base.OnMessage(transport, obj); diff --git a/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs b/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs index ac3438d71c..51cf1d4dde 100644 --- a/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs +++ b/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs @@ -140,7 +140,7 @@ namespace Avalonia.DesignerSupport.Remote }; } - private static void OnTransportMessage(IAvaloniaRemoteTransportConnection transport, object obj) => Dispatcher.UIThread.InvokeAsync(() => + private static void OnTransportMessage(IAvaloniaRemoteTransportConnection transport, object obj) => Dispatcher.UIThread.Post(() => { if (obj is ClientSupportedPixelFormatsMessage formats) { diff --git a/src/Avalonia.Layout/LayoutManager.cs b/src/Avalonia.Layout/LayoutManager.cs index f8911dc036..b6b786a077 100644 --- a/src/Avalonia.Layout/LayoutManager.cs +++ b/src/Avalonia.Layout/LayoutManager.cs @@ -203,7 +203,7 @@ namespace Avalonia.Layout { if (!_queued && !_running) { - Dispatcher.UIThread.InvokeAsync(ExecuteLayoutPass, DispatcherPriority.Layout); + Dispatcher.UIThread.Post(ExecuteLayoutPass, DispatcherPriority.Layout); _queued = true; } } diff --git a/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs b/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs index 041d8f8f6b..82cc0a260d 100644 --- a/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs +++ b/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs @@ -415,7 +415,7 @@ namespace Avalonia.Rendering if (!_updateQueued && (_dirty == null || _dirty.Count > 0)) { _updateQueued = true; - _dispatcher.InvokeAsync(UpdateScene, DispatcherPriority.Render); + _dispatcher.Post(UpdateScene, DispatcherPriority.Render); } Scene scene = null; diff --git a/src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs b/src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs index 136023c31d..c41a136bce 100644 --- a/src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs +++ b/src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs @@ -351,7 +351,7 @@ namespace Avalonia.Gtk3 void OnInput(RawInputEventArgs args) { - Dispatcher.UIThread.InvokeAsync(() => Input?.Invoke(args), DispatcherPriority.Input); + Dispatcher.UIThread.Post(() => Input?.Invoke(args), DispatcherPriority.Input); } public Point PointToClient(Point point) diff --git a/src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs b/src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs index daff4dd751..0db622ba13 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs @@ -41,7 +41,7 @@ namespace Avalonia.LinuxFramebuffer if(_renderQueued) return; _renderQueued = true; - Dispatcher.UIThread.InvokeAsync(() => + Dispatcher.UIThread.Post(() => { Paint?.Invoke(new Rect(default(Point), ClientSize)); _renderQueued = false; diff --git a/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs b/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs index e733beae27..896c91d087 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs @@ -62,7 +62,7 @@ public static class LinuxFramebufferPlatformExtensions public TokenClosable(CancellationToken token) { - token.Register(() => Dispatcher.UIThread.InvokeAsync(() => Closed?.Invoke(this, new EventArgs()))); + token.Register(() => Dispatcher.UIThread.Post(() => Closed?.Invoke(this, new EventArgs()))); } } diff --git a/src/OSX/Avalonia.MonoMac/TopLevelImpl.cs b/src/OSX/Avalonia.MonoMac/TopLevelImpl.cs index 5ea7972871..667ee12fa0 100644 --- a/src/OSX/Avalonia.MonoMac/TopLevelImpl.cs +++ b/src/OSX/Avalonia.MonoMac/TopLevelImpl.cs @@ -107,7 +107,7 @@ namespace Avalonia.MonoMac if (_nonUiRedrawQueued) return; _nonUiRedrawQueued = true; - Dispatcher.UIThread.InvokeAsync( + Dispatcher.UIThread.Post( () => { lock (SyncRoot) diff --git a/tests/Avalonia.UnitTests/ImmediateDispatcher.cs b/tests/Avalonia.UnitTests/ImmediateDispatcher.cs index 4019e65bdf..92f64bde6f 100644 --- a/tests/Avalonia.UnitTests/ImmediateDispatcher.cs +++ b/tests/Avalonia.UnitTests/ImmediateDispatcher.cs @@ -14,12 +14,12 @@ namespace Avalonia.UnitTests return true; } - public void InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal) + public void Post(Action action, DispatcherPriority priority = DispatcherPriority.Normal) { action(); } - public Task InvokeTaskAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal) + public Task InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal) { action(); return Task.FromResult(null); diff --git a/tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests.cs b/tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests.cs index c97070a2aa..8fcb54775b 100644 --- a/tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests.cs +++ b/tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests.cs @@ -24,13 +24,13 @@ namespace Avalonia.Visuals.UnitTests.Rendering var root = new TestRoot(); var dispatcher = new Mock(); - dispatcher.Setup(x => x.InvokeAsync(It.IsAny(), DispatcherPriority.Render)) + dispatcher.Setup(x => x.Post(It.IsAny(), DispatcherPriority.Render)) .Callback((a, p) => a()); CreateTargetAndRunFrame(root, dispatcher: dispatcher.Object); dispatcher.Verify(x => - x.InvokeAsync( + x.Post( It.Is(a => a.Method.Name == "UpdateScene"), DispatcherPriority.Render)); } From 7a60b790b046af0ae3a2e5e98565699b60073eb2 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sun, 14 Jan 2018 23:53:50 +0100 Subject: [PATCH 06/18] Added failing test for #1341. --- .../Avalonia.RenderTests/Shapes/PathTests.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Avalonia.RenderTests/Shapes/PathTests.cs b/tests/Avalonia.RenderTests/Shapes/PathTests.cs index 9a580794f8..fab867f428 100644 --- a/tests/Avalonia.RenderTests/Shapes/PathTests.cs +++ b/tests/Avalonia.RenderTests/Shapes/PathTests.cs @@ -362,5 +362,28 @@ namespace Avalonia.Direct2D1.RenderTests.Shapes await RenderToFile(target); CompareImages(); } + + [Fact] + public async Task Path_With_Rotated_Geometry() + { + var target = new Border + { + Width = 200, + Height = 200, + Background = Brushes.White, + Child = new Path + { + Fill = Brushes.Red, + Data = new RectangleGeometry + { + Rect = new Rect(50, 50, 100, 100), + Transform = new RotateTransform(45), + } + } + }; + + await RenderToFile(target); + CompareImages(); + } } } From 438bc89a9066391483c721c9f443c4c2970beca1 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 15 Jan 2018 00:07:24 +0100 Subject: [PATCH 07/18] Preserve defining geometry transform. Previous logic was overwriting `DefiningGeometry`'s transform with the transform calculated by the layout pass. Be sure to apply both transforms to the `RenderedGeometry`. --- src/Avalonia.Controls/Shapes/Shape.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Controls/Shapes/Shape.cs b/src/Avalonia.Controls/Shapes/Shape.cs index 2ea681891d..a1848a95b1 100644 --- a/src/Avalonia.Controls/Shapes/Shape.cs +++ b/src/Avalonia.Controls/Shapes/Shape.cs @@ -61,12 +61,26 @@ namespace Avalonia.Controls.Shapes { get { - if (_renderedGeometry == null) + if (_renderedGeometry == null && DefiningGeometry != null) { - if (DefiningGeometry != null) + if (_transform == Matrix.Identity) + { + _renderedGeometry = DefiningGeometry; + } + else { _renderedGeometry = DefiningGeometry.Clone(); - _renderedGeometry.Transform = new MatrixTransform(_transform); + + if (_renderedGeometry.Transform == null || + _renderedGeometry.Transform.Value == Matrix.Identity) + { + _renderedGeometry.Transform = new MatrixTransform(_transform); + } + else + { + _renderedGeometry.Transform = new MatrixTransform( + _renderedGeometry.Transform.Value * _transform); + } } } @@ -193,6 +207,7 @@ namespace Avalonia.Controls.Shapes return finalSize; } + private Size CalculateShapeSizeAndSetTransform(Size availableSize) { // This should probably use GetRenderBounds(strokeThickness) but then the calculations From 062f67cd189e4a50d470702b0a070aac351caf86 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 15 Jan 2018 00:10:44 +0100 Subject: [PATCH 08/18] Added expected test output. --- .../Path/Path_With_Rotated_Geometry.expected.png | Bin 0 -> 1100 bytes .../Path/Path_With_Rotated_Geometry.expected.png | Bin 0 -> 1149 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/TestFiles/Direct2D1/Shapes/Path/Path_With_Rotated_Geometry.expected.png create mode 100644 tests/TestFiles/Skia/Shapes/Path/Path_With_Rotated_Geometry.expected.png diff --git a/tests/TestFiles/Direct2D1/Shapes/Path/Path_With_Rotated_Geometry.expected.png b/tests/TestFiles/Direct2D1/Shapes/Path/Path_With_Rotated_Geometry.expected.png new file mode 100644 index 0000000000000000000000000000000000000000..767690045966974d1b2f61cc8feb121c93054348 GIT binary patch literal 1100 zcmdVa-A|HX0LI}r#6%D^=d6?&Lsx5SlZwikYe1B+m6>Z(H?xa=q4|KH|T25VH z*7}%H(Q*Te5Up8lW>QAB8EMWW#Kiobh+8dE{HXi+Gdh6x$HRT?87I`Fr=@b)v22Q> zxC*%}1J7>qVy(sd(=5wc5o`w^QHgi=sQ7F)}QAW7h9{DUsoC=GRBkD@EL)oynX-ssL=MG^V^%{ zp1R)`BI`Sk&T69T#jM8a%O5Aiwema8A$%4#%`&zMl+wYF4B6ZKLJq#IamUNoh2D6X zbWISoxwxEvFfq*60dH}6zCqQg(A%NaI z2atSh3847;et=Qt3cy=ifPkRi1cb~G5Z+q^;5E+!IFJ1Wu-@2CenZF@0d_k9TrB}{ z8wuDgBsZj}ya1)03*-jlUUEbDF9Nia1jO|akl8?hMM!RFSNZ^0WKzx=-&1du@{?*V za~Q7@qjDp=8*0bq<xhzbRj}nZ5kmT{aG*Ou@^E>@NC2 zUlG?PFGOgnD`}s&%N94umGN?v4&=>Aj*RD~ElBNTC{n3I-m^!@cqz0OS!u^sP4^%V z*|Alt%t*T(TQ7YTnHIp-Ynn$o0@(5lpOKOPwmefa(iXs0Z>U2mT-fSObI6Y_Y(<7o z;x0*o3tLg+Q)HeCTaihNeB{7Z2TpuX?;N1zl3 K(_|JYUGWb9wxlKi literal 0 HcmV?d00001 diff --git a/tests/TestFiles/Skia/Shapes/Path/Path_With_Rotated_Geometry.expected.png b/tests/TestFiles/Skia/Shapes/Path/Path_With_Rotated_Geometry.expected.png new file mode 100644 index 0000000000000000000000000000000000000000..7f258aa9de35ce524d04e6a97c285fd2ff3ce625 GIT binary patch literal 1149 zcmeAS@N?(olHy`uVBq!ia0vp^CqS5k4M?tyST_$yu@pObhHwBu4M$1`kZa=U;uumf z=j~nFAQ?}Q){EQ=kDfd_2n;dij_rzsML7* zUoE>J=bSJ9y?1#$=-vPSs1WC$r*H4?QEL1@=O3SvkVjChh6rcP2h~^=op+DdswpKV z&cEHQDkS#x=h-f$M91fEpNVpITh{O1?GbSz^|_820LH(-|1@U z%q>=nRq@H%y^vQa(do9IsUYX%n{{vcJ!YJ+E8ggGNadTfjJlB8hW9D16AgC!b?@(L zX_Pgd9j?OjYRAK?N{J4~{mR8Tn=SwSVxDL)!R&i;M~mZ@-45<5JPY3P1}iNre!D(F zm{T@e-a|=f*Hw3gPLCHs_Khk^3$1HeCv~)}`yvjKxR?%-aM}-&*tw6{)5R(HFFQ~= z?HGrOAg6DSFi;Vnc^FWU#gz)6qK5{_Y(Qz}9%-ONnRyvd;>Ojp!Jn>F3C{lU%k<}0 z?Vq2Pe)XDh;)nl)^#1;n+w)J(w_h86$mJQQil>~M%b{h@xPS)Fo~1v*MI|TgoP*HB z4V{%hdk%N)${iWdcgvyav*d9tqM>b88mJ5y97ZfkN_8)i98yl7T`?trj%Fam7I6Up$yGiryc^eK0KjAI> z(Bu#&#J-;6$xI8No=%I3=?+I66W=-RKP9`RD0oo1kg6OU;HjICRfT89xd2d2UI2d!Wbyk`46Z{ z_N6wEIkOJLe5DLzuKd<`=YDr{-qydN_wK9P*QuDB`%Y(kpZT3dkexY0xWhu?$VZ@& zjWW_e=9xkulTj8VdgUKT^essAP92cR`35LD;uWQ`H)u!uPF6Uc1+!~Evaw7bmFb9jK|34^DrpUXO@geCx4r>2Vl literal 0 HcmV?d00001 From 589b76e9cd0579a9a62c3cec773d565976b9e446 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 18 Jan 2018 23:30:26 +0100 Subject: [PATCH 09/18] Moved render tests for each platform to their own directory. The test .cs files stay in the `Avalonia.RenderTests` directory but the D2D and Skia render test .csprojs are moved to their own directory: include the test files by using a glob in the .csproj. This avoids the hack we were having to do to get `BaseIntermediateOutputPath` to work - we no longer have this problem as now each .csproj has its own directory, it can use the default directory for intermediate files. --- ...ia.Direct2D1.RenderTests.v3.ncrunchproject | 3 ++ ...valonia.Skia.RenderTests.v3.ncrunchproject | 6 ++-- Avalonia.sln | 12 +++---- .../Avalonia.Direct2D1.RenderTests.csproj | 16 ++------- .../Properties/AssemblyInfo.cs | 2 -- tests/Avalonia.RenderTests/.gitignore | 2 -- .../Avalonia.RenderTests.projitems | 33 ------------------ .../Avalonia.RenderTests.shproj | 16 --------- .../Controls/TextBlockTests.cs | 5 +-- .../Properties/AssemblyInfo.cs | 2 -- tests/Avalonia.RenderTests/TestBase.cs | 2 +- .../Avalonia.Skia.RenderTests.csproj | 20 ++--------- .../Cairo/SVGPath/SVGPath.expected.png | Bin 1041 -> 0 bytes .../TextBlock/Wrapping_NoWrap.expected.png | Bin 0 -> 1206 bytes 14 files changed, 20 insertions(+), 99 deletions(-) rename tests/{Avalonia.RenderTests => Avalonia.Direct2D1.RenderTests}/Avalonia.Direct2D1.RenderTests.csproj (69%) delete mode 100644 tests/Avalonia.RenderTests/.gitignore delete mode 100644 tests/Avalonia.RenderTests/Avalonia.RenderTests.projitems delete mode 100644 tests/Avalonia.RenderTests/Avalonia.RenderTests.shproj rename tests/{Avalonia.RenderTests => Avalonia.Skia.RenderTests}/Avalonia.Skia.RenderTests.csproj (69%) delete mode 100644 tests/TestFiles/Cairo/SVGPath/SVGPath.expected.png create mode 100644 tests/TestFiles/Skia/Controls/TextBlock/Wrapping_NoWrap.expected.png diff --git a/.ncrunch/Avalonia.Direct2D1.RenderTests.v3.ncrunchproject b/.ncrunch/Avalonia.Direct2D1.RenderTests.v3.ncrunchproject index 04ab17c4e1..2627a59093 100644 --- a/.ncrunch/Avalonia.Direct2D1.RenderTests.v3.ncrunchproject +++ b/.ncrunch/Avalonia.Direct2D1.RenderTests.v3.ncrunchproject @@ -1,5 +1,8 @@  + + ..\TestFiles\Direct2D1\**.* + 3000 True diff --git a/.ncrunch/Avalonia.Skia.RenderTests.v3.ncrunchproject b/.ncrunch/Avalonia.Skia.RenderTests.v3.ncrunchproject index a8c3abe8f2..7fe2430013 100644 --- a/.ncrunch/Avalonia.Skia.RenderTests.v3.ncrunchproject +++ b/.ncrunch/Avalonia.Skia.RenderTests.v3.ncrunchproject @@ -1,7 +1,9 @@  - 1000 - True + + ..\TestFiles\Skia\**.* + + 3000 True \ No newline at end of file diff --git a/Avalonia.sln b/Avalonia.sln index a29f3dd754..679ef1579e 100644 --- a/Avalonia.sln +++ b/Avalonia.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27004.2008 +VisualStudioVersion = 15.0.27130.2024 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Base", "src\Avalonia.Base\Avalonia.Base.csproj", "{B09B78D8-9B26-48B0-9149-D64A2F120F3F}" EndProject @@ -45,11 +45,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Layout.UnitTests", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Interactivity.UnitTests", "tests\Avalonia.Interactivity.UnitTests\Avalonia.Interactivity.UnitTests.csproj", "{08478EF5-44E8-42E9-92D6-15E00EC038D8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Direct2D1.RenderTests", "tests\Avalonia.RenderTests\Avalonia.Direct2D1.RenderTests.csproj", "{DABFD304-D6A4-4752-8123-C2CCF7AC7831}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Direct2D1.RenderTests", "tests\Avalonia.Direct2D1.RenderTests\Avalonia.Direct2D1.RenderTests.csproj", "{DABFD304-D6A4-4752-8123-C2CCF7AC7831}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Input.UnitTests", "tests\Avalonia.Input.UnitTests\Avalonia.Input.UnitTests.csproj", "{AC18926A-E784-40FE-B09D-BB0FE2B599F0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Direct2D1.UnitTests", "tests\Avalonia.Direct2D1.UnitTests\Avalonia.Direct2D1.UnitTests.csproj", "{EFB11458-9CDF-41C0-BE4F-44AF45A4CAB8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Direct2D1.UnitTests", "tests\Avalonia.Direct2D1.UnitTests\Avalonia.Direct2D1.UnitTests.csproj", "{EFB11458-9CDF-41C0-BE4F-44AF45A4CAB8}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Markup.Xaml.UnitTests", "tests\Avalonia.Markup.Xaml.UnitTests\Avalonia.Markup.Xaml.UnitTests.csproj", "{99135EAB-653D-47E4-A378-C96E1278CA44}" EndProject @@ -114,8 +114,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.DesignerSupport.Te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.DesignerSupport.TestApp", "tests\Avalonia.DesignerSupport.TestApp\Avalonia.DesignerSupport.TestApp.csproj", "{F1381F98-4D24-409A-A6C5-1C5B1E08BB08}" EndProject -Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Avalonia.RenderTests", "tests\Avalonia.RenderTests\Avalonia.RenderTests.shproj", "{48840EDD-24BF-495D-911E-2EB12AE75D3B}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtualizationTest", "samples\VirtualizationTest\VirtualizationTest.csproj", "{FBCAF3D0-2808-4934-8E96-3F607594517B}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Interop", "Interop", "{A0CC0258-D18C-4AB3-854F-7101680FC3F9}" @@ -176,7 +174,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Direct3DInteropSample", "sa EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Win32.Interop", "src\Windows\Avalonia.Win32.Interop\Avalonia.Win32.Interop.csproj", "{CBC4FF2F-92D4-420B-BE21-9FE0B930B04E}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Skia.RenderTests", "tests\Avalonia.RenderTests\Avalonia.Skia.RenderTests.csproj", "{E1582370-37B3-403C-917F-8209551B1634}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Skia.RenderTests", "tests\Avalonia.Skia.RenderTests\Avalonia.Skia.RenderTests.csproj", "{E1582370-37B3-403C-917F-8209551B1634}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Remote.Protocol", "src\Avalonia.Remote.Protocol\Avalonia.Remote.Protocol.csproj", "{D78A720C-C0C6-478B-8564-F167F9BDD01B}" EndProject @@ -200,7 +198,6 @@ Global src\Shared\RenderHelpers\RenderHelpers.projitems*{3e908f67-5543-4879-a1dc-08eace79b3cd}*SharedItemsImports = 4 src\Windows\Avalonia.Win32\Avalonia.Win32.Shared.projitems*{40759a76-d0f2-464e-8000-6ff0f5c4bd7c}*SharedItemsImports = 4 src\Shared\PlatformSupport\PlatformSupport.projitems*{4488ad85-1495-4809-9aa4-ddfe0a48527e}*SharedItemsImports = 4 - tests\Avalonia.RenderTests\Avalonia.RenderTests.projitems*{48840edd-24bf-495d-911e-2eb12ae75d3b}*SharedItemsImports = 13 src\Shared\PlatformSupport\PlatformSupport.projitems*{4a1abb09-9047-4bd5-a4ad-a055e52c5ee0}*SharedItemsImports = 4 src\Shared\PlatformSupport\PlatformSupport.projitems*{7863ea94-f0fb-4386-bf8c-e5bfa761560a}*SharedItemsImports = 4 src\Shared\PlatformSupport\PlatformSupport.projitems*{7b92af71-6287-4693-9dcb-bd5b6e927e23}*SharedItemsImports = 4 @@ -2643,7 +2640,6 @@ Global {57E0455D-D565-44BB-B069-EE1AA20F8337} = {9B9E3891-2366-4253-A952-D08BCEB71098} {52F55355-D120-42AC-8116-8410A7D602FA} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B} {F1381F98-4D24-409A-A6C5-1C5B1E08BB08} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B} - {48840EDD-24BF-495D-911E-2EB12AE75D3B} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B} {FBCAF3D0-2808-4934-8E96-3F607594517B} = {9B9E3891-2366-4253-A952-D08BCEB71098} {A0CC0258-D18C-4AB3-854F-7101680FC3F9} = {9B9E3891-2366-4253-A952-D08BCEB71098} {C7A69145-60B6-4882-97D6-A3921DD43978} = {A0CC0258-D18C-4AB3-854F-7101680FC3F9} diff --git a/tests/Avalonia.RenderTests/Avalonia.Direct2D1.RenderTests.csproj b/tests/Avalonia.Direct2D1.RenderTests/Avalonia.Direct2D1.RenderTests.csproj similarity index 69% rename from tests/Avalonia.RenderTests/Avalonia.Direct2D1.RenderTests.csproj rename to tests/Avalonia.Direct2D1.RenderTests/Avalonia.Direct2D1.RenderTests.csproj index 6af8fd8963..42d99cc19a 100644 --- a/tests/Avalonia.RenderTests/Avalonia.Direct2D1.RenderTests.csproj +++ b/tests/Avalonia.Direct2D1.RenderTests/Avalonia.Direct2D1.RenderTests.csproj @@ -1,19 +1,9 @@ - - - obj-Direct2D1 - - + netcoreapp2.0 - bin\Direct2D\$(Configuration) - false - False - $(DefineConstants);AVALONIA_DIRECT2D - Library - - + @@ -33,7 +23,5 @@ - - \ No newline at end of file diff --git a/tests/Avalonia.Direct2D1.UnitTests/Properties/AssemblyInfo.cs b/tests/Avalonia.Direct2D1.UnitTests/Properties/AssemblyInfo.cs index a8edd50b31..a462e5b079 100644 --- a/tests/Avalonia.Direct2D1.UnitTests/Properties/AssemblyInfo.cs +++ b/tests/Avalonia.Direct2D1.UnitTests/Properties/AssemblyInfo.cs @@ -4,7 +4,5 @@ using System.Reflection; using Xunit; -[assembly: AssemblyTitle("Avalonia.Direct2D1.UnitTests")] - // Don't run tests in parallel. [assembly: CollectionBehavior(DisableTestParallelization = true)] \ No newline at end of file diff --git a/tests/Avalonia.RenderTests/.gitignore b/tests/Avalonia.RenderTests/.gitignore deleted file mode 100644 index 76146e97c7..0000000000 --- a/tests/Avalonia.RenderTests/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -obj-Skia/ -obj-Skia/* \ No newline at end of file diff --git a/tests/Avalonia.RenderTests/Avalonia.RenderTests.projitems b/tests/Avalonia.RenderTests/Avalonia.RenderTests.projitems deleted file mode 100644 index ff729a6b48..0000000000 --- a/tests/Avalonia.RenderTests/Avalonia.RenderTests.projitems +++ /dev/null @@ -1,33 +0,0 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - true - 48840edd-24bf-495d-911e-2eb12ae75d3b - - - Avalonia.RenderTests - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tests/Avalonia.RenderTests/Avalonia.RenderTests.shproj b/tests/Avalonia.RenderTests/Avalonia.RenderTests.shproj deleted file mode 100644 index e3bed80491..0000000000 --- a/tests/Avalonia.RenderTests/Avalonia.RenderTests.shproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - 48840edd-24bf-495d-911e-2eb12ae75d3b - 14.0 - - - - - - - - - - - \ No newline at end of file diff --git a/tests/Avalonia.RenderTests/Controls/TextBlockTests.cs b/tests/Avalonia.RenderTests/Controls/TextBlockTests.cs index a5d06a1b0e..80b850635d 100644 --- a/tests/Avalonia.RenderTests/Controls/TextBlockTests.cs +++ b/tests/Avalonia.RenderTests/Controls/TextBlockTests.cs @@ -1,6 +1,7 @@ // Copyright (c) The Avalonia Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. +using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Layout; using Avalonia.Media; @@ -20,7 +21,7 @@ namespace Avalonia.Direct2D1.RenderTests.Controls } [Fact] - public void Wrapping_NoWrap() + public async Task Wrapping_NoWrap() { Decorator target = new Decorator { @@ -38,7 +39,7 @@ namespace Avalonia.Direct2D1.RenderTests.Controls } }; - RenderToFile(target); + await RenderToFile(target); CompareImages(); } } diff --git a/tests/Avalonia.RenderTests/Properties/AssemblyInfo.cs b/tests/Avalonia.RenderTests/Properties/AssemblyInfo.cs index d5ba64ac05..a462e5b079 100644 --- a/tests/Avalonia.RenderTests/Properties/AssemblyInfo.cs +++ b/tests/Avalonia.RenderTests/Properties/AssemblyInfo.cs @@ -4,7 +4,5 @@ using System.Reflection; using Xunit; -[assembly: AssemblyTitle("Avalonia.Direct2D1.RenderTests")] - // Don't run tests in parallel. [assembly: CollectionBehavior(DisableTestParallelization = true)] \ No newline at end of file diff --git a/tests/Avalonia.RenderTests/TestBase.cs b/tests/Avalonia.RenderTests/TestBase.cs index cf38ef3818..ae359c5c5f 100644 --- a/tests/Avalonia.RenderTests/TestBase.cs +++ b/tests/Avalonia.RenderTests/TestBase.cs @@ -46,7 +46,7 @@ namespace Avalonia.Direct2D1.RenderTests public TestBase(string outputPath) { - var testFiles = Path.GetFullPath(@"..\..\..\..\..\TestFiles\"); + var testFiles = Path.GetFullPath(@"..\..\..\..\TestFiles\"); #if AVALONIA_SKIA var platform = "Skia"; #else diff --git a/tests/Avalonia.RenderTests/Avalonia.Skia.RenderTests.csproj b/tests/Avalonia.Skia.RenderTests/Avalonia.Skia.RenderTests.csproj similarity index 69% rename from tests/Avalonia.RenderTests/Avalonia.Skia.RenderTests.csproj rename to tests/Avalonia.Skia.RenderTests/Avalonia.Skia.RenderTests.csproj index 370cfac6dd..4a297a340d 100644 --- a/tests/Avalonia.RenderTests/Avalonia.Skia.RenderTests.csproj +++ b/tests/Avalonia.Skia.RenderTests/Avalonia.Skia.RenderTests.csproj @@ -1,21 +1,10 @@ - - - obj-Skia - - - - + netcoreapp2.0 - bin\Skia\$(Configuration) - false - False - $(DefineConstants);AVALONIA_SKIA;AVALONIA_SKIA_SKIP_FAIL - Library + AVALONIA_SKIA;AVALONIA_SKIA_SKIP_FAIL - - + @@ -35,9 +24,6 @@ - - - \ No newline at end of file diff --git a/tests/TestFiles/Cairo/SVGPath/SVGPath.expected.png b/tests/TestFiles/Cairo/SVGPath/SVGPath.expected.png deleted file mode 100644 index 98300488100e4bb5bba799d456efa2cb4ba367e2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1041 zcmeAS@N?(olHy`uVBq!ia0vp^J|N7&1|*M957Y)yEX7WqAsj$Z!;#X#z`%UM)5S5Q zV$R!H4+|d|2(-$Zf0ws95Yhm|4l5X}8cGDT6l57hTS6LEDlB7~!u2NP!S9WW4;pSu zR9_>r<8PYDM#fD% zGed5_oxpfvl1pCCrfpG*#%{~;9AOrdZ7j3C%d@(lOx`!h*6^T$8Ex@KvZ+Kl&qSSw;C z={>Y&oHy^qF2fLwe6y!NHTqtDPnA12ef{ajz8elV-m3HW*8IOAF`|Bx!OS`F-HSf2 z_}plI&~0(BT(Re!jdy>|I(q)2+Kt!QKTESuCdI5W?_F4|cl`PDX7`AR4?mw-=Qa#B0Ohp$D&_Wm+nqJerq!4 zx8Ca<+TD8DC(}aSE;=?r_T>AHUe%h4z71c0RhKYsk$LSWGbh1yR>98(_k(Meep;Rp z^?1j>hq0DZ)w}*NAB>CBc>iSjw9~$&Y*+Sr{M4;Dop|&Flg2JR*^3s2pOg73F)=>y%0 z6YI+_P5Cs3;}iboFyt=akR{0Fs#U_y7O^ diff --git a/tests/TestFiles/Skia/Controls/TextBlock/Wrapping_NoWrap.expected.png b/tests/TestFiles/Skia/Controls/TextBlock/Wrapping_NoWrap.expected.png new file mode 100644 index 0000000000000000000000000000000000000000..2296e02d68707f6276a8a875cb38fa99ad3309b5 GIT binary patch literal 1206 zcmc&z>rdJT6vaAiYo|?@Ewh_W+c=G}K_@j<1R0CgQmeCF8^t2NWsV9~Xng>(wwvoC z(G;DEI@qj*WfjS!VtEKI%LG(pTK6-Eh}kNL7K!C0D0JBU5&Lk?$vq!V?#;dTUVdJ7 zXvha4AP^`NbuROgUzPhf6zpeS;V{cDZ{d)+ND%1P_9J^`LH_!1-8nP~1Pc3o9{~#D z&y{{NoSaoi{(@LdZYZm-0@an(5XfLc6*>AeI0>9~4bqb5&pD0CL|$&hT7U<&%V*yW z%1>dOpTD1gN?rAQSvSBG5R|Zx<6TghPC>Zh_JK-M1VgV1cLp-*C8Hidb=0* z{s98AGOh?U0*q%QbR<&db0x1vC7MvPYm2d(3O!IeyMjNrZ5of@ z6>D^I7r7x4TD?04L-Vzs2%J2|#SlM{Hn(0?p}|!X;ImPMvy#>Lz6WeE_yS>|V{6cO zfGh>Zz+Q?PPz!OYaNA>*Bc0G@^K3RTWEQr}cEa_Wi84hY)*u#3;fV9Y-iHn*b8}%( zFKwB$xTzUwoMDpEEuCzBZKEtXq$G`NM&xxGC9xJ0#)-)s8})#!*zV(dnwnoo{H9xK1|gN$^Pue6@TCIc;i=iPA<#M))_7g^jZF;1D78Ksvh2^W(hs<2Y@@VE%aIPz(+q=cM}n<^lnmMN zdW=F#C(7{izI88}FJf^^_;YUI)+s(v`sS>Jk+QfB<&UI0c4;j`lq7&vsKr!bF+r+W za8P5{3RFF$g^Ap>W_q)?TEC-uscXVkwMhtfQ@Ww+?aJlt*9FNw{kI-qqe|MGWf31el_O@3}8) zGc@&P_17oa@j4TF^(Ra1{o{>aQu@k+KU!Mh^xXPRI2K?1pZ(_P{&xz4!)bvXLFJJX S;fKrjyFq2;We$H Date: Fri, 19 Jan 2018 22:55:48 +0100 Subject: [PATCH 10/18] Update cake script with new render test locations. --- build.cake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.cake b/build.cake index 61fda13695..01aefff093 100644 --- a/build.cake +++ b/build.cake @@ -197,8 +197,8 @@ Task("Run-Render-Tests") .IsDependentOn("Build") .WithCriteria(() => !parameters.SkipTests && parameters.IsRunningOnWindows) .Does(() => { - RunCoreTest("./tests/Avalonia.RenderTests/Avalonia.Skia.RenderTests.csproj", parameters, true); - RunCoreTest("./tests/Avalonia.RenderTests/Avalonia.Direct2D1.RenderTests.csproj", parameters, true); + RunCoreTest("./tests/Avalonia.Skia.RenderTests/Avalonia.Skia.RenderTests.csproj", parameters, true); + RunCoreTest("./tests/Avalonia.Direct2D1.RenderTests/Avalonia.Direct2D1.RenderTests.csproj", parameters, true); }); Task("Run-Designer-Unit-Tests") From 02c6ae3c1a76baeeda39a56e7984183cd1a4c376 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 20 Jan 2018 19:23:13 +0100 Subject: [PATCH 11/18] Added ScrollBarVisibility.Disabled. --- src/Avalonia.Controls/Primitives/ScrollBar.cs | 1 + src/Avalonia.Controls/Primitives/ScrollBarVisibility.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Primitives/ScrollBar.cs b/src/Avalonia.Controls/Primitives/ScrollBar.cs index 009e1d0ab8..0057b15150 100644 --- a/src/Avalonia.Controls/Primitives/ScrollBar.cs +++ b/src/Avalonia.Controls/Primitives/ScrollBar.cs @@ -99,6 +99,7 @@ namespace Avalonia.Controls.Primitives case ScrollBarVisibility.Visible: return true; + case ScrollBarVisibility.Disabled: case ScrollBarVisibility.Hidden: return false; diff --git a/src/Avalonia.Controls/Primitives/ScrollBarVisibility.cs b/src/Avalonia.Controls/Primitives/ScrollBarVisibility.cs index 17413d2233..f1cca8f909 100644 --- a/src/Avalonia.Controls/Primitives/ScrollBarVisibility.cs +++ b/src/Avalonia.Controls/Primitives/ScrollBarVisibility.cs @@ -5,8 +5,9 @@ namespace Avalonia.Controls.Primitives { public enum ScrollBarVisibility { + Disabled, Auto, - Visible, Hidden, + Visible, } } From 1be39b8f711f63fc7ffe3cfd0200cae6ac16f674 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 20 Jan 2018 19:23:45 +0100 Subject: [PATCH 12/18] Select scrollbar visibility in VirtualizationTest. Does not currently work. --- samples/VirtualizationTest/MainWindow.xaml | 10 +++++++++- .../ViewModels/MainWindowViewModel.cs | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/samples/VirtualizationTest/MainWindow.xaml b/samples/VirtualizationTest/MainWindow.xaml index 55bd729fec..205e896fc8 100644 --- a/samples/VirtualizationTest/MainWindow.xaml +++ b/samples/VirtualizationTest/MainWindow.xaml @@ -21,6 +21,12 @@ + Horiz. ScrollBar + + Vert. ScrollBar + @@ -35,7 +41,9 @@ Items="{Binding Items}" SelectedItems="{Binding SelectedItems}" SelectionMode="Multiple" - VirtualizationMode="{Binding VirtualizationMode}"> + VirtualizationMode="{Binding VirtualizationMode}" + ScrollViewer.HorizontalScrollBarVisibility="{Binding HorizontalScrollBarVisibility, Mode=TwoWay}" + ScrollViewer.VerticalScrollBarVisibility="{Binding VerticalScrollBarVisibility, Mode=TwoWay}"> diff --git a/samples/VirtualizationTest/ViewModels/MainWindowViewModel.cs b/samples/VirtualizationTest/ViewModels/MainWindowViewModel.cs index f47627acb4..722af9e3af 100644 --- a/samples/VirtualizationTest/ViewModels/MainWindowViewModel.cs +++ b/samples/VirtualizationTest/ViewModels/MainWindowViewModel.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using Avalonia.Collections; using Avalonia.Controls; +using Avalonia.Controls.Primitives; using ReactiveUI; namespace VirtualizationTest.ViewModels @@ -17,6 +18,8 @@ namespace VirtualizationTest.ViewModels private int _newItemIndex; private IReactiveList _items; private string _prefix = "Item"; + private ScrollBarVisibility _horizontalScrollBarVisibility; + private ScrollBarVisibility _verticalScrollBarVisibility; private Orientation _orientation = Orientation.Vertical; private ItemVirtualizationMode _virtualizationMode = ItemVirtualizationMode.Simple; @@ -64,6 +67,21 @@ namespace VirtualizationTest.ViewModels public IEnumerable Orientations => Enum.GetValues(typeof(Orientation)).Cast(); + public ScrollBarVisibility HorizontalScrollBarVisibility + { + get { return _horizontalScrollBarVisibility; } + set { this.RaiseAndSetIfChanged(ref _horizontalScrollBarVisibility, value); } + } + + public ScrollBarVisibility VerticalScrollBarVisibility + { + get { return _verticalScrollBarVisibility; } + set { this.RaiseAndSetIfChanged(ref _verticalScrollBarVisibility, value); } + } + + public IEnumerable ScrollBarVisibilities => + Enum.GetValues(typeof(ScrollBarVisibility)).Cast(); + public ItemVirtualizationMode VirtualizationMode { get { return _virtualizationMode; } From 7e5e9c468baf3c9861e9bb8c74ddd7b4808b18a0 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 20 Jan 2018 19:38:49 +0100 Subject: [PATCH 13/18] Make VirtualizationTest items word-wrap. --- samples/VirtualizationTest/MainWindow.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/VirtualizationTest/MainWindow.xaml b/samples/VirtualizationTest/MainWindow.xaml index 205e896fc8..52c2b33680 100644 --- a/samples/VirtualizationTest/MainWindow.xaml +++ b/samples/VirtualizationTest/MainWindow.xaml @@ -51,7 +51,7 @@ - + From 8a80a724d72fde0494a474e08520356a1311332e Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 20 Jan 2018 19:47:24 +0100 Subject: [PATCH 14/18] Implement disabling of ListBox scrollbars. Fixes #1344. --- .../ViewModels/MainWindowViewModel.cs | 4 +- .../Presenters/ItemVirtualizerSimple.cs | 12 ++- .../Presenters/ItemsPresenter.cs | 27 ++++++ .../Presenters/ScrollContentPresenter.cs | 63 +++++++++--- .../Primitives/ILogicalScrollable.cs | 10 ++ src/Avalonia.Controls/ScrollViewer.cs | 97 ++++++++++++++----- src/Avalonia.Controls/TextBox.cs | 22 +---- .../VirtualizingStackPanel.cs | 2 - src/Avalonia.Themes.Default/ListBox.xaml | 7 +- src/Avalonia.Themes.Default/ScrollViewer.xaml | 5 +- src/Avalonia.Themes.Default/TextBox.xaml | 3 +- src/Avalonia.Themes.Default/TreeView.xaml | 2 +- .../ItemsPresenterTests_Virtualization.cs | 2 + ...emsPresenterTests_Virtualization_Simple.cs | 2 + .../Presenters/ScrollContentPresenterTests.cs | 11 ++- ...ontentPresenterTests_ILogicalScrollable.cs | 46 +++++++-- .../ScrollViewerTests.cs | 30 +++++- .../FullLayoutTests.cs | 2 +- .../DeferredRendererTests_HitTesting.cs | 2 + .../ImmediateRendererTests_HitTesting.cs | 2 + 20 files changed, 273 insertions(+), 78 deletions(-) diff --git a/samples/VirtualizationTest/ViewModels/MainWindowViewModel.cs b/samples/VirtualizationTest/ViewModels/MainWindowViewModel.cs index 722af9e3af..8eab91e06d 100644 --- a/samples/VirtualizationTest/ViewModels/MainWindowViewModel.cs +++ b/samples/VirtualizationTest/ViewModels/MainWindowViewModel.cs @@ -18,8 +18,8 @@ namespace VirtualizationTest.ViewModels private int _newItemIndex; private IReactiveList _items; private string _prefix = "Item"; - private ScrollBarVisibility _horizontalScrollBarVisibility; - private ScrollBarVisibility _verticalScrollBarVisibility; + private ScrollBarVisibility _horizontalScrollBarVisibility = ScrollBarVisibility.Auto; + private ScrollBarVisibility _verticalScrollBarVisibility = ScrollBarVisibility.Auto; private Orientation _orientation = Orientation.Vertical; private ItemVirtualizationMode _virtualizationMode = ItemVirtualizationMode.Simple; diff --git a/src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs b/src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs index 20602d5475..c1489e7138 100644 --- a/src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs +++ b/src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs @@ -5,6 +5,7 @@ using System; using System.Collections; using System.Collections.Specialized; using System.Linq; +using Avalonia.Controls.Primitives; using Avalonia.Controls.Utils; using Avalonia.Input; using Avalonia.Layout; @@ -97,6 +98,7 @@ namespace Avalonia.Controls.Presenters /// public override Size MeasureOverride(Size availableSize) { + var scrollable = (ILogicalScrollable)Owner; var visualRoot = Owner.GetVisualRoot(); var maxAvailableSize = (visualRoot as WindowBase)?.PlatformImpl?.MaxClientSize ?? (visualRoot as TopLevel)?.ClientSize; @@ -115,7 +117,10 @@ namespace Avalonia.Controls.Presenters } } - availableSize = availableSize.WithWidth(double.PositiveInfinity); + if (scrollable.CanHorizontallyScroll) + { + availableSize = availableSize.WithWidth(double.PositiveInfinity); + } } else { @@ -127,7 +132,10 @@ namespace Avalonia.Controls.Presenters } } - availableSize = availableSize.WithHeight(double.PositiveInfinity); + if (scrollable.CanVerticallyScroll) + { + availableSize = availableSize.WithHeight(double.PositiveInfinity); + } } Owner.Panel.Measure(availableSize); diff --git a/src/Avalonia.Controls/Presenters/ItemsPresenter.cs b/src/Avalonia.Controls/Presenters/ItemsPresenter.cs index 185193f889..590bfa25ac 100644 --- a/src/Avalonia.Controls/Presenters/ItemsPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ItemsPresenter.cs @@ -23,6 +23,8 @@ namespace Avalonia.Controls.Presenters defaultValue: ItemVirtualizationMode.None); private ItemVirtualizer _virtualizer; + private bool _canHorizontallyScroll; + private bool _canVerticallyScroll; /// /// Initializes static members of the class. @@ -46,6 +48,31 @@ namespace Avalonia.Controls.Presenters set { SetValue(VirtualizationModeProperty, value); } } + /// + /// Gets or sets a value indicating whether the content can be scrolled horizontally. + /// + bool ILogicalScrollable.CanHorizontallyScroll + { + get { return _canHorizontallyScroll; } + set + { + _canHorizontallyScroll = value; + InvalidateMeasure(); + } + } + + /// + /// Gets or sets a value indicating whether the content can be scrolled horizontally. + /// + bool ILogicalScrollable.CanVerticallyScroll + { + get { return _canVerticallyScroll; } + set + { + _canVerticallyScroll = value; + InvalidateMeasure(); + } + } /// bool ILogicalScrollable.IsLogicalScrollEnabled { diff --git a/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs b/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs index e41c4e1e28..6c61375054 100644 --- a/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs @@ -17,6 +17,24 @@ namespace Avalonia.Controls.Presenters /// public class ScrollContentPresenter : ContentPresenter, IPresenter, IScrollable { + /// + /// Defines the property. + /// + public static readonly DirectProperty CanHorizontallyScrollProperty = + AvaloniaProperty.RegisterDirect( + nameof(CanHorizontallyScroll), + o => o.CanHorizontallyScroll, + (o, v) => o.CanHorizontallyScroll = v); + + /// + /// Defines the property. + /// + public static readonly DirectProperty CanVerticallyScrollProperty = + AvaloniaProperty.RegisterDirect( + nameof(CanVerticallyScroll), + o => o.CanVerticallyScroll, + (o, v) => o.CanVerticallyScroll = v); + /// /// Defines the property. /// @@ -41,12 +59,8 @@ namespace Avalonia.Controls.Presenters o => o.Viewport, (o, v) => o.Viewport = v); - /// - /// Defines the property. - /// - public static readonly StyledProperty CanScrollHorizontallyProperty = - ScrollViewer.CanScrollHorizontallyProperty.AddOwner(); - + private bool _canHorizontallyScroll; + private bool _canVerticallyScroll; private Size _extent; private Size _measuredExtent; private Vector _offset; @@ -73,6 +87,24 @@ namespace Avalonia.Controls.Presenters this.GetObservable(ChildProperty).Subscribe(UpdateScrollableSubscription); } + /// + /// Gets or sets a value indicating whether the content can be scrolled horizontally. + /// + public bool CanHorizontallyScroll + { + get { return _canHorizontallyScroll; } + set { SetAndRaise(CanHorizontallyScrollProperty, ref _canHorizontallyScroll, value); } + } + + /// + /// Gets or sets a value indicating whether the content can be scrolled horizontally. + /// + public bool CanVerticallyScroll + { + get { return _canVerticallyScroll; } + set { SetAndRaise(CanVerticallyScrollProperty, ref _canVerticallyScroll, value); } + } + /// /// Gets the extent of the scrollable content. /// @@ -100,11 +132,6 @@ namespace Avalonia.Controls.Presenters private set { SetAndRaise(ViewportProperty, ref _viewport, value); } } - /// - /// Gets a value indicating whether the content can be scrolled horizontally. - /// - public bool CanScrollHorizontally => GetValue(CanScrollHorizontallyProperty); - /// /// Attempts to bring a portion of the target visual into view by scrolling the content. /// @@ -182,10 +209,15 @@ namespace Avalonia.Controls.Presenters { measureSize = new Size(double.PositiveInfinity, double.PositiveInfinity); - if (!CanScrollHorizontally) + if (!CanHorizontallyScroll) { measureSize = measureSize.WithWidth(availableSize.Width); } + + if (!CanVerticallyScroll) + { + measureSize = measureSize.WithHeight(availableSize.Height); + } } child.Measure(measureSize); @@ -289,7 +321,12 @@ namespace Avalonia.Controls.Presenters if (scrollable.IsLogicalScrollEnabled == true) { _logicalScrollSubscription = new CompositeDisposable( - this.GetObservable(OffsetProperty).Skip(1).Subscribe(x => scrollable.Offset = x), + this.GetObservable(CanHorizontallyScrollProperty) + .Subscribe(x => scrollable.CanHorizontallyScroll = x), + this.GetObservable(CanVerticallyScrollProperty) + .Subscribe(x => scrollable.CanVerticallyScroll = x), + this.GetObservable(OffsetProperty) + .Skip(1).Subscribe(x => scrollable.Offset = x), Disposable.Create(() => scrollable.InvalidateScroll = null)); UpdateFromScrollable(scrollable); } diff --git a/src/Avalonia.Controls/Primitives/ILogicalScrollable.cs b/src/Avalonia.Controls/Primitives/ILogicalScrollable.cs index 6c8f463a96..490beb12b3 100644 --- a/src/Avalonia.Controls/Primitives/ILogicalScrollable.cs +++ b/src/Avalonia.Controls/Primitives/ILogicalScrollable.cs @@ -19,6 +19,16 @@ namespace Avalonia.Controls.Primitives /// public interface ILogicalScrollable : IScrollable { + /// + /// Gets or sets a value indicating whether the content can be scrolled horizontally. + /// + bool CanHorizontallyScroll { get; set; } + + /// + /// Gets or sets a value indicating whether the content can be scrolled horizontally. + /// + bool CanVerticallyScroll { get; set; } + /// /// Gets a value indicating whether logical scrolling is enabled on the control. /// diff --git a/src/Avalonia.Controls/ScrollViewer.cs b/src/Avalonia.Controls/ScrollViewer.cs index 0442652540..39854e0071 100644 --- a/src/Avalonia.Controls/ScrollViewer.cs +++ b/src/Avalonia.Controls/ScrollViewer.cs @@ -2,8 +2,6 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using System; -using System.Linq; -using System.Reactive.Linq; using Avalonia.Controls.Presenters; using Avalonia.Controls.Primitives; @@ -15,16 +13,34 @@ namespace Avalonia.Controls public class ScrollViewer : ContentControl, IScrollable { /// - /// Defines the property. + /// Defines the property. /// - public static readonly StyledProperty CanScrollHorizontallyProperty = - AvaloniaProperty.Register(nameof(CanScrollHorizontally), true); + /// + /// There is no public C# accessor for this property as it is intended to be bound to by a + /// in the control's template. + /// + public static readonly DirectProperty CanHorizontallyScrollProperty = + AvaloniaProperty.RegisterDirect( + nameof(CanHorizontallyScroll), + o => o.CanHorizontallyScroll); + + /// + /// Defines the property. + /// + /// + /// There is no public C# accessor for this property as it is intended to be bound to by a + /// in the control's template. + /// + public static readonly DirectProperty CanVerticallyScrollProperty = + AvaloniaProperty.RegisterDirect( + nameof(CanVerticallyScroll), + o => o.CanVerticallyScroll); /// /// Defines the property. /// public static readonly DirectProperty ExtentProperty = - AvaloniaProperty.RegisterDirect(nameof(Extent), + AvaloniaProperty.RegisterDirect(nameof(Extent), o => o.Extent, (o, v) => o.Extent = v); @@ -41,7 +57,7 @@ namespace Avalonia.Controls /// Defines the property. /// public static readonly DirectProperty ViewportProperty = - AvaloniaProperty.RegisterDirect(nameof(Viewport), + AvaloniaProperty.RegisterDirect(nameof(Viewport), o => o.Viewport, (o, v) => o.Viewport = v); @@ -85,14 +101,10 @@ namespace Avalonia.Controls /// /// Defines the property. /// - /// - /// There is no public C# accessor for this property as it is intended to be bound to by a - /// in the control's template. - /// public static readonly AttachedProperty HorizontalScrollBarVisibilityProperty = AvaloniaProperty.RegisterAttached( nameof(HorizontalScrollBarVisibility), - ScrollBarVisibility.Auto); + ScrollBarVisibility.Hidden); /// /// Defines the VerticalScrollBarMaximum property. @@ -136,7 +148,7 @@ namespace Avalonia.Controls /// public static readonly AttachedProperty VerticalScrollBarVisibilityProperty = AvaloniaProperty.RegisterAttached( - nameof(VerticalScrollBarVisibility), + nameof(VerticalScrollBarVisibility), ScrollBarVisibility.Auto); private Size _extent; @@ -150,6 +162,8 @@ namespace Avalonia.Controls { AffectsValidation(ExtentProperty, OffsetProperty); AffectsValidation(ViewportProperty, OffsetProperty); + HorizontalScrollBarVisibilityProperty.Changed.AddClassHandler(x => x.ScrollBarVisibilityChanged); + VerticalScrollBarVisibilityProperty.Changed.AddClassHandler(x => x.ScrollBarVisibilityChanged); } /// @@ -218,15 +232,6 @@ namespace Avalonia.Controls } } - /// - /// Gets a value indicating whether the content can be scrolled horizontally. - /// - public bool CanScrollHorizontally - { - get { return GetValue(CanScrollHorizontallyProperty); } - set { SetValue(CanScrollHorizontallyProperty, value); } - } - /// /// Gets or sets the horizontal scrollbar visibility. /// @@ -245,6 +250,22 @@ namespace Avalonia.Controls set { SetValue(VerticalScrollBarVisibilityProperty, value); } } + /// + /// Gets a value indicating whether the viewer can scroll horizontally. + /// + protected bool CanHorizontallyScroll + { + get { return HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled; } + } + + /// + /// Gets a value indicating whether the viewer can scroll vertically. + /// + protected bool CanVerticallyScroll + { + get { return VerticalScrollBarVisibility != ScrollBarVisibility.Disabled; } + } + /// /// Gets the maximum horizontal scrollbar value. /// @@ -316,7 +337,7 @@ namespace Avalonia.Controls /// /// The control to read the value from. /// The value of the property. - public ScrollBarVisibility GetHorizontalScrollBarVisibility(Control control) + public static ScrollBarVisibility GetHorizontalScrollBarVisibility(Control control) { return control.GetValue(HorizontalScrollBarVisibilityProperty); } @@ -326,7 +347,7 @@ namespace Avalonia.Controls /// /// The control to set the value on. /// The value of the property. - public void SetHorizontalScrollBarVisibility(Control control, ScrollBarVisibility value) + public static void SetHorizontalScrollBarVisibility(Control control, ScrollBarVisibility value) { control.SetValue(HorizontalScrollBarVisibilityProperty, value); } @@ -336,7 +357,7 @@ namespace Avalonia.Controls /// /// The control to read the value from. /// The value of the property. - public ScrollBarVisibility GetVerticalScrollBarVisibility(Control control) + public static ScrollBarVisibility GetVerticalScrollBarVisibility(Control control) { return control.GetValue(VerticalScrollBarVisibilityProperty); } @@ -346,7 +367,7 @@ namespace Avalonia.Controls /// /// The control to set the value on. /// The value of the property. - public void SetVerticalScrollBarVisibility(Control control, ScrollBarVisibility value) + public static void SetVerticalScrollBarVisibility(Control control, ScrollBarVisibility value) { control.SetValue(VerticalScrollBarVisibilityProperty, value); } @@ -385,6 +406,30 @@ namespace Avalonia.Controls } } + private void ScrollBarVisibilityChanged(AvaloniaPropertyChangedEventArgs e) + { + var wasEnabled = !ScrollBarVisibility.Disabled.Equals(e.OldValue); + var isEnabled = !ScrollBarVisibility.Disabled.Equals(e.NewValue); + + if (wasEnabled != isEnabled) + { + if (e.Property == HorizontalScrollBarVisibilityProperty) + { + RaisePropertyChanged( + CanHorizontallyScrollProperty, + wasEnabled, + isEnabled); + } + else if (e.Property == VerticalScrollBarVisibilityProperty) + { + RaisePropertyChanged( + CanVerticallyScrollProperty, + wasEnabled, + isEnabled); + } + } + } + private void CalculatedPropertiesChanged() { // Pass old values of 0 here because we don't have the old values at this point, diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 1a663ed3b6..8f4606884e 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Reactive.Linq; using Avalonia.Controls.Presenters; using Avalonia.Controls.Primitives; -using Avalonia.Controls.Templates; using Avalonia.Controls.Utils; using Avalonia.Input; using Avalonia.Interactivity; @@ -26,9 +25,6 @@ namespace Avalonia.Controls public static readonly StyledProperty AcceptsTabProperty = AvaloniaProperty.Register(nameof(AcceptsTab)); - public static readonly DirectProperty CanScrollHorizontallyProperty = - AvaloniaProperty.RegisterDirect(nameof(CanScrollHorizontally), o => o.CanScrollHorizontally); - public static readonly DirectProperty CaretIndexProperty = AvaloniaProperty.RegisterDirect( nameof(CaretIndex), @@ -92,7 +88,6 @@ namespace Avalonia.Controls private int _caretIndex; private int _selectionStart; private int _selectionEnd; - private bool _canScrollHorizontally; private TextPresenter _presenter; private UndoRedoHelper _undoRedoHelper; private bool _ignoreTextChanges; @@ -106,12 +101,11 @@ namespace Avalonia.Controls public TextBox() { - this.GetObservable(TextWrappingProperty) - .Select(x => x == TextWrapping.NoWrap) - .Subscribe(x => CanScrollHorizontally = x); - - var horizontalScrollBarVisibility = this.GetObservable(AcceptsReturnProperty) - .Select(x => x ? ScrollBarVisibility.Auto : ScrollBarVisibility.Hidden); + var horizontalScrollBarVisibility = Observable.CombineLatest( + this.GetObservable(AcceptsReturnProperty), + this.GetObservable(TextWrappingProperty), + (acceptsReturn, wrapping) => acceptsReturn && wrapping == TextWrapping.NoWrap ? + ScrollBarVisibility.Auto : ScrollBarVisibility.Disabled); Bind( ScrollViewer.HorizontalScrollBarVisibilityProperty, @@ -132,12 +126,6 @@ namespace Avalonia.Controls set { SetValue(AcceptsTabProperty, value); } } - public bool CanScrollHorizontally - { - get { return _canScrollHorizontally; } - private set { SetAndRaise(CanScrollHorizontallyProperty, ref _canScrollHorizontally, value); } - } - public int CaretIndex { get diff --git a/src/Avalonia.Controls/VirtualizingStackPanel.cs b/src/Avalonia.Controls/VirtualizingStackPanel.cs index 409dd231ad..dee537029c 100644 --- a/src/Avalonia.Controls/VirtualizingStackPanel.cs +++ b/src/Avalonia.Controls/VirtualizingStackPanel.cs @@ -3,11 +3,9 @@ using System; using System.Collections.Specialized; -using Avalonia.Controls.Presenters; using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Layout; -using Avalonia.VisualTree; namespace Avalonia.Controls { diff --git a/src/Avalonia.Themes.Default/ListBox.xaml b/src/Avalonia.Themes.Default/ListBox.xaml index aa63a1b6c3..57b0c541b8 100644 --- a/src/Avalonia.Themes.Default/ListBox.xaml +++ b/src/Avalonia.Themes.Default/ListBox.xaml @@ -3,11 +3,16 @@ + + - + + Viewport="{TemplateBinding Path=Viewport, Mode=TwoWay}"/> - diff --git a/src/Avalonia.Themes.Default/TreeView.xaml b/src/Avalonia.Themes.Default/TreeView.xaml index 4ce677667b..42c0b2cdd9 100644 --- a/src/Avalonia.Themes.Default/TreeView.xaml +++ b/src/Avalonia.Themes.Default/TreeView.xaml @@ -7,7 +7,7 @@ - + (target.Presenter.Child); } + [Fact] + public void CanHorizontallyScroll_Should_Track_HorizontalScrollBarVisibility() + { + var target = new ScrollViewer(); + var values = new List(); + + target.GetObservable(ScrollViewer.CanHorizontallyScrollProperty).Subscribe(x => values.Add(x)); + target.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; + target.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; + + Assert.Equal(new[] { true, false, true }, values); + } + + [Fact] + public void CanVerticallyScroll_Should_Track_VerticalScrollBarVisibility() + { + var target = new ScrollViewer(); + var values = new List(); + + target.GetObservable(ScrollViewer.CanVerticallyScrollProperty).Subscribe(x => values.Add(x)); + target.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled; + target.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; + + Assert.Equal(new[] { true, false, true }, values); + } + [Fact] public void Offset_Should_Be_Coerced_To_Viewport() { @@ -59,7 +87,7 @@ namespace Avalonia.Controls.UnitTests [~~ScrollContentPresenter.ExtentProperty] = control[~~ScrollViewer.ExtentProperty], [~~ScrollContentPresenter.OffsetProperty] = control[~~ScrollViewer.OffsetProperty], [~~ScrollContentPresenter.ViewportProperty] = control[~~ScrollViewer.ViewportProperty], - [~ScrollContentPresenter.CanScrollHorizontallyProperty] = control[~ScrollViewer.CanScrollHorizontallyProperty], + [~ScrollContentPresenter.CanHorizontallyScrollProperty] = control[~ScrollViewer.CanHorizontallyScrollProperty], }, new ScrollBar { diff --git a/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs b/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs index 1a07bdc7d1..d4df32a4b3 100644 --- a/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs +++ b/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs @@ -85,7 +85,7 @@ namespace Avalonia.Layout.UnitTests { Width = 200, Height = 200, - CanScrollHorizontally = true, + HorizontalScrollBarVisibility = ScrollBarVisibility.Auto, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Content = textBlock = new TextBlock diff --git a/tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests_HitTesting.cs b/tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests_HitTesting.cs index 3a9e45a02b..a53809a029 100644 --- a/tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests_HitTesting.cs +++ b/tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests_HitTesting.cs @@ -372,6 +372,8 @@ namespace Avalonia.Visuals.UnitTests.Rendering Margin = new Thickness(0, 100, 0, 0), Child = scroll = new ScrollContentPresenter() { + CanHorizontallyScroll = true, + CanVerticallyScroll = true, Content = new StackPanel() { Children = diff --git a/tests/Avalonia.Visuals.UnitTests/Rendering/ImmediateRendererTests_HitTesting.cs b/tests/Avalonia.Visuals.UnitTests/Rendering/ImmediateRendererTests_HitTesting.cs index 9a1d8cb59c..1de6d02a35 100644 --- a/tests/Avalonia.Visuals.UnitTests/Rendering/ImmediateRendererTests_HitTesting.cs +++ b/tests/Avalonia.Visuals.UnitTests/Rendering/ImmediateRendererTests_HitTesting.cs @@ -357,6 +357,8 @@ namespace Avalonia.Visuals.UnitTests.Rendering Margin = new Thickness(0, 100, 0, 0), Child = scroll = new ScrollContentPresenter() { + CanHorizontallyScroll = true, + CanVerticallyScroll = true, Content = new StackPanel() { Children = From f102ef9c1ff359f8490cbb28612e12714190916d Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sun, 21 Jan 2018 15:59:25 +0100 Subject: [PATCH 15/18] Updated cake to latest version. --- tools/packages.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/packages.config b/tools/packages.config index e0dd39bd2b..e52a2c7e98 100644 --- a/tools/packages.config +++ b/tools/packages.config @@ -1,4 +1,4 @@ - + From 6133837600153d459511995e258f533163897bba Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sun, 21 Jan 2018 20:12:13 +0100 Subject: [PATCH 16/18] Locate tests directory in code. Rather than using a hard-coded path. --- tests/Avalonia.RenderTests/TestBase.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/Avalonia.RenderTests/TestBase.cs b/tests/Avalonia.RenderTests/TestBase.cs index ae359c5c5f..321dbc4fbe 100644 --- a/tests/Avalonia.RenderTests/TestBase.cs +++ b/tests/Avalonia.RenderTests/TestBase.cs @@ -46,7 +46,8 @@ namespace Avalonia.Direct2D1.RenderTests public TestBase(string outputPath) { - var testFiles = Path.GetFullPath(@"..\..\..\..\TestFiles\"); + var testPath = GetTestsDirectory(); + var testFiles = Path.Combine(testPath, "TestFiles"); #if AVALONIA_SKIA var platform = "Skia"; #else @@ -142,6 +143,18 @@ namespace Avalonia.Direct2D1.RenderTests } } + private string GetTestsDirectory() + { + var path = Directory.GetCurrentDirectory(); + + while (path.Length > 0 && Path.GetFileName(path) != "tests") + { + path = Path.GetDirectoryName(path); + } + + return path; + } + private class TestThreadingInterface : IPlatformThreadingInterface { public bool CurrentThreadIsLoopThread => MainThread.ManagedThreadId == Thread.CurrentThread.ManagedThreadId; From 7458f28ca9a2e31378ce1f92f6c9f1fe8a53dbeb Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sun, 21 Jan 2018 23:39:53 +0100 Subject: [PATCH 17/18] Fix intermittently failing test. Fixed in https://ci.appveyor.com/project/AvaloniaUI/Avalonia/build/0.1.4466: this should prevent that by keeping both of the data objects alive. --- .../Data/ExpressionObserverTests_Observable.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Observable.cs b/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Observable.cs index 62d5c28f49..aa78c100c1 100644 --- a/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Observable.cs +++ b/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Observable.cs @@ -103,20 +103,22 @@ namespace Avalonia.Markup.UnitTests.Data { using (var sync = UnitTestSynchronizationContext.Begin()) { - var data = new Class1(); - var target = new ExpressionObserver(data, "Next^.Foo", true); + var data1 = new Class1(); + var data2 = new Class2("foo"); + var target = new ExpressionObserver(data1, "Next^.Foo", true); var result = new List(); var sub = target.Subscribe(x => result.Add(x)); - data.Next.OnNext(new Class2("foo")); + data1.Next.OnNext(data2); sync.ExecutePostedCallbacks(); Assert.Equal(new[] { new BindingNotification("foo") }, result); sub.Dispose(); - Assert.Equal(0, data.PropertyChangedSubscriptionCount); + Assert.Equal(0, data1.PropertyChangedSubscriptionCount); - GC.KeepAlive(data); + GC.KeepAlive(data1); + GC.KeepAlive(data2); } } From 51a47b3a946d693d54abbec0e9dd3b184aba1969 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 22 Jan 2018 00:07:19 +0100 Subject: [PATCH 18/18] Instance can be null here. Was causing intermittently failing test: https://ci.appveyor.com/project/AvaloniaUI/Avalonia/build/0.1.4468 --- .../Data/Plugins/AvaloniaPropertyAccessorPlugin.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Markup/Avalonia.Markup/Data/Plugins/AvaloniaPropertyAccessorPlugin.cs b/src/Markup/Avalonia.Markup/Data/Plugins/AvaloniaPropertyAccessorPlugin.cs index 3f6f15ed5b..90eabc69fb 100644 --- a/src/Markup/Avalonia.Markup/Data/Plugins/AvaloniaPropertyAccessorPlugin.cs +++ b/src/Markup/Avalonia.Markup/Data/Plugins/AvaloniaPropertyAccessorPlugin.cs @@ -104,7 +104,7 @@ namespace Avalonia.Markup.Data.Plugins protected override void SubscribeCore(IObserver observer) { - _subscription = Instance.GetWeakObservable(_property).Subscribe(observer); + _subscription = Instance?.GetWeakObservable(_property).Subscribe(observer); } } }