Browse Source

Constrain to availableSize in MeasureCore.

#2431 erroneously removed the `.Constrain(availableSize)` call in `Layoutable.Measure`. Now that the WPF source is available, I can see i that WPF does in fact constrain measure to availableSize and Grid relies on this.

Put constraint back in, undo the changes to the controls changed in #2431 (`StackPanel`, `Image`) and update the expected test results based on cross-checks with WPF in https://github.com/wieslawsoltes/WpfUnitTests/pull/1.
pull/2682/head
Steven Kirk 7 years ago
parent
commit
b4d7d03afd
  1. 2
      src/Avalonia.Controls/Image.cs
  2. 4
      src/Avalonia.Controls/StackPanel.cs
  3. 3
      src/Avalonia.Layout/Layoutable.cs
  4. 16
      tests/Avalonia.Controls.UnitTests/StackPanelTests.cs

2
src/Avalonia.Controls/Image.cs

@ -96,7 +96,7 @@ namespace Avalonia.Controls
} }
} }
return result.Constrain(availableSize); return result;
} }
/// <inheritdoc/> /// <inheritdoc/>

4
src/Avalonia.Controls/StackPanel.cs

@ -229,9 +229,7 @@ namespace Avalonia.Controls
stackDesiredSize = stackDesiredSize.WithHeight(stackDesiredSize.Height - (hasVisibleChild ? spacing : 0)); stackDesiredSize = stackDesiredSize.WithHeight(stackDesiredSize.Height - (hasVisibleChild ? spacing : 0));
} }
// TODO: In WPF `.Constrain(availableSize)` is not used. return stackDesiredSize;
//return stackDesiredSize;
return stackDesiredSize.Constrain(availableSize);
} }
/// <summary> /// <summary>

3
src/Avalonia.Layout/Layoutable.cs

@ -534,6 +534,9 @@ namespace Avalonia.Layout
height = Math.Min(height, MaxHeight); height = Math.Min(height, MaxHeight);
height = Math.Max(height, MinHeight); height = Math.Max(height, MinHeight);
width = Math.Min(width, availableSize.Width);
height = Math.Min(height, availableSize.Height);
if (UseLayoutRounding) if (UseLayoutRounding)
{ {
var scale = GetLayoutScale(); var scale = GetLayoutScale();

16
tests/Avalonia.Controls.UnitTests/StackPanelTests.cs

@ -210,13 +210,13 @@ namespace Avalonia.Controls.UnitTests
new[] new[]
{ {
new Rect(0, 0, 50, 10), new Rect(0, 0, 50, 10),
new Rect(0, 10, 150, 10), new Rect(0, 10, 100, 10),
new Rect(25, 20, 50, 10), new Rect(25, 20, 50, 10),
new Rect(-25, 30, 150, 10), new Rect(0, 30, 100, 10),
new Rect(50, 40, 50, 10), new Rect(50, 40, 50, 10),
new Rect(-50, 50, 150, 10), new Rect(0, 50, 100, 10),
new Rect(0, 60, 100, 10), new Rect(0, 60, 100, 10),
new Rect(0, 70, 150, 10), new Rect(0, 70, 100, 10),
}, bounds); }, bounds);
} }
@ -283,13 +283,13 @@ namespace Avalonia.Controls.UnitTests
new[] new[]
{ {
new Rect(0, 0, 10, 50), new Rect(0, 0, 10, 50),
new Rect(10, 0, 10, 150), new Rect(10, 0, 10, 100),
new Rect(20, 25, 10, 50), new Rect(20, 25, 10, 50),
new Rect(30, -25, 10, 150), new Rect(30, 0, 10, 100),
new Rect(40, 50, 10, 50), new Rect(40, 50, 10, 50),
new Rect(50, -50, 10, 150), new Rect(50, 0, 10, 100),
new Rect(60, 0, 10, 100), new Rect(60, 0, 10, 100),
new Rect(70, 0, 10, 150), new Rect(70, 0, 10, 100),
}, bounds); }, bounds);
} }

Loading…
Cancel
Save