From f0e41bd6815ce9337798a6e4b0ccd48f27ce90e2 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 13 Sep 2014 23:28:52 +0200 Subject: [PATCH] Fixed layout bug. --- Perspex/Controls/TextBoxView.cs | 8 +++++++- Perspex/Layout/LayoutHelper.cs | 13 ++++++++++++- Perspex/Layout/Layoutable.cs | 13 ++++--------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Perspex/Controls/TextBoxView.cs b/Perspex/Controls/TextBoxView.cs index d415e49748..9c452223e8 100644 --- a/Perspex/Controls/TextBoxView.cs +++ b/Perspex/Controls/TextBoxView.cs @@ -8,6 +8,7 @@ namespace Perspex.Controls { using System; using System.Globalization; + using Perspex.Layout; using Perspex.Media; using Perspex.Platform; using Perspex.Threading; @@ -98,7 +99,12 @@ namespace Perspex.Controls protected override Size MeasureOverride(Size constraint) { - return this.FormattedText.Measure(constraint); + if (!string.IsNullOrEmpty(this.parent.Text)) + { + return this.FormattedText.Measure(constraint); + } + + return new Size(); } private FormattedText CreateFormattedText() diff --git a/Perspex/Layout/LayoutHelper.cs b/Perspex/Layout/LayoutHelper.cs index 2060f99fbb..cd6f1c1e35 100644 --- a/Perspex/Layout/LayoutHelper.cs +++ b/Perspex/Layout/LayoutHelper.cs @@ -15,6 +15,17 @@ namespace Perspex.Layout public static class LayoutHelper { + public static Size ApplyLayoutConstraints(Layoutable control, Size constraints) + { + double width = (control.Width > 0) ? control.Width : constraints.Width; + double height = (control.Height > 0) ? control.Height : constraints.Height; + width = Math.Min(width, control.MaxWidth); + width = Math.Max(width, control.MinWidth); + height = Math.Min(height, control.MaxHeight); + height = Math.Max(height, control.MinHeight); + return new Size(width, height); + } + public static Size MeasureDecorator( Control decorator, Control content, @@ -26,7 +37,7 @@ namespace Perspex.Layout if (content != null) { - content.Measure(availableSize); + content.Measure(availableSize.Deflate(padding)); Size s = content.DesiredSize.Value.Inflate(padding); width = s.Width; height = s.Height; diff --git a/Perspex/Layout/Layoutable.cs b/Perspex/Layout/Layoutable.cs index 9d2a0a86e5..16642b0fe8 100644 --- a/Perspex/Layout/Layoutable.cs +++ b/Perspex/Layout/Layoutable.cs @@ -217,16 +217,11 @@ namespace Perspex.Layout { if (this.IsVisible) { - Size measuredSize = this.MeasureOverride(availableSize.Deflate(this.Margin)).Inflate(this.Margin); - double width = (this.Width > 0) ? this.Width : measuredSize.Width; - double height = (this.Height > 0) ? this.Height : measuredSize.Height; + availableSize = LayoutHelper.ApplyLayoutConstraints(this, availableSize) + .Deflate(this.Margin); + var measured = this.MeasureOverride(availableSize); - width = Math.Min(width, this.MaxWidth); - width = Math.Max(width, this.MinWidth); - height = Math.Min(height, this.MaxHeight); - height = Math.Max(height, this.MinHeight); - - return new Size(width, height); + return measured.Inflate(this.Margin); } else {