Browse Source

Fix Border/Decorator measure with no child.

Should return border thickness + padding.
pull/58/head
Steven Kirk 11 years ago
parent
commit
7eceb16220
  1. 6
      Perspex.Controls/Border.cs
  2. 6
      Perspex.Controls/Decorator.cs
  3. 127
      Tests/Perspex.Controls.UnitTests/BorderTests.cs
  4. 13
      Tests/Perspex.Controls.UnitTests/DecoratorTests.cs
  5. 1
      Tests/Perspex.Controls.UnitTests/Perspex.Controls.UnitTests.csproj

6
Perspex.Controls/Border.cs

@ -87,8 +87,10 @@ namespace Perspex.Controls
content.Measure(availableSize.Deflate(padding));
return content.DesiredSize.Inflate(padding);
}
return new Size();
else
{
return new Size(padding.Left + padding.Right, padding.Bottom + padding.Top);
}
}
}
}

6
Perspex.Controls/Decorator.cs

@ -82,8 +82,10 @@ namespace Perspex.Controls
content.Measure(availableSize.Deflate(padding));
return content.DesiredSize.Inflate(padding);
}
return new Size();
else
{
return new Size(padding.Left + padding.Right, padding.Bottom + padding.Top);
}
}
}
}

127
Tests/Perspex.Controls.UnitTests/BorderTests.cs

@ -0,0 +1,127 @@
// -----------------------------------------------------------------------
// <copyright file="BorderTests.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls.UnitTests
{
using System.Collections.Specialized;
using System.Linq;
using Xunit;
public class BorderTests
{
[Fact]
public void Setting_Content_Should_Set_Child_Controls_Parent()
{
var target = new Border();
var child = new Control();
target.Content = child;
Assert.Equal(child.Parent, target);
Assert.Equal(((ILogical)child).LogicalParent, target);
}
[Fact]
public void Clearing_Content_Should_Clear_Child_Controls_Parent()
{
var target = new Border();
var child = new Control();
target.Content = child;
target.Content = null;
Assert.Null(child.Parent);
Assert.Null(((ILogical)child).LogicalParent);
}
[Fact]
public void Content_Control_Should_Appear_In_LogicalChildren()
{
var target = new Border();
var child = new Control();
target.Content = child;
Assert.Equal(new[] { child }, ((ILogical)target).LogicalChildren.ToList());
}
[Fact]
public void Clearing_Content_Should_Remove_From_LogicalChildren()
{
var target = new Border();
var child = new Control();
target.Content = child;
target.Content = null;
Assert.Equal(new ILogical[0], ((ILogical)target).LogicalChildren.ToList());
}
[Fact]
public void Setting_Content_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new Border();
var child = new Control();
var called = false;
((ILogical)target).LogicalChildren.CollectionChanged += (s, e) =>
called = e.Action == NotifyCollectionChangedAction.Add;
target.Content = child;
Assert.True(called);
}
[Fact]
public void Clearing_Content_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new Border();
var child = new Control();
var called = false;
target.Content = child;
((ILogical)target).LogicalChildren.CollectionChanged += (s, e) =>
called = e.Action == NotifyCollectionChangedAction.Remove;
target.Content = null;
Assert.True(called);
}
[Fact]
public void Changing_Content_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new Border();
var child1 = new Control();
var child2 = new Control();
var called = false;
target.Content = child1;
((ILogical)target).LogicalChildren.CollectionChanged += (s, e) =>
called = e.Action == NotifyCollectionChangedAction.Replace;
target.Content = child2;
Assert.True(called);
}
[Fact]
public void Measure_Should_Return_BorderThickness_Plus_Padding_When_No_Child_Present()
{
var target = new Border
{
Padding = new Thickness(6),
BorderThickness = 4,
};
target.Measure(new Size(100, 100));
Assert.Equal(new Size(20, 20), target.DesiredSize);
}
}
}

13
Tests/Perspex.Controls.UnitTests/DecoratorTests.cs

@ -109,5 +109,18 @@ namespace Perspex.Controls.UnitTests
Assert.True(called);
}
[Fact]
public void Measure_Should_Return_Padding_When_No_Child_Present()
{
var target = new Decorator
{
Padding = new Thickness(8),
};
target.Measure(new Size(100, 100));
Assert.Equal(new Size(16, 16), target.DesiredSize);
}
}
}

1
Tests/Perspex.Controls.UnitTests/Perspex.Controls.UnitTests.csproj

@ -89,6 +89,7 @@
</Choose>
<ItemGroup>
<Compile Include="ContentPresenterTests.cs" />
<Compile Include="BorderTests.cs" />
<Compile Include="DropDownTests.cs" />
<Compile Include="Presenters\ItemsPresenterTests.cs" />
<Compile Include="ScrollContentPresenterTests.cs" />

Loading…
Cancel
Save