Browse Source

More work on layout.

Mostly works but Test_ScrollViewer_With_TextBlock is failing again.
pull/10/head
Steven Kirk 12 years ago
parent
commit
a8ae15b3ed
  1. 40
      Perspex.Layout.UnitTests/FullLayoutTests.cs
  2. 8
      Perspex.Layout/LayoutManager.cs
  3. 48
      Perspex.Layout/Layoutable.cs

40
Perspex.Layout.UnitTests/FullLayoutTests.cs

@ -4,6 +4,7 @@
// </copyright>
// -----------------------------------------------------------------------
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Perspex.Layout.UnitTests
{
using System.Linq;
@ -24,6 +25,44 @@ namespace Perspex.Layout.UnitTests
[TestClass]
public class FullLayoutTests
{
[TestMethod]
public void Grandchild_Size_Changed()
{
using (var context = Locator.CurrentMutable.WithResolver())
{
this.RegisterServices();
Border border;
TextBlock textBlock;
var window = new Window()
{
Content = (border = new Border
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Content = new Border
{
Content = (textBlock = new TextBlock
{
Width = 400,
Height = 400,
Text = "Hello World!",
}),
}
})
};
window.LayoutManager.ExecuteLayoutPass();
Assert.AreEqual(new Size(400, 400), border.ActualSize);
textBlock.Width = 200;
window.LayoutManager.ExecuteLayoutPass();
Assert.AreEqual(new Size(200, 400), border.ActualSize);
}
}
[TestMethod]
public void Test_ScrollViewer_With_TextBlock()
{
@ -38,7 +77,6 @@ namespace Perspex.Layout.UnitTests
{
Content = (scrollViewer = new ScrollViewer
{
Id = "scrollViewer",
Width = 200,
Height = 200,
HorizontalAlignment = HorizontalAlignment.Center,

8
Perspex.Layout/LayoutManager.cs

@ -207,14 +207,14 @@ namespace Perspex.Layout
{
if (!item.Control.IsArrangeValid)
{
var parent = item.Control.GetVisualParent<ILayoutable>();
var control = item.Control;
while (parent.PreviousArrange == null)
while (control.PreviousArrange == null)
{
parent = parent.GetVisualParent<ILayoutable>();
control = control.GetVisualParent<ILayoutable>();
}
parent.Arrange(parent.PreviousArrange.Value, true);
control.Arrange(control.PreviousArrange.Value, true);
}
}
}

48
Perspex.Layout/Layoutable.cs

@ -222,29 +222,44 @@ namespace Perspex.Layout
public void InvalidateMeasure()
{
var root = this.GetLayoutRoot();
if (this.IsMeasureValid)
{
var parent = this.GetVisualParent<ILayoutable>();
this.IsMeasureValid = false;
this.IsArrangeValid = false;
this.previousMeasure = null;
this.previousArrange = null;
this.IsMeasureValid = false;
this.IsArrangeValid = false;
this.previousMeasure = null;
this.previousArrange = null;
if (root != null && root.Item1.LayoutManager != null)
{
root.Item1.LayoutManager.InvalidateMeasure(this, root.Item2);
if (parent != null && IsResizable(parent))
{
parent.InvalidateMeasure();
}
else
{
var root = this.GetLayoutRoot();
if (root != null && root.Item1.LayoutManager != null)
{
root.Item1.LayoutManager.InvalidateMeasure(this, root.Item2);
}
}
}
}
public void InvalidateArrange()
{
var root = this.GetLayoutRoot();
if (this.IsArrangeValid)
{
var root = this.GetLayoutRoot();
this.IsArrangeValid = false;
this.previousArrange = null;
this.IsArrangeValid = false;
this.previousArrange = null;
if (root != null && root.Item1.LayoutManager != null)
{
root.Item1.LayoutManager.InvalidateArrange(this, root.Item2);
if (root != null && root.Item1.LayoutManager != null)
{
root.Item1.LayoutManager.InvalidateArrange(this, root.Item2);
}
}
}
@ -407,5 +422,10 @@ namespace Perspex.Layout
return control != null ? Tuple.Create((ILayoutRoot)control, distance) : null;
}
private static bool IsResizable(ILayoutable control)
{
return double.IsNaN(control.Width) || double.IsNaN(control.Height);
}
}
}

Loading…
Cancel
Save