Browse Source

Added StackPanel.Gap property.

pull/4/head
Steven Kirk 12 years ago
parent
commit
1d753d04b3
  1. 23
      Perspex/Controls/StackPanel.cs
  2. 1
      TestApplication/Program.cs

23
Perspex/Controls/StackPanel.cs

@ -20,9 +20,18 @@ namespace Perspex.Controls
public class StackPanel : Panel public class StackPanel : Panel
{ {
public static readonly PerspexProperty<double> GapProperty =
PerspexProperty.Register<StackPanel, double>("Gap");
public static readonly PerspexProperty<Orientation> OrientationProperty = public static readonly PerspexProperty<Orientation> OrientationProperty =
PerspexProperty.Register<StackPanel, Orientation>("Orientation"); PerspexProperty.Register<StackPanel, Orientation>("Orientation");
public double Gap
{
get { return this.GetValue(GapProperty); }
set { this.SetValue(GapProperty, value); }
}
public Orientation Orientation public Orientation Orientation
{ {
get { return this.GetValue(OrientationProperty); } get { return this.GetValue(OrientationProperty); }
@ -61,6 +70,7 @@ namespace Perspex.Controls
double measuredWidth = 0; double measuredWidth = 0;
double measuredHeight = 0; double measuredHeight = 0;
double gap = this.Gap;
foreach (Control child in this.Children) foreach (Control child in this.Children)
{ {
@ -69,12 +79,12 @@ namespace Perspex.Controls
if (Orientation == Orientation.Vertical) if (Orientation == Orientation.Vertical)
{ {
measuredHeight += size.Height; measuredHeight += size.Height + gap;
measuredWidth = Math.Max(measuredWidth, size.Width); measuredWidth = Math.Max(measuredWidth, size.Width);
} }
else else
{ {
measuredWidth += size.Width; measuredWidth += size.Width + gap;
measuredHeight = Math.Max(measuredHeight, size.Height); measuredHeight = Math.Max(measuredHeight, size.Height);
} }
} }
@ -86,6 +96,7 @@ namespace Perspex.Controls
{ {
double arrangedWidth = finalSize.Width; double arrangedWidth = finalSize.Width;
double arrangedHeight = finalSize.Height; double arrangedHeight = finalSize.Height;
double gap = this.Gap;
if (Orientation == Orientation.Vertical) if (Orientation == Orientation.Vertical)
{ {
@ -117,7 +128,7 @@ namespace Perspex.Controls
} }
arrangedWidth = Math.Max(arrangedWidth, childWidth); arrangedWidth = Math.Max(arrangedWidth, childWidth);
arrangedHeight += childHeight; arrangedHeight += childHeight + gap;
} }
else else
{ {
@ -134,18 +145,18 @@ namespace Perspex.Controls
child.Arrange(childFinal); child.Arrange(childFinal);
} }
arrangedWidth += childWidth; arrangedWidth += childWidth + gap;
arrangedHeight = Math.Max(arrangedHeight, childHeight); arrangedHeight = Math.Max(arrangedHeight, childHeight);
} }
} }
if (Orientation == Orientation.Vertical) if (Orientation == Orientation.Vertical)
{ {
arrangedHeight = Math.Max(arrangedHeight, finalSize.Height); arrangedHeight = Math.Max(arrangedHeight - gap, finalSize.Height);
} }
else else
{ {
arrangedWidth = Math.Max(arrangedWidth, finalSize.Width); arrangedWidth = Math.Max(arrangedWidth - gap, finalSize.Width);
} }
return new Size(arrangedWidth, arrangedHeight); return new Size(arrangedWidth, arrangedHeight);

1
TestApplication/Program.cs

@ -57,6 +57,7 @@ namespace TestApplication
HorizontalAlignment = HorizontalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center, VerticalAlignment = VerticalAlignment.Center,
Orientation = Orientation.Vertical, Orientation = Orientation.Vertical,
Gap = 6,
Children = new PerspexList<Control> Children = new PerspexList<Control>
{ {
new Button new Button

Loading…
Cancel
Save