Browse Source

Make Arrange call Measure if !IsMeasureValid.

To follow WPF. Also removed force parameter from Arrange and fixed
Decorator measure invalidation.
pull/387/merge
Steven Kirk 11 years ago
parent
commit
f7f2fc65b7
  1. 1
      src/Perspex.Controls/Decorator.cs
  2. 6
      src/Perspex.Layout/ILayoutable.cs
  3. 10
      src/Perspex.Layout/Layoutable.cs
  4. 33
      tests/Perspex.Layout.UnitTests/ArrangeTests.cs
  5. 1
      tests/Perspex.Layout.UnitTests/Perspex.Layout.UnitTests.csproj
  6. 4
      tests/Perspex.SceneGraph.UnitTests/VisualTree/BoundsTrackerTests.cs

1
src/Perspex.Controls/Decorator.cs

@ -27,6 +27,7 @@ namespace Perspex.Controls
/// </summary> /// </summary>
static Decorator() static Decorator()
{ {
AffectsMeasure(ChildProperty, PaddingProperty);
ChildProperty.Changed.AddClassHandler<Decorator>(x => x.ChildChanged); ChildProperty.Changed.AddClassHandler<Decorator>(x => x.ChildChanged);
} }

6
src/Perspex.Layout/ILayoutable.cs

@ -93,11 +93,7 @@ namespace Perspex.Layout
/// Arranges the control and its children. /// Arranges the control and its children.
/// </summary> /// </summary>
/// <param name="rect">The control's new bounds.</param> /// <param name="rect">The control's new bounds.</param>
/// <param name="force"> void Arrange(Rect rect);
/// If true, the control will be arranged even if <paramref name="rect"/> has not changed
/// from the last arrange.
/// </param>
void Arrange(Rect rect, bool force = false);
/// <summary> /// <summary>
/// Invalidates the measurement of the control and queues a new layout pass. /// Invalidates the measurement of the control and queues a new layout pass.

10
src/Perspex.Layout/Layoutable.cs

@ -352,11 +352,7 @@ namespace Perspex.Layout
/// Arranges the control and its children. /// Arranges the control and its children.
/// </summary> /// </summary>
/// <param name="rect">The control's new bounds.</param> /// <param name="rect">The control's new bounds.</param>
/// <param name="force"> public void Arrange(Rect rect)
/// If true, the control will be arranged even if <paramref name="rect"/> has not changed
/// from the last arrange.
/// </param>
public void Arrange(Rect rect, bool force = false)
{ {
if (IsInvalidRect(rect)) if (IsInvalidRect(rect))
{ {
@ -367,10 +363,10 @@ namespace Perspex.Layout
// be re-run. // be re-run.
if (!IsMeasureValid) if (!IsMeasureValid)
{ {
return; Measure(rect.Size);
} }
if (force || !IsArrangeValid || _previousArrange != rect) if (!IsArrangeValid || _previousArrange != rect)
{ {
_layoutLog.Verbose("Arrange to {Rect} ", rect); _layoutLog.Verbose("Arrange to {Rect} ", rect);

33
tests/Perspex.Layout.UnitTests/ArrangeTests.cs

@ -0,0 +1,33 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Perspex.Controls;
using Xunit;
namespace Perspex.Layout.UnitTests
{
public class ArrangeTests
{
[Fact]
public void Arrange_With_IsMeasureValid_False_Calls_Measure()
{
var target = new TestControl();
Assert.False(target.IsMeasureValid);
target.Arrange(new Rect(0, 0, 120, 120));
Assert.True(target.IsMeasureValid);
Assert.Equal(new Size(120, 120), target.MeasureConstraint);
}
private class TestControl : Border
{
public Size MeasureConstraint { get; private set; }
protected override Size MeasureOverride(Size constraint)
{
MeasureConstraint = constraint;
return base.MeasureOverride(constraint);
}
}
}
}

1
tests/Perspex.Layout.UnitTests/Perspex.Layout.UnitTests.csproj

@ -87,6 +87,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="FullLayoutTests.cs" /> <Compile Include="FullLayoutTests.cs" />
<Compile Include="LayoutManagerTests.cs" /> <Compile Include="LayoutManagerTests.cs" />
<Compile Include="ArrangeTests.cs" />
<Compile Include="MeasureTests.cs" /> <Compile Include="MeasureTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestLayoutRoot.cs" /> <Compile Include="TestLayoutRoot.cs" />

4
tests/Perspex.SceneGraph.UnitTests/VisualTree/BoundsTrackerTests.cs

@ -44,9 +44,9 @@ namespace Perspex.SceneGraph.UnitTests.VisualTree
tree.Padding = new Thickness(15); tree.Padding = new Thickness(15);
tree.Measure(Size.Infinity); tree.Measure(Size.Infinity);
tree.Arrange(new Rect(0, 0, 100, 100), true); tree.Arrange(new Rect(0, 0, 100, 100));
Assert.Equal(new Rect(47, 47, 15, 15), results[1].Bounds); Assert.Equal(new Rect(37, 37, 15, 15), results[1].Bounds);
} }
} }
} }

Loading…
Cancel
Save