From 6f2b9cd5ecb9ed6210379a7a6b3505df5d242c09 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 5 May 2015 12:53:47 +0200 Subject: [PATCH] Added UseLayoutRounding. --- Perspex.Layout/Layoutable.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Perspex.Layout/Layoutable.cs b/Perspex.Layout/Layoutable.cs index e1974018a7..838aa73577 100644 --- a/Perspex.Layout/Layoutable.cs +++ b/Perspex.Layout/Layoutable.cs @@ -56,6 +56,9 @@ namespace Perspex.Layout public static readonly PerspexProperty VerticalAlignmentProperty = PerspexProperty.Register("VerticalAlignment"); + public static readonly PerspexProperty UseLayoutRoundingProperty = + PerspexProperty.Register("UseLayoutRounding", defaultValue: true, inherits: true); + private Size? previousMeasure; private Rect? previousArrange; @@ -146,6 +149,12 @@ namespace Perspex.Layout private set; } + public bool UseLayoutRounding + { + get { return this.GetValue(UseLayoutRoundingProperty); } + set { this.SetValue(UseLayoutRoundingProperty, value); } + } + Size? ILayoutable.PreviousMeasure { get { return this.previousMeasure; } @@ -307,6 +316,12 @@ namespace Perspex.Layout } size = LayoutHelper.ApplyLayoutConstraints(this, size); + + if (this.UseLayoutRounding) + { + size = new Size(Math.Ceiling(size.Width), Math.Ceiling(size.Height)); + } + size = this.ArrangeOverride(size).Constrain(size); switch (this.HorizontalAlignment) @@ -329,6 +344,13 @@ namespace Perspex.Layout break; } + if (this.UseLayoutRounding) + { + originX = Math.Floor(originX); + originY = Math.Floor(originY); + size = this.ArrangeOverride(size).Constrain(size); + } + this.Bounds = new Rect(originX, originY, size.Width, size.Height); } }