Browse Source

Fixed layout bug.

pull/4/head
Steven Kirk 12 years ago
parent
commit
f0e41bd681
  1. 8
      Perspex/Controls/TextBoxView.cs
  2. 13
      Perspex/Layout/LayoutHelper.cs
  3. 13
      Perspex/Layout/Layoutable.cs

8
Perspex/Controls/TextBoxView.cs

@ -8,6 +8,7 @@ namespace Perspex.Controls
{ {
using System; using System;
using System.Globalization; using System.Globalization;
using Perspex.Layout;
using Perspex.Media; using Perspex.Media;
using Perspex.Platform; using Perspex.Platform;
using Perspex.Threading; using Perspex.Threading;
@ -98,7 +99,12 @@ namespace Perspex.Controls
protected override Size MeasureOverride(Size constraint) 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() private FormattedText CreateFormattedText()

13
Perspex/Layout/LayoutHelper.cs

@ -15,6 +15,17 @@ namespace Perspex.Layout
public static class LayoutHelper 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( public static Size MeasureDecorator(
Control decorator, Control decorator,
Control content, Control content,
@ -26,7 +37,7 @@ namespace Perspex.Layout
if (content != null) if (content != null)
{ {
content.Measure(availableSize); content.Measure(availableSize.Deflate(padding));
Size s = content.DesiredSize.Value.Inflate(padding); Size s = content.DesiredSize.Value.Inflate(padding);
width = s.Width; width = s.Width;
height = s.Height; height = s.Height;

13
Perspex/Layout/Layoutable.cs

@ -217,16 +217,11 @@ namespace Perspex.Layout
{ {
if (this.IsVisible) if (this.IsVisible)
{ {
Size measuredSize = this.MeasureOverride(availableSize.Deflate(this.Margin)).Inflate(this.Margin); availableSize = LayoutHelper.ApplyLayoutConstraints(this, availableSize)
double width = (this.Width > 0) ? this.Width : measuredSize.Width; .Deflate(this.Margin);
double height = (this.Height > 0) ? this.Height : measuredSize.Height; var measured = this.MeasureOverride(availableSize);
width = Math.Min(width, this.MaxWidth); return measured.Inflate(this.Margin);
width = Math.Max(width, this.MinWidth);
height = Math.Min(height, this.MaxHeight);
height = Math.Max(height, this.MinHeight);
return new Size(width, height);
} }
else else
{ {

Loading…
Cancel
Save