|
|
@@ -1,11 +1,6 @@
|
|
|
+using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
-using Avalonia.Controls.Primitives;
|
|
|
-using Avalonia.Input;
|
|
|
-using Avalonia.Platform;
|
|
|
-using Avalonia.UnitTests;
|
|
|
-
|
|
|
-using Moq;
|
|
|
using Xunit;
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
@@ -34,7 +29,6 @@ namespace Avalonia.Controls.UnitTests
|
|
|
|
|
|
private Grid CreateGrid(params (string name, GridLength width, double minWidth, double maxWidth)[] columns)
|
|
|
{
|
|
|
-
|
|
|
var grid = new Grid();
|
|
|
foreach (var k in columns.Select(c => new ColumnDefinition
|
|
|
{
|
|
|
@@ -1178,6 +1172,41 @@ namespace Avalonia.Controls.UnitTests
|
|
|
Assert.Equal(0, grids[0].ColumnDefinitions[0].ActualWidth);
|
|
|
}
|
|
|
|
|
|
+ [Fact]
|
|
|
+ public void Size_Group_Definition_Resizes_Are_Tracked()
|
|
|
+ {
|
|
|
+ var grids = new[] {
|
|
|
+ CreateGrid(("A", new GridLength(5, GridUnitType.Pixel)), (null, new GridLength())),
|
|
|
+ CreateGrid(("A", new GridLength(5, GridUnitType.Pixel)), (null, new GridLength())) };
|
|
|
+ var scope = new Grid();
|
|
|
+ foreach (var xgrids in grids)
|
|
|
+ scope.Children.Add(xgrids);
|
|
|
+
|
|
|
+ var root = new Grid();
|
|
|
+ root.UseLayoutRounding = false;
|
|
|
+ root.SetValue(Grid.IsSharedSizeScopeProperty, true);
|
|
|
+ root.Children.Add(scope);
|
|
|
+
|
|
|
+ root.Measure(new Size(50, 50));
|
|
|
+ root.Arrange(new Rect(new Point(), new Point(50, 50)));
|
|
|
+
|
|
|
+ PrintColumnDefinitions(grids[0]);
|
|
|
+ Assert.Equal(5, grids[0].ColumnDefinitions[0].ActualWidth);
|
|
|
+ Assert.Equal(5, grids[1].ColumnDefinitions[0].ActualWidth);
|
|
|
+
|
|
|
+ grids[0].ColumnDefinitions[0].Width = new GridLength(10, GridUnitType.Pixel);
|
|
|
+
|
|
|
+ foreach (Grid grid in grids)
|
|
|
+ {
|
|
|
+ grid.Measure(new Size(50, 50));
|
|
|
+ grid.Arrange(new Rect(new Point(), new Point(50, 50)));
|
|
|
+ }
|
|
|
+
|
|
|
+ PrintColumnDefinitions(grids[0]);
|
|
|
+ Assert.Equal(10, grids[0].ColumnDefinitions[0].ActualWidth);
|
|
|
+ Assert.Equal(10, grids[1].ColumnDefinitions[0].ActualWidth);
|
|
|
+ }
|
|
|
+
|
|
|
[Fact]
|
|
|
public void Collection_Changes_Are_Tracked()
|
|
|
{
|
|
|
@@ -1270,11 +1299,11 @@ namespace Avalonia.Controls.UnitTests
|
|
|
// grid.Measure(new Size(100, 100));
|
|
|
// grid.Arrange(new Rect(new Point(), new Point(100, 100)));
|
|
|
// PrintColumnDefinitions(grid);
|
|
|
-
|
|
|
+
|
|
|
// NOTE: THIS IS BROKEN IN WPF
|
|
|
// all in group are equal to width (MinWidth) of the sizer in the second column
|
|
|
// Assert.All(grid.ColumnDefinitions.Where(cd => cd.SharedSizeGroup == "A"), cd => Assert.Equal(6 + 1 * 6, cd.ActualWidth));
|
|
|
-
|
|
|
+
|
|
|
// NOTE: THIS IS BROKEN IN WPF
|
|
|
// grid.ColumnDefinitions[2].SharedSizeGroup = null;
|
|
|
|
|
|
@@ -1382,6 +1411,245 @@ namespace Avalonia.Controls.UnitTests
|
|
|
Assert.Equal(new Size(100, 100), grid.Bounds.Size);
|
|
|
}
|
|
|
|
|
|
+ [Theory]
|
|
|
+ [InlineData(true)]
|
|
|
+ [InlineData(false)]
|
|
|
+ public void Changing_Column_Width_Should_Invalidate_Grid(bool setUsingAvaloniaProperty)
|
|
|
+ {
|
|
|
+ var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("1*,1*") };
|
|
|
+
|
|
|
+ Change_Property_And_Verify_Measure_Requested(grid, () =>
|
|
|
+ {
|
|
|
+ if (setUsingAvaloniaProperty)
|
|
|
+ grid.ColumnDefinitions[0][ColumnDefinition.WidthProperty] = new GridLength(5);
|
|
|
+ else
|
|
|
+ grid.ColumnDefinitions[0].Width = new GridLength(5);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData(true)]
|
|
|
+ [InlineData(false)]
|
|
|
+ public void Changing_Column_MinWidth_Should_Invalidate_Grid(bool setUsingAvaloniaProperty)
|
|
|
+ {
|
|
|
+ var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("1*,1*") };
|
|
|
+
|
|
|
+ Change_Property_And_Verify_Measure_Requested(grid, () =>
|
|
|
+ {
|
|
|
+ if (setUsingAvaloniaProperty)
|
|
|
+ grid.ColumnDefinitions[0][ColumnDefinition.MinWidthProperty] = 5;
|
|
|
+ else
|
|
|
+ grid.ColumnDefinitions[0].MinWidth = 5;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData(true)]
|
|
|
+ [InlineData(false)]
|
|
|
+ public void Changing_Column_MaxWidth_Should_Invalidate_Grid(bool setUsingAvaloniaProperty)
|
|
|
+ {
|
|
|
+ var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("1*,1*") };
|
|
|
+
|
|
|
+ Change_Property_And_Verify_Measure_Requested(grid, () =>
|
|
|
+ {
|
|
|
+ if (setUsingAvaloniaProperty)
|
|
|
+ grid.ColumnDefinitions[0][ColumnDefinition.MaxWidthProperty] = 5;
|
|
|
+ else
|
|
|
+ grid.ColumnDefinitions[0].MaxWidth = 5;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData(true)]
|
|
|
+ [InlineData(false)]
|
|
|
+ public void Changing_Row_Height_Should_Invalidate_Grid(bool setUsingAvaloniaProperty)
|
|
|
+ {
|
|
|
+ var grid = new Grid { RowDefinitions = RowDefinitions.Parse("1*,1*") };
|
|
|
+
|
|
|
+ Change_Property_And_Verify_Measure_Requested(grid, () =>
|
|
|
+ {
|
|
|
+ if (setUsingAvaloniaProperty)
|
|
|
+ grid.RowDefinitions[0][RowDefinition.HeightProperty] = new GridLength(5);
|
|
|
+ else
|
|
|
+ grid.RowDefinitions[0].Height = new GridLength(5);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData(true)]
|
|
|
+ [InlineData(false)]
|
|
|
+ public void Changing_Row_MinHeight_Should_Invalidate_Grid(bool setUsingAvaloniaProperty)
|
|
|
+ {
|
|
|
+ var grid = new Grid { RowDefinitions = RowDefinitions.Parse("1*,1*") };
|
|
|
+
|
|
|
+ Change_Property_And_Verify_Measure_Requested(grid, () =>
|
|
|
+ {
|
|
|
+ if (setUsingAvaloniaProperty)
|
|
|
+ grid.RowDefinitions[0][RowDefinition.MinHeightProperty] = 5;
|
|
|
+ else
|
|
|
+ grid.RowDefinitions[0].MinHeight = 5;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData(true)]
|
|
|
+ [InlineData(false)]
|
|
|
+ public void Changing_Row_MaxHeight_Should_Invalidate_Grid(bool setUsingAvaloniaProperty)
|
|
|
+ {
|
|
|
+ var grid = new Grid { RowDefinitions = RowDefinitions.Parse("1*,1*") };
|
|
|
+
|
|
|
+ Change_Property_And_Verify_Measure_Requested(grid, () =>
|
|
|
+ {
|
|
|
+ if (setUsingAvaloniaProperty)
|
|
|
+ grid.RowDefinitions[0][RowDefinition.MaxHeightProperty] = 5;
|
|
|
+ else
|
|
|
+ grid.RowDefinitions[0].MaxHeight = 5;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Adding_Column_Should_Invalidate_Grid()
|
|
|
+ {
|
|
|
+ var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("1*,1*") };
|
|
|
+
|
|
|
+ Change_Property_And_Verify_Measure_Requested(grid, () =>
|
|
|
+ {
|
|
|
+ grid.ColumnDefinitions.Add(new ColumnDefinition(new GridLength(5)));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Adding_Row_Should_Invalidate_Grid()
|
|
|
+ {
|
|
|
+ var grid = new Grid { RowDefinitions = RowDefinitions.Parse("1*,1*") };
|
|
|
+
|
|
|
+ Change_Property_And_Verify_Measure_Requested(grid, () =>
|
|
|
+ {
|
|
|
+ grid.RowDefinitions.Add(new RowDefinition(new GridLength(5)));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Replacing_Columns_Should_Invalidate_Grid()
|
|
|
+ {
|
|
|
+ var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("1*,1*") };
|
|
|
+
|
|
|
+ Change_Property_And_Verify_Measure_Requested(grid, () =>
|
|
|
+ {
|
|
|
+ grid.ColumnDefinitions = ColumnDefinitions.Parse("2*,1*");
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Replacing_Rows_Should_Invalidate_Grid()
|
|
|
+ {
|
|
|
+ var grid = new Grid { RowDefinitions = RowDefinitions.Parse("1*,1*") };
|
|
|
+
|
|
|
+ Change_Property_And_Verify_Measure_Requested(grid, () =>
|
|
|
+ {
|
|
|
+ grid.RowDefinitions = RowDefinitions.Parse("2*,1*");
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Removing_Column_Should_Invalidate_Grid()
|
|
|
+ {
|
|
|
+ var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("1*,1*") };
|
|
|
+
|
|
|
+ Change_Property_And_Verify_Measure_Requested(grid, () =>
|
|
|
+ {
|
|
|
+ grid.ColumnDefinitions.RemoveAt(0);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Removing_Row_Should_Invalidate_Grid()
|
|
|
+ {
|
|
|
+ var grid = new Grid { RowDefinitions = RowDefinitions.Parse("1*,1*") };
|
|
|
+
|
|
|
+ Change_Property_And_Verify_Measure_Requested(grid, () =>
|
|
|
+ {
|
|
|
+ grid.RowDefinitions.RemoveAt(0);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Removing_Child_Should_Invalidate_Grid_And_Be_Operational()
|
|
|
+ {
|
|
|
+ var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("*,Auto") };
|
|
|
+
|
|
|
+ grid.Children.Add(new Decorator() { [Grid.ColumnProperty] = 0 });
|
|
|
+ grid.Children.Add(new Decorator() { Width = 10, Height = 10, [Grid.ColumnProperty] = 1 });
|
|
|
+
|
|
|
+ var size = new Size(100, 100);
|
|
|
+ grid.Measure(size);
|
|
|
+ grid.Arrange(new Rect(size));
|
|
|
+
|
|
|
+ Assert.True(grid.IsMeasureValid);
|
|
|
+ Assert.True(grid.IsArrangeValid);
|
|
|
+
|
|
|
+ Assert.Equal(90, grid.Children[0].Bounds.Width);
|
|
|
+ Assert.Equal(10, grid.Children[1].Bounds.Width);
|
|
|
+
|
|
|
+ grid.Children.RemoveAt(1);
|
|
|
+
|
|
|
+ Assert.False(grid.IsMeasureValid);
|
|
|
+ Assert.False(grid.IsArrangeValid);
|
|
|
+
|
|
|
+ grid.Measure(size);
|
|
|
+ grid.Arrange(new Rect(size));
|
|
|
+
|
|
|
+ Assert.True(grid.IsMeasureValid);
|
|
|
+ Assert.True(grid.IsArrangeValid);
|
|
|
+
|
|
|
+ Assert.Equal(100, grid.Children[0].Bounds.Width);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Adding_Child_Should_Invalidate_Grid_And_Be_Operational()
|
|
|
+ {
|
|
|
+ var grid = new Grid { ColumnDefinitions = ColumnDefinitions.Parse("*,Auto") };
|
|
|
+
|
|
|
+ grid.Children.Add(new Decorator() { [Grid.ColumnProperty] = 0 });
|
|
|
+
|
|
|
+ var size = new Size(100, 100);
|
|
|
+ grid.Measure(size);
|
|
|
+ grid.Arrange(new Rect(size));
|
|
|
+
|
|
|
+ Assert.True(grid.IsMeasureValid);
|
|
|
+ Assert.True(grid.IsArrangeValid);
|
|
|
+
|
|
|
+ Assert.Equal(100, grid.Children[0].Bounds.Width);
|
|
|
+
|
|
|
+ grid.Children.Add(new Decorator() { Width = 10, Height = 10, [Grid.ColumnProperty] = 1 });
|
|
|
+
|
|
|
+ Assert.False(grid.IsMeasureValid);
|
|
|
+ Assert.False(grid.IsArrangeValid);
|
|
|
+
|
|
|
+ grid.Measure(size);
|
|
|
+ grid.Arrange(new Rect(size));
|
|
|
+
|
|
|
+ Assert.True(grid.IsMeasureValid);
|
|
|
+ Assert.True(grid.IsArrangeValid);
|
|
|
+
|
|
|
+ Assert.Equal(90, grid.Children[0].Bounds.Width);
|
|
|
+ Assert.Equal(10, grid.Children[1].Bounds.Width);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void Change_Property_And_Verify_Measure_Requested(Grid grid, Action change)
|
|
|
+ {
|
|
|
+ grid.Measure(new Size(100, 100));
|
|
|
+ grid.Arrange(new Rect(grid.DesiredSize));
|
|
|
+
|
|
|
+ Assert.True(grid.IsMeasureValid);
|
|
|
+ Assert.True(grid.IsArrangeValid);
|
|
|
+
|
|
|
+ change();
|
|
|
+
|
|
|
+ Assert.False(grid.IsMeasureValid);
|
|
|
+ Assert.False(grid.IsArrangeValid);
|
|
|
+ }
|
|
|
+
|
|
|
private class TestControl : Control
|
|
|
{
|
|
|
public Size MeasureSize { get; set; }
|