Browse Source

Make stuff get measured properly.

And added some logging to Layoutable to help diagnose this.
pull/4/head
Steven Kirk 12 years ago
parent
commit
6205545bc5
  1. 40
      Perspex.Controls/Panel.cs
  2. 15
      Perspex.Layout/Layoutable.cs
  3. 12
      Perspex.SceneGraph/Visual.cs
  4. 15
      Perspex.Windows/Window.cs

40
Perspex.Controls/Panel.cs

@ -7,7 +7,7 @@
namespace Perspex.Controls
{
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
/// <summary>
@ -24,22 +24,56 @@ namespace Perspex.Controls
if (this.children == null)
{
this.children = new Controls();
this.children.CollectionChanged += ChildrenChanged;
}
return this.children;
}
set
{
Contract.Requires<ArgumentNullException>(value != null);
if (this.children != value)
{
if (this.children != null)
{
this.children.CollectionChanged -= ChildrenChanged;
}
this.children = value;
this.ClearVisualChildren();
this.AddVisualChildren(value);
if (this.children != null)
{
this.children.CollectionChanged += ChildrenChanged;
this.AddVisualChildren(value);
this.InvalidateMeasure();
}
}
}
}
private void ChildrenChanged(object sender, NotifyCollectionChangedEventArgs e)
{
// TODO: Handle Move and Replace.
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
this.AddVisualChildren(e.NewItems.OfType<Visual>());
break;
case NotifyCollectionChangedAction.Remove:
this.RemoveVisualChildren(e.OldItems.OfType<Visual>());
break;
case NotifyCollectionChangedAction.Reset:
this.ClearVisualChildren();
this.AddVisualChildren(this.children);
break;
}
this.InvalidateMeasure();
}
}
}

15
Perspex.Layout/Layoutable.cs

@ -8,6 +8,7 @@ namespace Perspex.Layout
{
using System;
using System.Linq;
using Splat;
public enum HorizontalAlignment
{
@ -25,7 +26,7 @@ namespace Perspex.Layout
Bottom,
}
public class Layoutable : Visual, ILayoutable
public class Layoutable : Visual, ILayoutable, IEnableLogger
{
public static readonly PerspexProperty<double> WidthProperty =
PerspexProperty.Register<Layoutable, double>("Width", double.NaN);
@ -123,10 +124,22 @@ namespace Perspex.Layout
{
availableSize = availableSize.Deflate(this.Margin);
this.DesiredSize = this.MeasureCore(availableSize).Constrain(availableSize);
this.Log().Debug(string.Format(
"Measure of {0} (#{1:x8}) requested {2} ",
this.GetType().Name,
this.GetHashCode(),
this.DesiredSize));
}
public void Arrange(Rect rect)
{
this.Log().Debug(string.Format(
"Arrange of {0} (#{1:x8}) gave {2} ",
this.GetType().Name,
this.GetHashCode(),
rect));
if (this.DesiredSize.HasValue)
{
this.ArrangeCore(rect);

12
Perspex.SceneGraph/Visual.cs

@ -143,6 +143,18 @@ namespace Perspex
this.visualChildren.Remove(visual);
}
protected void RemoveVisualChildren(IEnumerable<Visual> visuals)
{
Contract.Requires<ArgumentNullException>(visuals != null);
this.EnsureVisualChildrenCreated();
foreach (var v in visuals)
{
this.visualChildren.Remove(v);
}
}
protected void SetVisualBounds(Rect bounds)
{
this.bounds = bounds;

15
Perspex.Windows/Window.cs

@ -33,8 +33,6 @@ namespace Perspex.Windows
private IInputManager inputManager;
private bool layoutPending;
public Window()
{
IPlatformRenderInterface factory = Locator.Current.GetService<IPlatformRenderInterface>();
@ -47,9 +45,8 @@ namespace Perspex.Windows
this.inputManager = Locator.Current.GetService<IInputManager>();
this.Template = ControlTemplate.Create<Window>(this.DefaultTemplate);
this.LayoutManager.LayoutNeeded.Where(_ => !this.layoutPending).Subscribe(x =>
this.LayoutManager.LayoutNeeded.Subscribe(x =>
{
this.layoutPending = true;
WindowsDispatcher.CurrentDispatcher.BeginInvoke(
DispatcherPriority.Render,
() =>
@ -57,22 +54,18 @@ namespace Perspex.Windows
this.LayoutManager.ExecuteLayoutPass();
this.renderer.Render(this);
this.RenderManager.RenderFinished();
this.layoutPending = false;
});
});
this.RenderManager.RenderNeeded.Where(_ => !layoutPending)
this.RenderManager.RenderNeeded
.Subscribe(x =>
{
WindowsDispatcher.CurrentDispatcher.BeginInvoke(
DispatcherPriority.Render,
() =>
{
if (!this.layoutPending)
{
this.renderer.Render(this);
this.RenderManager.RenderFinished();
}
this.renderer.Render(this);
this.RenderManager.RenderFinished();
});
});
}

Loading…
Cancel
Save