Browse Source

Fix layout calculations w/margins.

pull/39/head
Steven Kirk 12 years ago
parent
commit
350b2444e2
  1. 1
      Perspex.Controls/Presenters/ContentPresenter.cs
  2. 11
      Perspex.Layout/Layoutable.cs

1
Perspex.Controls/Presenters/ContentPresenter.cs

@ -11,6 +11,7 @@ namespace Perspex.Controls.Presenters
using System.Reactive.Linq;
using System.Reactive.Subjects;
using Perspex.Controls.Primitives;
using Perspex.Media;
public class ContentPresenter : Control, IVisual
{

11
Perspex.Layout/Layoutable.cs

@ -270,9 +270,10 @@ namespace Perspex.Layout
{
double originX = finalRect.X + this.Margin.Left;
double originY = finalRect.Y + this.Margin.Top;
var size = new Size(
var sizeMinusMargins = new Size(
Math.Max(0, finalRect.Width - this.Margin.Left - this.Margin.Right),
Math.Max(0, finalRect.Height - this.Margin.Top - this.Margin.Bottom));
var size = sizeMinusMargins;
if (this.HorizontalAlignment != HorizontalAlignment.Stretch)
{
@ -290,20 +291,20 @@ namespace Perspex.Layout
switch (this.HorizontalAlignment)
{
case HorizontalAlignment.Center:
originX += (finalRect.Width - size.Width) / 2;
originX += (sizeMinusMargins.Width - size.Width) / 2;
break;
case HorizontalAlignment.Right:
originX += finalRect.Width - size.Width;
originX += sizeMinusMargins.Width - size.Width;
break;
}
switch (this.VerticalAlignment)
{
case VerticalAlignment.Center:
originY += (finalRect.Height - size.Height) / 2;
originY += (sizeMinusMargins.Height - size.Height) / 2;
break;
case VerticalAlignment.Bottom:
originY += finalRect.Height - size.Height;
originY += sizeMinusMargins.Height - size.Height;
break;
}

Loading…
Cancel
Save