From 4e443c87bd84241dd9e7905e1daa3a3b8bcb6c07 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 24 Jul 2015 19:28:17 +0200 Subject: [PATCH] More porting docs etc from ideas branch. --- Perspex.Controls/DefinitionBase.cs | 15 ++++-- Perspex.Controls/ISelectable.cs | 18 ++++++- Perspex.Controls/Image.cs | 52 ++++++++++++++----- Perspex.Controls/Primitives/AccessText.cs | 4 +- .../Primitives/HeaderedContentControl.cs | 11 +++- .../Primitives/SelectingItemsControl.cs | 4 +- Perspex.Controls/TextBlock.cs | 42 +++++++++++---- Perspex.Controls/TextWrapping.cs | 14 ++++- 8 files changed, 123 insertions(+), 37 deletions(-) diff --git a/Perspex.Controls/DefinitionBase.cs b/Perspex.Controls/DefinitionBase.cs index f36cab0052..aca0b55859 100644 --- a/Perspex.Controls/DefinitionBase.cs +++ b/Perspex.Controls/DefinitionBase.cs @@ -1,20 +1,29 @@ // ----------------------------------------------------------------------- // -// Copyright 2013 MIT Licence. See licence.md for more information. +// Copyright 2015 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Controls { + /// + /// Base class for and . + /// public class DefinitionBase : PerspexObject { + /// + /// Defines the property. + /// public static readonly PerspexProperty SharedSizeGroupProperty = - PerspexProperty.Register("SharedSizeGroup", inherits: true); + PerspexProperty.Register(nameof(SharedSizeGroup), inherits: true); + /// + /// Gets or sets the name of the shared size group of the column or row. + /// public string SharedSizeGroup { get { return this.GetValue(SharedSizeGroupProperty); } set { this.SetValue(SharedSizeGroupProperty, value); } } } -} +} \ No newline at end of file diff --git a/Perspex.Controls/ISelectable.cs b/Perspex.Controls/ISelectable.cs index dae37394fa..405e1161b1 100644 --- a/Perspex.Controls/ISelectable.cs +++ b/Perspex.Controls/ISelectable.cs @@ -1,13 +1,27 @@ // ----------------------------------------------------------------------- // -// Copyright 2014 MIT Licence. See licence.md for more information. +// Copyright 2015 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Controls { + using Perspex.Controls.Primitives; + + /// + /// Interface for objects that are selectable. + /// + /// + /// Controls such as use this interface to indicate the selected + /// control in a list. If changing the control's property should + /// update the selection in a or equivalent, then the + /// control should raise the . + /// public interface ISelectable { + /// + /// Gets or sets the selected state of the object. + /// bool IsSelected { get; set; } } -} +} \ No newline at end of file diff --git a/Perspex.Controls/Image.cs b/Perspex.Controls/Image.cs index 3e3ef957b2..698d4dc206 100644 --- a/Perspex.Controls/Image.cs +++ b/Perspex.Controls/Image.cs @@ -1,6 +1,6 @@ // ----------------------------------------------------------------------- // -// Copyright 2013 MIT Licence. See licence.md for more information. +// Copyright 2015 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- @@ -10,27 +10,46 @@ namespace Perspex.Controls using Perspex.Media; using Perspex.Media.Imaging; + /// + /// Displays a image. + /// public class Image : Control { + /// + /// Defines the property. + /// public static readonly PerspexProperty SourceProperty = - PerspexProperty.Register("Source"); + PerspexProperty.Register(nameof(Source)); + /// + /// Defines the property. + /// public static readonly PerspexProperty StretchProperty = - PerspexProperty.Register("Stretch", Stretch.Uniform); + PerspexProperty.Register(nameof(Stretch), Stretch.Uniform); + /// + /// Gets or sets the bitmap image that will be displayed. + /// public Bitmap Source { get { return this.GetValue(SourceProperty); } set { this.SetValue(SourceProperty, value); } } - public Stretch Stretch - { + /// + /// Gets or sets a value controlling how the image will be stretched. + /// + public Stretch Stretch + { get { return (Stretch)this.GetValue(StretchProperty); } set { this.SetValue(StretchProperty, value); } } - public override void Render(IDrawingContext drawingContext) + /// + /// Renders the control. + /// + /// The drawing context. + public override void Render(IDrawingContext context) { Bitmap source = this.Source; @@ -46,10 +65,15 @@ namespace Perspex.Controls Rect sourceRect = new Rect(sourceSize) .CenterIn(new Rect(destRect.Size / scale)); - drawingContext.DrawImage(source, 1, sourceRect, destRect); + context.DrawImage(source, 1, sourceRect, destRect); } } + /// + /// Measures the control. + /// + /// The available size. + /// The desired size of the control. protected override Size MeasureOverride(Size availableSize) { double width = 0; @@ -77,11 +101,13 @@ namespace Perspex.Controls return new Size(width * scale.X, height * scale.Y); } - protected override Size ArrangeOverride(Size finalSize) - { - return finalSize; - } - + /// + /// Calculates the scaling for the image. + /// + /// The size available to display the image. + /// The pxiel size of the image. + /// The stretch mode of the control. + /// A vector with the X and Y scaling factors. private static Vector CalculateScaling(Size availableSize, Size imageSize, Stretch stretch) { double scaleX = 1; @@ -106,4 +132,4 @@ namespace Perspex.Controls return new Vector(scaleX, scaleY); } } -} +} \ No newline at end of file diff --git a/Perspex.Controls/Primitives/AccessText.cs b/Perspex.Controls/Primitives/AccessText.cs index 6bcf6f6714..a6b8c60167 100644 --- a/Perspex.Controls/Primitives/AccessText.cs +++ b/Perspex.Controls/Primitives/AccessText.cs @@ -7,12 +7,10 @@ namespace Perspex.Controls.Primitives { using System; - using Perspex.Media; using Perspex.Input; + using Perspex.Media; using Perspex.Rendering; - - /// /// A text block that displays a character prefixed with an underscore as an access key. /// diff --git a/Perspex.Controls/Primitives/HeaderedContentControl.cs b/Perspex.Controls/Primitives/HeaderedContentControl.cs index bfd9478706..f42ea56bb4 100644 --- a/Perspex.Controls/Primitives/HeaderedContentControl.cs +++ b/Perspex.Controls/Primitives/HeaderedContentControl.cs @@ -6,15 +6,24 @@ namespace Perspex.Controls.Primitives { + /// + /// A with a header. + /// public class HeaderedContentControl : ContentControl, IHeadered { + /// + /// Defines the property. + /// public static readonly PerspexProperty HeaderProperty = PerspexProperty.Register("Header"); + /// + /// Gets or sets the header content. + /// public object Header { get { return this.GetValue(HeaderProperty); } set { this.SetValue(HeaderProperty, value); } } } -} +} \ No newline at end of file diff --git a/Perspex.Controls/Primitives/SelectingItemsControl.cs b/Perspex.Controls/Primitives/SelectingItemsControl.cs index 5c1d18f8b3..99bfce60e7 100644 --- a/Perspex.Controls/Primitives/SelectingItemsControl.cs +++ b/Perspex.Controls/Primitives/SelectingItemsControl.cs @@ -7,13 +7,13 @@ namespace Perspex.Controls.Primitives { using System; - using System.Linq; using System.Collections; using System.Collections.Specialized; + using System.Linq; using Perspex.Controls.Utils; using Perspex.Input; - using Perspex.VisualTree; using Perspex.Interactivity; + using Perspex.VisualTree; /// /// An that maintains a selection. diff --git a/Perspex.Controls/TextBlock.cs b/Perspex.Controls/TextBlock.cs index 911ed1727e..1700ae990a 100644 --- a/Perspex.Controls/TextBlock.cs +++ b/Perspex.Controls/TextBlock.cs @@ -1,6 +1,6 @@ // ----------------------------------------------------------------------- // -// Copyright 2014 MIT Licence. See licence.md for more information. +// Copyright 2015 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- @@ -26,49 +26,61 @@ namespace Perspex.Controls /// Defines the property. /// public static readonly PerspexProperty FontFamilyProperty = - PerspexProperty.RegisterAttached("FontFamily", inherits: true); + PerspexProperty.RegisterAttached( + nameof(FontFamily), + inherits: true); /// /// Defines the property. /// public static readonly PerspexProperty FontSizeProperty = - PerspexProperty.RegisterAttached("FontSize", inherits: true); + PerspexProperty.RegisterAttached( + nameof(FontSize), + inherits: true); /// /// Defines the property. /// public static readonly PerspexProperty FontStyleProperty = - PerspexProperty.RegisterAttached("FontStyle", inherits: true); + PerspexProperty.RegisterAttached( + nameof(FontStyle), + inherits: true); /// /// Defines the property. /// public static readonly PerspexProperty FontWeightProperty = - PerspexProperty.RegisterAttached("FontWeight", inherits: true, defaultValue: FontWeight.Normal); + PerspexProperty.RegisterAttached( + nameof(FontWeight), + inherits: true, + defaultValue: FontWeight.Normal); /// /// Defines the property. /// public static readonly PerspexProperty ForegroundProperty = - PerspexProperty.RegisterAttached("Foreground", new SolidColorBrush(0xff000000), inherits: true); + PerspexProperty.RegisterAttached( + nameof(Foreground), + new SolidColorBrush(0xff000000), + inherits: true); /// /// Defines the property. /// public static readonly PerspexProperty TextProperty = - PerspexProperty.Register("Text"); + PerspexProperty.Register(nameof(Text)); /// /// Defines the property. /// public static readonly PerspexProperty TextAlignmentProperty = - PerspexProperty.Register("TextAlignment"); + PerspexProperty.Register(nameof(TextAlignment)); /// /// Defines the property. /// public static readonly PerspexProperty TextWrappingProperty = - PerspexProperty.Register("TextWrapping"); + PerspexProperty.Register(nameof(TextWrapping)); /// /// The formatted text used for rendering. @@ -80,6 +92,14 @@ namespace Perspex.Controls /// private Size constraint; + /// + /// Initializes static members of the class. + /// + static TextBlock() + { + AffectsRender(ForegroundProperty); + } + /// /// Initializes a new instance of the class. /// @@ -207,7 +227,7 @@ namespace Perspex.Controls } this.FormattedText.Constraint = this.Bounds.Size; - context.DrawText(this.Foreground, new Point(), this.FormattedText); + context.DrawText(this.Foreground, new Point(), this.FormattedText); } /// @@ -267,4 +287,4 @@ namespace Perspex.Controls return new Size(); } } -} +} \ No newline at end of file diff --git a/Perspex.Controls/TextWrapping.cs b/Perspex.Controls/TextWrapping.cs index f23281d047..4fcacfc8ad 100644 --- a/Perspex.Controls/TextWrapping.cs +++ b/Perspex.Controls/TextWrapping.cs @@ -1,14 +1,24 @@ // ----------------------------------------------------------------------- // -// Copyright 2014 MIT Licence. See licence.md for more information. +// Copyright 2015 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Controls { + /// + /// Controls the wrapping mode in a . + /// public enum TextWrapping { + /// + /// Text should not wrap. + /// NoWrap, + + /// + /// Text can wrap. + /// Wrap } -} +} \ No newline at end of file