From e700832ee075a79a1d021e4662b1f5fa7baf7b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro?= Date: Thu, 5 Sep 2019 17:27:41 +0100 Subject: [PATCH 1/7] Updated ReactiveUI to version 10.0.1. --- build/ReactiveUI.props | 2 +- build/Rx.props | 2 +- .../ViewModels/MainWindowViewModel.cs | 7 ++--- .../ViewModels/MainWindowViewModel.cs | 5 ++-- .../ViewModels/MainWindowViewModel.cs | 27 ++++++++++--------- .../AvaloniaActivationForViewFetcher.cs | 2 +- src/Avalonia.ReactiveUI/RoutedViewHost.cs | 4 +-- .../AvaloniaActivationForViewFetcherTest.cs | 8 +++--- 8 files changed, 30 insertions(+), 27 deletions(-) diff --git a/build/ReactiveUI.props b/build/ReactiveUI.props index 1208be34b8..1292f52c4a 100644 --- a/build/ReactiveUI.props +++ b/build/ReactiveUI.props @@ -1,5 +1,5 @@ - + diff --git a/build/Rx.props b/build/Rx.props index 359ce53a92..edff0af160 100644 --- a/build/Rx.props +++ b/build/Rx.props @@ -1,5 +1,5 @@  - + diff --git a/samples/BindingDemo/ViewModels/MainWindowViewModel.cs b/samples/BindingDemo/ViewModels/MainWindowViewModel.cs index 858fb5159a..22d01e0765 100644 --- a/samples/BindingDemo/ViewModels/MainWindowViewModel.cs +++ b/samples/BindingDemo/ViewModels/MainWindowViewModel.cs @@ -1,10 +1,11 @@ using System; using System.Collections.ObjectModel; using System.Linq; -using ReactiveUI; +using System.Reactive; using System.Reactive.Linq; using System.Threading.Tasks; using System.Threading; +using ReactiveUI; namespace BindingDemo.ViewModels { @@ -56,7 +57,7 @@ namespace BindingDemo.ViewModels public ObservableCollection Items { get; } public ObservableCollection SelectedItems { get; } - public ReactiveCommand ShuffleItems { get; } + public ReactiveCommand ShuffleItems { get; } public string BooleanString { @@ -89,7 +90,7 @@ namespace BindingDemo.ViewModels } public IObservable CurrentTimeObservable { get; } - public ReactiveCommand StringValueCommand { get; } + public ReactiveCommand StringValueCommand { get; } public DataAnnotationsErrorViewModel DataAnnotationsValidation { get; } = new DataAnnotationsErrorViewModel(); public ExceptionErrorViewModel ExceptionDataValidation { get; } = new ExceptionErrorViewModel(); diff --git a/samples/RenderDemo/ViewModels/MainWindowViewModel.cs b/samples/RenderDemo/ViewModels/MainWindowViewModel.cs index 0cb5e1b87b..d2d789a687 100644 --- a/samples/RenderDemo/ViewModels/MainWindowViewModel.cs +++ b/samples/RenderDemo/ViewModels/MainWindowViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Reactive; using ReactiveUI; namespace RenderDemo.ViewModels @@ -26,7 +27,7 @@ namespace RenderDemo.ViewModels set { this.RaiseAndSetIfChanged(ref drawFps, value); } } - public ReactiveCommand ToggleDrawDirtyRects { get; } - public ReactiveCommand ToggleDrawFps { get; } + public ReactiveCommand ToggleDrawDirtyRects { get; } + public ReactiveCommand ToggleDrawFps { get; } } } diff --git a/samples/VirtualizationDemo/ViewModels/MainWindowViewModel.cs b/samples/VirtualizationDemo/ViewModels/MainWindowViewModel.cs index 93fe09a156..37c7178c56 100644 --- a/samples/VirtualizationDemo/ViewModels/MainWindowViewModel.cs +++ b/samples/VirtualizationDemo/ViewModels/MainWindowViewModel.cs @@ -4,10 +4,10 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reactive; using Avalonia.Collections; using Avalonia.Controls; using Avalonia.Controls.Primitives; -using ReactiveUI.Legacy; using ReactiveUI; using Avalonia.Layout; @@ -18,7 +18,7 @@ namespace VirtualizationDemo.ViewModels private int _itemCount = 200; private string _newItemString = "New Item"; private int _newItemIndex; - private IReactiveList _items; + private AvaloniaList _items; private string _prefix = "Item"; private ScrollBarVisibility _horizontalScrollBarVisibility = ScrollBarVisibility.Auto; private ScrollBarVisibility _verticalScrollBarVisibility = ScrollBarVisibility.Auto; @@ -28,11 +28,12 @@ namespace VirtualizationDemo.ViewModels public MainWindowViewModel() { this.WhenAnyValue(x => x.ItemCount).Subscribe(ResizeItems); - RecreateCommand = ReactiveCommand.Create(() => Recreate()); - AddItemCommand = ReactiveCommand.Create(() => AddItem()); + RecreateCommand = ReactiveCommand.Create(Recreate); - RemoveItemCommand = ReactiveCommand.Create(() => Remove()); + AddItemCommand = ReactiveCommand.Create(AddItem); + + RemoveItemCommand = ReactiveCommand.Create(Remove); SelectFirstCommand = ReactiveCommand.Create(() => SelectItem(0)); @@ -54,7 +55,7 @@ namespace VirtualizationDemo.ViewModels public AvaloniaList SelectedItems { get; } = new AvaloniaList(); - public IReactiveList Items + public AvaloniaList Items { get { return _items; } private set { this.RaiseAndSetIfChanged(ref _items, value); } @@ -93,11 +94,11 @@ namespace VirtualizationDemo.ViewModels public IEnumerable VirtualizationModes => Enum.GetValues(typeof(ItemVirtualizationMode)).Cast(); - public ReactiveCommand AddItemCommand { get; private set; } - public ReactiveCommand RecreateCommand { get; private set; } - public ReactiveCommand RemoveItemCommand { get; private set; } - public ReactiveCommand SelectFirstCommand { get; private set; } - public ReactiveCommand SelectLastCommand { get; private set; } + public ReactiveCommand AddItemCommand { get; private set; } + public ReactiveCommand RecreateCommand { get; private set; } + public ReactiveCommand RemoveItemCommand { get; private set; } + public ReactiveCommand SelectFirstCommand { get; private set; } + public ReactiveCommand SelectLastCommand { get; private set; } public void RandomizeSize() { @@ -123,7 +124,7 @@ namespace VirtualizationDemo.ViewModels { var items = Enumerable.Range(0, count) .Select(x => new ItemViewModel(x)); - Items = new ReactiveList(items); + Items = new AvaloniaList(items); } else if (count > Items.Count) { @@ -162,7 +163,7 @@ namespace VirtualizationDemo.ViewModels _prefix = _prefix == "Item" ? "Recreated" : "Item"; var items = Enumerable.Range(0, _itemCount) .Select(x => new ItemViewModel(x, _prefix)); - Items = new ReactiveList(items); + Items = new AvaloniaList(items); } private void SelectItem(int index) diff --git a/src/Avalonia.ReactiveUI/AvaloniaActivationForViewFetcher.cs b/src/Avalonia.ReactiveUI/AvaloniaActivationForViewFetcher.cs index cfa7a270be..5a4d625c41 100644 --- a/src/Avalonia.ReactiveUI/AvaloniaActivationForViewFetcher.cs +++ b/src/Avalonia.ReactiveUI/AvaloniaActivationForViewFetcher.cs @@ -27,7 +27,7 @@ namespace Avalonia.ReactiveUI /// /// Returns activation observable for activatable Avalonia view. /// - public IObservable GetActivationForView(IActivatable view) + public IObservable GetActivationForView(IActivatableView view) { if (!(view is IVisual visual)) return Observable.Return(false); if (view is WindowBase window) return GetActivationForWindowBase(window); diff --git a/src/Avalonia.ReactiveUI/RoutedViewHost.cs b/src/Avalonia.ReactiveUI/RoutedViewHost.cs index 05edeea683..5d96fd264a 100644 --- a/src/Avalonia.ReactiveUI/RoutedViewHost.cs +++ b/src/Avalonia.ReactiveUI/RoutedViewHost.cs @@ -53,7 +53,7 @@ namespace Avalonia.ReactiveUI /// ReactiveUI routing documentation website for more info. /// /// - public class RoutedViewHost : TransitioningContentControl, IActivatable, IEnableLogger + public class RoutedViewHost : TransitioningContentControl, IActivatableView, IEnableLogger { /// /// for the property. @@ -118,4 +118,4 @@ namespace Avalonia.ReactiveUI Content = viewInstance; } } -} \ No newline at end of file +} diff --git a/tests/Avalonia.ReactiveUI.UnitTests/AvaloniaActivationForViewFetcherTest.cs b/tests/Avalonia.ReactiveUI.UnitTests/AvaloniaActivationForViewFetcherTest.cs index 1d85312b1a..643dd3efac 100644 --- a/tests/Avalonia.ReactiveUI.UnitTests/AvaloniaActivationForViewFetcherTest.cs +++ b/tests/Avalonia.ReactiveUI.UnitTests/AvaloniaActivationForViewFetcherTest.cs @@ -20,9 +20,9 @@ namespace Avalonia.ReactiveUI.UnitTests { public class AvaloniaActivationForViewFetcherTest { - public class TestUserControl : UserControl, IActivatable { } + public class TestUserControl : UserControl, IActivatableView { } - public class TestUserControlWithWhenActivated : UserControl, IActivatable + public class TestUserControlWithWhenActivated : UserControl, IActivatableView { public bool Active { get; private set; } @@ -38,7 +38,7 @@ namespace Avalonia.ReactiveUI.UnitTests } } - public class TestWindowWithWhenActivated : Window, IActivatable + public class TestWindowWithWhenActivated : Window, IActivatableView { public bool Active { get; private set; } @@ -54,7 +54,7 @@ namespace Avalonia.ReactiveUI.UnitTests } } - public class ActivatableViewModel : ISupportsActivation + public class ActivatableViewModel : IActivatableViewModel { public ViewModelActivator Activator { get; } From 570313f392896d3e3d66b24e7bda8742f1d414cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro?= Date: Fri, 6 Sep 2019 16:31:56 +0100 Subject: [PATCH 2/7] Updated System.Memory to version 4.5.3. --- build/System.Memory.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/System.Memory.props b/build/System.Memory.props index b328f7fd97..b36998a780 100644 --- a/build/System.Memory.props +++ b/build/System.Memory.props @@ -1,5 +1,5 @@ - + From b6d77a7a0f531da0a2f045c47eb238e019eb4770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro?= Date: Sun, 8 Sep 2019 18:58:26 +0100 Subject: [PATCH 3/7] Updated ReactiveUI to version 10.1.1. --- build/ReactiveUI.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/ReactiveUI.props b/build/ReactiveUI.props index 1292f52c4a..7caeaf90ae 100644 --- a/build/ReactiveUI.props +++ b/build/ReactiveUI.props @@ -1,5 +1,5 @@ - + From 1cf93ad393540cd81383708fbc4e16781765f932 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Tue, 17 Sep 2019 23:04:12 -0400 Subject: [PATCH 4/7] Add ItemWidth and ItemHeight properties to WrapPanel (with unit tests) --- src/Avalonia.Controls/WrapPanel.cs | 198 +++++++++++------- .../WrapPanelTests.cs | 23 ++ 2 files changed, 150 insertions(+), 71 deletions(-) diff --git a/src/Avalonia.Controls/WrapPanel.cs b/src/Avalonia.Controls/WrapPanel.cs index 3acf341c35..418a59b64e 100644 --- a/src/Avalonia.Controls/WrapPanel.cs +++ b/src/Avalonia.Controls/WrapPanel.cs @@ -15,7 +15,7 @@ namespace Avalonia.Controls /// Positions child elements in sequential position from left to right, /// breaking content to the next line at the edge of the containing box. /// Subsequent ordering happens sequentially from top to bottom or from right to left, - /// depending on the value of the Orientation property. + /// depending on the value of the property. /// public class WrapPanel : Panel, INavigableContainer { @@ -25,6 +25,18 @@ namespace Avalonia.Controls public static readonly StyledProperty OrientationProperty = AvaloniaProperty.Register(nameof(Orientation), defaultValue: Orientation.Horizontal); + /// + /// Defines the property. + /// + public static readonly StyledProperty ItemWidthProperty = + AvaloniaProperty.Register(nameof(ItemWidth), double.NaN); + + /// + /// Defines the property. + /// + public static readonly StyledProperty ItemHeightProperty = + AvaloniaProperty.Register(nameof(ItemHeight), double.NaN); + /// /// Initializes static members of the class. /// @@ -42,6 +54,24 @@ namespace Avalonia.Controls set { SetValue(OrientationProperty, value); } } + /// + /// Gets or sets the width of all items in the WrapPanel. + /// + public double ItemWidth + { + get { return GetValue(ItemWidthProperty); } + set { SetValue(ItemWidthProperty, value); } + } + + /// + /// Gets or sets the height of all items in the WrapPanel. + /// + public double ItemHeight + { + get { return GetValue(ItemHeightProperty); } + set { SetValue(ItemHeightProperty, value); } + } + /// /// Gets the next control in the specified direction. /// @@ -51,7 +81,9 @@ namespace Avalonia.Controls /// The control. IInputElement INavigableContainer.GetControl(NavigationDirection direction, IInputElement from, bool wrap) { - var horiz = Orientation == Orientation.Horizontal; + var orientation = Orientation; + var children = Children; + bool horiz = orientation == Orientation.Horizontal; int index = Children.IndexOf((IControl)from); switch (direction) @@ -60,7 +92,7 @@ namespace Avalonia.Controls index = 0; break; case NavigationDirection.Last: - index = Children.Count - 1; + index = children.Count - 1; break; case NavigationDirection.Next: ++index; @@ -82,9 +114,9 @@ namespace Avalonia.Controls break; } - if (index >= 0 && index < Children.Count) + if (index >= 0 && index < children.Count) { - return Children[index]; + return children[index]; } else { @@ -95,40 +127,51 @@ namespace Avalonia.Controls /// protected override Size MeasureOverride(Size constraint) { - var curLineSize = new UVSize(Orientation); - var panelSize = new UVSize(Orientation); - var uvConstraint = new UVSize(Orientation, constraint.Width, constraint.Height); - - var childConstraint = new Size(constraint.Width, constraint.Height); - - for (int i = 0, count = Children.Count; i < count; i++) + double itemWidth = ItemWidth; + double itemHeight = ItemHeight; + var orientation = Orientation; + var children = Children; + var curLineSize = new UVSize(orientation); + var panelSize = new UVSize(orientation); + var uvConstraint = new UVSize(orientation, constraint.Width, constraint.Height); + bool itemWidthSet = !double.IsNaN(itemWidth); + bool itemHeightSet = !double.IsNaN(itemHeight); + + var childConstraint = new Size( + itemWidthSet ? itemWidth : constraint.Width, + itemHeightSet ? itemHeight : constraint.Height); + + for (int i = 0, count = children.Count; i < count; i++) { - var child = Children[i]; - if (child == null) continue; - - //Flow passes its own constrint to children - child.Measure(childConstraint); - - //this is the size of the child in UV space - var sz = new UVSize(Orientation, child.DesiredSize.Width, child.DesiredSize.Height); - - if (MathUtilities.GreaterThan(curLineSize.U + sz.U, uvConstraint.U)) //need to switch to another line + var child = children[i]; + if (child != null) { - panelSize.U = Max(curLineSize.U, panelSize.U); - panelSize.V += curLineSize.V; - curLineSize = sz; + //Flow passes its own constrint to children + child.Measure(childConstraint); + + //this is the size of the child in UV space + var sz = new UVSize(orientation, + itemWidthSet ? itemWidth : child.DesiredSize.Width, + itemHeightSet ? itemHeight : child.DesiredSize.Height); - if (MathUtilities.GreaterThan(sz.U, uvConstraint.U)) //the element is wider then the constrint - give it a separate line + if (MathUtilities.GreaterThan(curLineSize.U + sz.U, uvConstraint.U)) //need to switch to another line { - panelSize.U = Max(sz.U, panelSize.U); - panelSize.V += sz.V; - curLineSize = new UVSize(Orientation); + panelSize.U = Max(curLineSize.U, panelSize.U); + panelSize.V += curLineSize.V; + curLineSize = sz; + + if (MathUtilities.GreaterThan(sz.U, uvConstraint.U)) //the element is wider then the constrint - give it a separate line + { + panelSize.U = Max(sz.U, panelSize.U); + panelSize.V += sz.V; + curLineSize = new UVSize(orientation); + } + } + else //continue to accumulate a line + { + curLineSize.U += sz.U; + curLineSize.V = Max(sz.V, curLineSize.V); } - } - else //continue to accumulate a line - { - curLineSize.U += sz.U; - curLineSize.V = Max(sz.V, curLineSize.V); } } @@ -143,68 +186,81 @@ namespace Avalonia.Controls /// protected override Size ArrangeOverride(Size finalSize) { + double itemWidth = ItemWidth; + double itemHeight = ItemHeight; + var orientation = Orientation; + var children = Children; int firstInLine = 0; double accumulatedV = 0; - UVSize curLineSize = new UVSize(Orientation); - UVSize uvFinalSize = new UVSize(Orientation, finalSize.Width, finalSize.Height); - - for (int i = 0; i < Children.Count; i++) + double itemU = orientation == Orientation.Horizontal ? itemWidth : itemHeight; + var curLineSize = new UVSize(orientation); + var uvFinalSize = new UVSize(orientation, finalSize.Width, finalSize.Height); + bool itemWidthSet = !double.IsNaN(itemWidth); + bool itemHeightSet = !double.IsNaN(itemHeight); + bool useItemU = orientation == Orientation.Horizontal ? itemWidthSet : itemHeightSet; + + for (int i = 0; i < children.Count; i++) { - var child = Children[i]; - if (child == null) continue; + var child = children[i]; + if (child != null) + { + var sz = new UVSize(orientation, + itemWidthSet ? itemWidth : child.DesiredSize.Width, + itemHeightSet ? itemHeight : child.DesiredSize.Height); - var sz = new UVSize(Orientation, child.DesiredSize.Width, child.DesiredSize.Height); + if (MathUtilities.GreaterThan(curLineSize.U + sz.U, uvFinalSize.U)) //need to switch to another line + { + ArrangeLine(accumulatedV, curLineSize.V, firstInLine, i, useItemU, itemU); - if (MathUtilities.GreaterThan(curLineSize.U + sz.U, uvFinalSize.U)) //need to switch to another line - { - arrangeLine(accumulatedV, curLineSize.V, firstInLine, i); + accumulatedV += curLineSize.V; + curLineSize = sz; - accumulatedV += curLineSize.V; - curLineSize = sz; + if (MathUtilities.GreaterThan(sz.U, uvFinalSize.U)) //the element is wider then the constraint - give it a separate line + { + //switch to next line which only contain one element + ArrangeLine(accumulatedV, sz.V, i, ++i, useItemU, itemU); - if (MathUtilities.GreaterThan(sz.U, uvFinalSize.U)) //the element is wider then the constraint - give it a separate line + accumulatedV += sz.V; + curLineSize = new UVSize(orientation); + } + firstInLine = i; + } + else //continue to accumulate a line { - //switch to next line which only contain one element - arrangeLine(accumulatedV, sz.V, i, ++i); - - accumulatedV += sz.V; - curLineSize = new UVSize(Orientation); + curLineSize.U += sz.U; + curLineSize.V = Max(sz.V, curLineSize.V); } - firstInLine = i; - } - else //continue to accumulate a line - { - curLineSize.U += sz.U; - curLineSize.V = Max(sz.V, curLineSize.V); } } //arrange the last line, if any - if (firstInLine < Children.Count) + if (firstInLine < children.Count) { - arrangeLine(accumulatedV, curLineSize.V, firstInLine, Children.Count); + ArrangeLine(accumulatedV, curLineSize.V, firstInLine, children.Count, useItemU, itemU); } return finalSize; } - private void arrangeLine(double v, double lineV, int start, int end) + private void ArrangeLine(double v, double lineV, int start, int end, bool useItemU, double itemU) { + var orientation = Orientation; + var children = Children; double u = 0; - bool isHorizontal = (Orientation == Orientation.Horizontal); + bool isHorizontal = orientation == Orientation.Horizontal; for (int i = start; i < end; i++) { - var child = Children[i]; + var child = children[i]; if (child != null) { - UVSize childSize = new UVSize(Orientation, child.DesiredSize.Width, child.DesiredSize.Height); - double layoutSlotU = childSize.U; + var childSize = new UVSize(orientation, child.DesiredSize.Width, child.DesiredSize.Height); + double layoutSlotU = useItemU ? itemU : childSize.U; child.Arrange(new Rect( - (isHorizontal ? u : v), - (isHorizontal ? v : u), - (isHorizontal ? layoutSlotU : lineV), - (isHorizontal ? lineV : layoutSlotU))); + isHorizontal ? u : v, + isHorizontal ? v : u, + isHorizontal ? layoutSlotU : lineV, + isHorizontal ? lineV : layoutSlotU)); u += layoutSlotU; } } @@ -232,12 +288,12 @@ namespace Avalonia.Controls internal double Width { - get { return (_orientation == Orientation.Horizontal ? U : V); } + get { return _orientation == Orientation.Horizontal ? U : V; } set { if (_orientation == Orientation.Horizontal) U = value; else V = value; } } internal double Height { - get { return (_orientation == Orientation.Horizontal ? V : U); } + get { return _orientation == Orientation.Horizontal ? V : U; } set { if (_orientation == Orientation.Horizontal) V = value; else U = value; } } } diff --git a/tests/Avalonia.Controls.UnitTests/WrapPanelTests.cs b/tests/Avalonia.Controls.UnitTests/WrapPanelTests.cs index a0511761e4..e0fa02814a 100644 --- a/tests/Avalonia.Controls.UnitTests/WrapPanelTests.cs +++ b/tests/Avalonia.Controls.UnitTests/WrapPanelTests.cs @@ -93,5 +93,28 @@ namespace Avalonia.Controls.UnitTests Assert.Equal(new Rect(0, 0, 100, 50), target.Children[0].Bounds); Assert.Equal(new Rect(100, 0, 100, 50), target.Children[1].Bounds); } + + [Fact] + public void Applies_ItemWidth_And_ItemHeight_Properties() + { + var target = new WrapPanel + { + Width = 50, + ItemWidth = 20, + ItemHeight = 15, + Children = + { + new Border(), + new Border { Width = 50, Height = 50 }, + } + }; + + target.Measure(Size.Infinity); + target.Arrange(new Rect(target.DesiredSize)); + + Assert.Equal(new Size(50, 15), target.Bounds.Size); + Assert.Equal(new Rect(0, 0, 20, 15), target.Children[0].Bounds); + Assert.Equal(new Rect(20, 15, 20, 15), target.Children[1].Bounds); + } } } From 9cc2d777addb1d46593d87e25baf4056b6e6658a Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Tue, 17 Sep 2019 23:56:47 -0400 Subject: [PATCH 5/7] Update WrapPanelTests.cs --- .../WrapPanelTests.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/Avalonia.Controls.UnitTests/WrapPanelTests.cs b/tests/Avalonia.Controls.UnitTests/WrapPanelTests.cs index e0fa02814a..149f723458 100644 --- a/tests/Avalonia.Controls.UnitTests/WrapPanelTests.cs +++ b/tests/Avalonia.Controls.UnitTests/WrapPanelTests.cs @@ -97,24 +97,25 @@ namespace Avalonia.Controls.UnitTests [Fact] public void Applies_ItemWidth_And_ItemHeight_Properties() { - var target = new WrapPanel - { - Width = 50, - ItemWidth = 20, - ItemHeight = 15, - Children = - { - new Border(), - new Border { Width = 50, Height = 50 }, - } - }; + var target = new WrapPanel() + { + Orientation = Orientation.Horizontal, + Width = 50, + ItemWidth = 20, + ItemHeight = 15, + Children = + { + new Border(), + new Border { Width = 50, Height = 50 }, + } + }; target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(new Size(50, 15), target.Bounds.Size); Assert.Equal(new Rect(0, 0, 20, 15), target.Children[0].Bounds); - Assert.Equal(new Rect(20, 15, 20, 15), target.Children[1].Bounds); + Assert.Equal(new Rect(20, 0, 20, 15), target.Children[1].Bounds); } } } From 1566c1a0689b6697149f229aee19dccde5794954 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Wed, 18 Sep 2019 11:12:37 -0400 Subject: [PATCH 6/7] Update comments --- src/Avalonia.Controls/WrapPanel.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Avalonia.Controls/WrapPanel.cs b/src/Avalonia.Controls/WrapPanel.cs index 418a59b64e..7c88401615 100644 --- a/src/Avalonia.Controls/WrapPanel.cs +++ b/src/Avalonia.Controls/WrapPanel.cs @@ -146,28 +146,28 @@ namespace Avalonia.Controls var child = children[i]; if (child != null) { - //Flow passes its own constrint to children + // Flow passes its own constraint to children child.Measure(childConstraint); - //this is the size of the child in UV space + // This is the size of the child in UV space var sz = new UVSize(orientation, itemWidthSet ? itemWidth : child.DesiredSize.Width, itemHeightSet ? itemHeight : child.DesiredSize.Height); - if (MathUtilities.GreaterThan(curLineSize.U + sz.U, uvConstraint.U)) //need to switch to another line + if (MathUtilities.GreaterThan(curLineSize.U + sz.U, uvConstraint.U)) // Need to switch to another line { panelSize.U = Max(curLineSize.U, panelSize.U); panelSize.V += curLineSize.V; curLineSize = sz; - if (MathUtilities.GreaterThan(sz.U, uvConstraint.U)) //the element is wider then the constrint - give it a separate line + if (MathUtilities.GreaterThan(sz.U, uvConstraint.U)) // The element is wider then the constraint - give it a separate line { panelSize.U = Max(sz.U, panelSize.U); panelSize.V += sz.V; curLineSize = new UVSize(orientation); } } - else //continue to accumulate a line + else // Continue to accumulate a line { curLineSize.U += sz.U; curLineSize.V = Max(sz.V, curLineSize.V); @@ -175,11 +175,11 @@ namespace Avalonia.Controls } } - //the last line size, if any should be added + // The last line size, if any should be added panelSize.U = Max(curLineSize.U, panelSize.U); panelSize.V += curLineSize.V; - //go from UV space to W/H space + // Go from UV space to W/H space return new Size(panelSize.Width, panelSize.Height); } @@ -208,16 +208,16 @@ namespace Avalonia.Controls itemWidthSet ? itemWidth : child.DesiredSize.Width, itemHeightSet ? itemHeight : child.DesiredSize.Height); - if (MathUtilities.GreaterThan(curLineSize.U + sz.U, uvFinalSize.U)) //need to switch to another line + if (MathUtilities.GreaterThan(curLineSize.U + sz.U, uvFinalSize.U)) // Need to switch to another line { ArrangeLine(accumulatedV, curLineSize.V, firstInLine, i, useItemU, itemU); accumulatedV += curLineSize.V; curLineSize = sz; - if (MathUtilities.GreaterThan(sz.U, uvFinalSize.U)) //the element is wider then the constraint - give it a separate line + if (MathUtilities.GreaterThan(sz.U, uvFinalSize.U)) // The element is wider then the constraint - give it a separate line { - //switch to next line which only contain one element + // Switch to next line which only contain one element ArrangeLine(accumulatedV, sz.V, i, ++i, useItemU, itemU); accumulatedV += sz.V; @@ -225,7 +225,7 @@ namespace Avalonia.Controls } firstInLine = i; } - else //continue to accumulate a line + else // Continue to accumulate a line { curLineSize.U += sz.U; curLineSize.V = Max(sz.V, curLineSize.V); @@ -233,7 +233,7 @@ namespace Avalonia.Controls } } - //arrange the last line, if any + // Arrange the last line, if any if (firstInLine < children.Count) { ArrangeLine(accumulatedV, curLineSize.V, firstInLine, children.Count, useItemU, itemU); From 2ee5a21dd7366fa98fbf350b07b18d5d164927e1 Mon Sep 17 00:00:00 2001 From: Kermalis <29823718+Kermalis@users.noreply.github.com> Date: Sun, 22 Sep 2019 12:51:59 -0400 Subject: [PATCH 7/7] Remove broken test for now An issue will be made after merging because it's unrelated --- tests/Avalonia.Controls.UnitTests/WrapPanelTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Avalonia.Controls.UnitTests/WrapPanelTests.cs b/tests/Avalonia.Controls.UnitTests/WrapPanelTests.cs index 149f723458..fd93df46b8 100644 --- a/tests/Avalonia.Controls.UnitTests/WrapPanelTests.cs +++ b/tests/Avalonia.Controls.UnitTests/WrapPanelTests.cs @@ -106,7 +106,7 @@ namespace Avalonia.Controls.UnitTests Children = { new Border(), - new Border { Width = 50, Height = 50 }, + new Border(), } };