From 350b2444e22a4c77c331f9bfbfe4259139b7f2d6 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 30 Dec 2014 18:07:05 +0000 Subject: [PATCH] Fix layout calculations w/margins. --- Perspex.Controls/Presenters/ContentPresenter.cs | 1 + Perspex.Layout/Layoutable.cs | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Perspex.Controls/Presenters/ContentPresenter.cs b/Perspex.Controls/Presenters/ContentPresenter.cs index c0340567c3..4646a05f67 100644 --- a/Perspex.Controls/Presenters/ContentPresenter.cs +++ b/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 { diff --git a/Perspex.Layout/Layoutable.cs b/Perspex.Layout/Layoutable.cs index f41b07b618..e435068f74 100644 --- a/Perspex.Layout/Layoutable.cs +++ b/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; }