From 0a0e35646f6726b8d959f7dba9312eec4fc0c497 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 24 Jul 2015 19:05:10 +0200 Subject: [PATCH] Documented Border. Ported from ideas branch so some other changes came across too. --- Perspex.Controls/Border.cs | 103 ++++++++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 31 deletions(-) diff --git a/Perspex.Controls/Border.cs b/Perspex.Controls/Border.cs index c46017b111..e355228efb 100644 --- a/Perspex.Controls/Border.cs +++ b/Perspex.Controls/Border.cs @@ -1,67 +1,98 @@ // ----------------------------------------------------------------------- // -// Copyright 2014 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.Reactive.Linq; - using Perspex.Layout; using Perspex.Media; + /// + /// A control which decorates a child with a border and background. + /// public class Border : Decorator { + /// + /// Defines the property. + /// public static readonly PerspexProperty BackgroundProperty = - PerspexProperty.Register("Background"); + PerspexProperty.Register(nameof(Background)); + /// + /// Defines the property. + /// public static readonly PerspexProperty BorderBrushProperty = - PerspexProperty.Register("BorderBrush"); + PerspexProperty.Register(nameof(BorderBrush)); + /// + /// Defines the property. + /// public static readonly PerspexProperty BorderThicknessProperty = - PerspexProperty.Register("BorderThickness"); + PerspexProperty.Register(nameof(BorderThickness)); + /// + /// Defines the property. + /// public static readonly PerspexProperty CornerRadiusProperty = - PerspexProperty.Register("CornerRadius"); + PerspexProperty.Register(nameof(CornerRadius)); + /// + /// Initializes static members of the class. + /// static Border() { Control.AffectsRender(Border.BackgroundProperty); Control.AffectsRender(Border.BorderBrushProperty); } + /// + /// Gets or sets a brush with which to paint the background. + /// public Brush Background { get { return this.GetValue(BackgroundProperty); } set { this.SetValue(BackgroundProperty, value); } } + /// + /// Gets or sets a brush with which to paint the border. + /// public Brush BorderBrush { get { return this.GetValue(BorderBrushProperty); } set { this.SetValue(BorderBrushProperty, value); } } + /// + /// Gets or sets the thickness of the border. + /// public double BorderThickness { get { return this.GetValue(BorderThicknessProperty); } set { this.SetValue(BorderThicknessProperty, value); } } + /// + /// Gets or sets the radius of the border rounded corners. + /// public float CornerRadius { get { return this.GetValue(CornerRadiusProperty); } set { this.SetValue(CornerRadiusProperty, value); } } + /// + /// Renders the control. + /// + /// The drawing context. public override void Render(IDrawingContext context) { - Brush background = this.Background; - Brush borderBrush = this.BorderBrush; - double borderThickness = this.BorderThickness; - float cornerRadius = this.CornerRadius; - Rect rect = new Rect(this.Bounds.Size).Deflate(this.BorderThickness); + var background = this.Background; + var borderBrush = this.BorderBrush; + var borderThickness = this.BorderThickness; + var cornerRadius = this.CornerRadius; + var rect = new Rect(this.Bounds.Size).Deflate(this.BorderThickness); if (background != null) { @@ -74,33 +105,43 @@ namespace Perspex.Controls } } - protected override Size ArrangeOverride(Size finalSize) - { - Control content = this.Child; - - if (content != null) - { - Thickness padding = this.Padding + new Thickness(this.BorderThickness); - content.Arrange(new Rect(finalSize).Deflate(padding)); - } - - return finalSize; - } - + /// + /// Measures the control. + /// + /// The available size. + /// The desired size of the control. protected override Size MeasureOverride(Size availableSize) { - var content = this.Child; + var child = this.Child; var padding = this.Padding + new Thickness(this.BorderThickness); - if (content != null) + if (child != null) { - content.Measure(availableSize.Deflate(padding)); - return content.DesiredSize.Inflate(padding); + child.Measure(availableSize.Deflate(padding)); + return child.DesiredSize.Inflate(padding); } else { return new Size(padding.Left + padding.Right, padding.Bottom + padding.Top); } } + + /// + /// Arranges the control's child. + /// + /// The size allocated to the control. + /// The space taken. + protected override Size ArrangeOverride(Size finalSize) + { + var child = this.Child; + + if (child != null) + { + var padding = this.Padding + new Thickness(this.BorderThickness); + child.Arrange(new Rect(finalSize).Deflate(padding)); + } + + return finalSize; + } } -} +} \ No newline at end of file