diff --git a/Perspex.Controls/StackPanel.cs b/Perspex.Controls/StackPanel.cs index 5e1435af7f..123ed22b79 100644 --- a/Perspex.Controls/StackPanel.cs +++ b/Perspex.Controls/StackPanel.cs @@ -1,41 +1,80 @@ // ----------------------------------------------------------------------- // -// Copyright 2013 MIT Licence. See licence.md for more information. +// Copyright 2015 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Controls { using System; - using System.Linq; using Perspex.Input; + /// + /// Defines vertical or horizontal orientation. + /// public enum Orientation { + /// + /// Vertical orientation. + /// Vertical, + + /// + /// Horizontal orientation. + /// Horizontal, } + /// + /// A panel which lays out its children horizontally or vertically. + /// public class StackPanel : Panel, INavigablePanel { + /// + /// Defines the property. + /// public static readonly PerspexProperty GapProperty = - PerspexProperty.Register("Gap"); + PerspexProperty.Register(nameof(Gap)); + /// + /// Defines the property. + /// public static readonly PerspexProperty OrientationProperty = - PerspexProperty.Register("Orientation"); + PerspexProperty.Register(nameof(Orientation)); + + /// + /// Initializes static members of the class. + /// + static StackPanel() + { + AffectsMeasure(GapProperty); + AffectsMeasure(OrientationProperty); + } + /// + /// Gets or sets the size of the gap to place between child controls. + /// public double Gap { get { return this.GetValue(GapProperty); } set { this.SetValue(GapProperty, value); } } + /// + /// Gets or sets the orientation in which child controls will be layed out. + /// public Orientation Orientation { get { return this.GetValue(OrientationProperty); } set { this.SetValue(OrientationProperty, value); } } + /// + /// Gets the next control in the specified direction. + /// + /// The movement direction. + /// The control from which movement begins. + /// The control. Control INavigablePanel.GetControl(FocusNavigationDirection direction, Control from) { var horiz = this.Orientation == Orientation.Horizontal; @@ -79,6 +118,11 @@ namespace Perspex.Controls } } + /// + /// Measures the control. + /// + /// The available size. + /// The desired size of the control. protected override Size MeasureOverride(Size availableSize) { double childAvailableWidth = double.PositiveInfinity; @@ -118,7 +162,7 @@ namespace Perspex.Controls child.Measure(new Size(childAvailableWidth, childAvailableHeight)); Size size = child.DesiredSize; - if (Orientation == Orientation.Vertical) + if (this.Orientation == Orientation.Vertical) { measuredHeight += size.Height + gap; measuredWidth = Math.Max(measuredWidth, size.Width); @@ -133,13 +177,18 @@ namespace Perspex.Controls return new Size(measuredWidth, measuredHeight); } + /// + /// Arranges the control's children. + /// + /// The size allocated to the control. + /// The space taken. protected override Size ArrangeOverride(Size finalSize) { double arrangedWidth = finalSize.Width; double arrangedHeight = finalSize.Height; double gap = this.Gap; - if (Orientation == Orientation.Vertical) + if (this.Orientation == Orientation.Vertical) { arrangedHeight = 0; } @@ -153,7 +202,7 @@ namespace Perspex.Controls double childWidth = child.DesiredSize.Width; double childHeight = child.DesiredSize.Height; - if (Orientation == Orientation.Vertical) + if (this.Orientation == Orientation.Vertical) { double width = Math.Max(childWidth, arrangedWidth); Rect childFinal = new Rect(0, arrangedHeight, width, childHeight); @@ -171,7 +220,7 @@ namespace Perspex.Controls } } - if (Orientation == Orientation.Vertical) + if (this.Orientation == Orientation.Vertical) { arrangedHeight = Math.Max(arrangedHeight - gap, finalSize.Height); } @@ -183,4 +232,4 @@ namespace Perspex.Controls return new Size(arrangedWidth, arrangedHeight); } } -} +} \ No newline at end of file