Browse Source

More porting docs etc from ideas branch.

pull/63/head
Steven Kirk 11 years ago
parent
commit
4e443c87bd
  1. 15
      Perspex.Controls/DefinitionBase.cs
  2. 18
      Perspex.Controls/ISelectable.cs
  3. 52
      Perspex.Controls/Image.cs
  4. 4
      Perspex.Controls/Primitives/AccessText.cs
  5. 11
      Perspex.Controls/Primitives/HeaderedContentControl.cs
  6. 4
      Perspex.Controls/Primitives/SelectingItemsControl.cs
  7. 42
      Perspex.Controls/TextBlock.cs
  8. 14
      Perspex.Controls/TextWrapping.cs

15
Perspex.Controls/DefinitionBase.cs

@ -1,20 +1,29 @@
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// <copyright file="DefinitionBase.cs" company="Steven Kirk"> // <copyright file="DefinitionBase.cs" company="Steven Kirk">
// Copyright 2013 MIT Licence. See licence.md for more information. // Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright> // </copyright>
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
namespace Perspex.Controls namespace Perspex.Controls
{ {
/// <summary>
/// Base class for <see cref="ColumnDefinition"/> and <see cref="RowDefinition"/>.
/// </summary>
public class DefinitionBase : PerspexObject public class DefinitionBase : PerspexObject
{ {
/// <summary>
/// Defines the <see cref="SharedSizeGroup"/> property.
/// </summary>
public static readonly PerspexProperty<string> SharedSizeGroupProperty = public static readonly PerspexProperty<string> SharedSizeGroupProperty =
PerspexProperty.Register<DefinitionBase, string>("SharedSizeGroup", inherits: true); PerspexProperty.Register<DefinitionBase, string>(nameof(SharedSizeGroup), inherits: true);
/// <summary>
/// Gets or sets the name of the shared size group of the column or row.
/// </summary>
public string SharedSizeGroup public string SharedSizeGroup
{ {
get { return this.GetValue(SharedSizeGroupProperty); } get { return this.GetValue(SharedSizeGroupProperty); }
set { this.SetValue(SharedSizeGroupProperty, value); } set { this.SetValue(SharedSizeGroupProperty, value); }
} }
} }
} }

18
Perspex.Controls/ISelectable.cs

@ -1,13 +1,27 @@
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// <copyright file="ISelectable.cs" company="Steven Kirk"> // <copyright file="ISelectable.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information. // Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright> // </copyright>
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
namespace Perspex.Controls namespace Perspex.Controls
{ {
using Perspex.Controls.Primitives;
/// <summary>
/// Interface for objects that are selectable.
/// </summary>
/// <remarks>
/// Controls such as <see cref="Selector"/> use this interface to indicate the selected
/// control in a list. If changing the control's <see cref="IsSelected"/> property should
/// update the selection in a <see cref="SelectingItemsControl"/> or equivalent, then the
/// control should raise the <see cref="SelectingItemsControl.IsSelectedChangedEvent"/>.
/// </remarks>
public interface ISelectable public interface ISelectable
{ {
/// <summary>
/// Gets or sets the selected state of the object.
/// </summary>
bool IsSelected { get; set; } bool IsSelected { get; set; }
} }
} }

52
Perspex.Controls/Image.cs

@ -1,6 +1,6 @@
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// <copyright file="Image.cs" company="Steven Kirk"> // <copyright file="Image.cs" company="Steven Kirk">
// Copyright 2013 MIT Licence. See licence.md for more information. // Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright> // </copyright>
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@ -10,27 +10,46 @@ namespace Perspex.Controls
using Perspex.Media; using Perspex.Media;
using Perspex.Media.Imaging; using Perspex.Media.Imaging;
/// <summary>
/// Displays a <see cref="Bitmap"/> image.
/// </summary>
public class Image : Control public class Image : Control
{ {
/// <summary>
/// Defines the <see cref="Source"/> property.
/// </summary>
public static readonly PerspexProperty<Bitmap> SourceProperty = public static readonly PerspexProperty<Bitmap> SourceProperty =
PerspexProperty.Register<Image, Bitmap>("Source"); PerspexProperty.Register<Image, Bitmap>(nameof(Source));
/// <summary>
/// Defines the <see cref="Stretch"/> property.
/// </summary>
public static readonly PerspexProperty<Stretch> StretchProperty = public static readonly PerspexProperty<Stretch> StretchProperty =
PerspexProperty.Register<Image, Stretch>("Stretch", Stretch.Uniform); PerspexProperty.Register<Image, Stretch>(nameof(Stretch), Stretch.Uniform);
/// <summary>
/// Gets or sets the bitmap image that will be displayed.
/// </summary>
public Bitmap Source public Bitmap Source
{ {
get { return this.GetValue(SourceProperty); } get { return this.GetValue(SourceProperty); }
set { this.SetValue(SourceProperty, value); } set { this.SetValue(SourceProperty, value); }
} }
public Stretch Stretch /// <summary>
{ /// Gets or sets a value controlling how the image will be stretched.
/// </summary>
public Stretch Stretch
{
get { return (Stretch)this.GetValue(StretchProperty); } get { return (Stretch)this.GetValue(StretchProperty); }
set { this.SetValue(StretchProperty, value); } set { this.SetValue(StretchProperty, value); }
} }
public override void Render(IDrawingContext drawingContext) /// <summary>
/// Renders the control.
/// </summary>
/// <param name="context">The drawing context.</param>
public override void Render(IDrawingContext context)
{ {
Bitmap source = this.Source; Bitmap source = this.Source;
@ -46,10 +65,15 @@ namespace Perspex.Controls
Rect sourceRect = new Rect(sourceSize) Rect sourceRect = new Rect(sourceSize)
.CenterIn(new Rect(destRect.Size / scale)); .CenterIn(new Rect(destRect.Size / scale));
drawingContext.DrawImage(source, 1, sourceRect, destRect); context.DrawImage(source, 1, sourceRect, destRect);
} }
} }
/// <summary>
/// Measures the control.
/// </summary>
/// <param name="availableSize">The available size.</param>
/// <returns>The desired size of the control.</returns>
protected override Size MeasureOverride(Size availableSize) protected override Size MeasureOverride(Size availableSize)
{ {
double width = 0; double width = 0;
@ -77,11 +101,13 @@ namespace Perspex.Controls
return new Size(width * scale.X, height * scale.Y); return new Size(width * scale.X, height * scale.Y);
} }
protected override Size ArrangeOverride(Size finalSize) /// <summary>
{ /// Calculates the scaling for the image.
return finalSize; /// </summary>
} /// <param name="availableSize">The size available to display the image.</param>
/// <param name="imageSize">The pxiel size of the image.</param>
/// <param name="stretch">The stretch mode of the control.</param>
/// <returns>A vector with the X and Y scaling factors.</returns>
private static Vector CalculateScaling(Size availableSize, Size imageSize, Stretch stretch) private static Vector CalculateScaling(Size availableSize, Size imageSize, Stretch stretch)
{ {
double scaleX = 1; double scaleX = 1;
@ -106,4 +132,4 @@ namespace Perspex.Controls
return new Vector(scaleX, scaleY); return new Vector(scaleX, scaleY);
} }
} }
} }

4
Perspex.Controls/Primitives/AccessText.cs

@ -7,12 +7,10 @@
namespace Perspex.Controls.Primitives namespace Perspex.Controls.Primitives
{ {
using System; using System;
using Perspex.Media;
using Perspex.Input; using Perspex.Input;
using Perspex.Media;
using Perspex.Rendering; using Perspex.Rendering;
/// <summary> /// <summary>
/// A text block that displays a character prefixed with an underscore as an access key. /// A text block that displays a character prefixed with an underscore as an access key.
/// </summary> /// </summary>

11
Perspex.Controls/Primitives/HeaderedContentControl.cs

@ -6,15 +6,24 @@
namespace Perspex.Controls.Primitives namespace Perspex.Controls.Primitives
{ {
/// <summary>
/// A <see cref="ContentControl"/> with a header.
/// </summary>
public class HeaderedContentControl : ContentControl, IHeadered public class HeaderedContentControl : ContentControl, IHeadered
{ {
/// <summary>
/// Defines the <see cref="Header"/> property.
/// </summary>
public static readonly PerspexProperty<object> HeaderProperty = public static readonly PerspexProperty<object> HeaderProperty =
PerspexProperty.Register<ContentControl, object>("Header"); PerspexProperty.Register<ContentControl, object>("Header");
/// <summary>
/// Gets or sets the header content.
/// </summary>
public object Header public object Header
{ {
get { return this.GetValue(HeaderProperty); } get { return this.GetValue(HeaderProperty); }
set { this.SetValue(HeaderProperty, value); } set { this.SetValue(HeaderProperty, value); }
} }
} }
} }

4
Perspex.Controls/Primitives/SelectingItemsControl.cs

@ -7,13 +7,13 @@
namespace Perspex.Controls.Primitives namespace Perspex.Controls.Primitives
{ {
using System; using System;
using System.Linq;
using System.Collections; using System.Collections;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq;
using Perspex.Controls.Utils; using Perspex.Controls.Utils;
using Perspex.Input; using Perspex.Input;
using Perspex.VisualTree;
using Perspex.Interactivity; using Perspex.Interactivity;
using Perspex.VisualTree;
/// <summary> /// <summary>
/// An <see cref="ItemsControl"/> that maintains a selection. /// An <see cref="ItemsControl"/> that maintains a selection.

42
Perspex.Controls/TextBlock.cs

@ -1,6 +1,6 @@
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// <copyright file="TextBlock.cs" company="Steven Kirk"> // <copyright file="TextBlock.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information. // Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright> // </copyright>
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@ -26,49 +26,61 @@ namespace Perspex.Controls
/// Defines the <see cref="FontFamily"/> property. /// Defines the <see cref="FontFamily"/> property.
/// </summary> /// </summary>
public static readonly PerspexProperty<string> FontFamilyProperty = public static readonly PerspexProperty<string> FontFamilyProperty =
PerspexProperty.RegisterAttached<TextBlock, Control, string>("FontFamily", inherits: true); PerspexProperty.RegisterAttached<TextBlock, Control, string>(
nameof(FontFamily),
inherits: true);
/// <summary> /// <summary>
/// Defines the <see cref="FontSize"/> property. /// Defines the <see cref="FontSize"/> property.
/// </summary> /// </summary>
public static readonly PerspexProperty<double> FontSizeProperty = public static readonly PerspexProperty<double> FontSizeProperty =
PerspexProperty.RegisterAttached<TextBlock, Control, double>("FontSize", inherits: true); PerspexProperty.RegisterAttached<TextBlock, Control, double>(
nameof(FontSize),
inherits: true);
/// <summary> /// <summary>
/// Defines the <see cref="FontStyle"/> property. /// Defines the <see cref="FontStyle"/> property.
/// </summary> /// </summary>
public static readonly PerspexProperty<FontStyle> FontStyleProperty = public static readonly PerspexProperty<FontStyle> FontStyleProperty =
PerspexProperty.RegisterAttached<TextBlock, Control, FontStyle>("FontStyle", inherits: true); PerspexProperty.RegisterAttached<TextBlock, Control, FontStyle>(
nameof(FontStyle),
inherits: true);
/// <summary> /// <summary>
/// Defines the <see cref="FontWeight"/> property. /// Defines the <see cref="FontWeight"/> property.
/// </summary> /// </summary>
public static readonly PerspexProperty<FontWeight> FontWeightProperty = public static readonly PerspexProperty<FontWeight> FontWeightProperty =
PerspexProperty.RegisterAttached<TextBlock, Control, FontWeight>("FontWeight", inherits: true, defaultValue: FontWeight.Normal); PerspexProperty.RegisterAttached<TextBlock, Control, FontWeight>(
nameof(FontWeight),
inherits: true,
defaultValue: FontWeight.Normal);
/// <summary> /// <summary>
/// Defines the <see cref="Foreground"/> property. /// Defines the <see cref="Foreground"/> property.
/// </summary> /// </summary>
public static readonly PerspexProperty<Brush> ForegroundProperty = public static readonly PerspexProperty<Brush> ForegroundProperty =
PerspexProperty.RegisterAttached<TextBlock, Control, Brush>("Foreground", new SolidColorBrush(0xff000000), inherits: true); PerspexProperty.RegisterAttached<TextBlock, Control, Brush>(
nameof(Foreground),
new SolidColorBrush(0xff000000),
inherits: true);
/// <summary> /// <summary>
/// Defines the <see cref="Text"/> property. /// Defines the <see cref="Text"/> property.
/// </summary> /// </summary>
public static readonly PerspexProperty<string> TextProperty = public static readonly PerspexProperty<string> TextProperty =
PerspexProperty.Register<TextBlock, string>("Text"); PerspexProperty.Register<TextBlock, string>(nameof(Text));
/// <summary> /// <summary>
/// Defines the <see cref="TextAlignment"/> property. /// Defines the <see cref="TextAlignment"/> property.
/// </summary> /// </summary>
public static readonly PerspexProperty<TextAlignment> TextAlignmentProperty = public static readonly PerspexProperty<TextAlignment> TextAlignmentProperty =
PerspexProperty.Register<TextBlock, TextAlignment>("TextAlignment"); PerspexProperty.Register<TextBlock, TextAlignment>(nameof(TextAlignment));
/// <summary> /// <summary>
/// Defines the <see cref="TextWrapping"/> property. /// Defines the <see cref="TextWrapping"/> property.
/// </summary> /// </summary>
public static readonly PerspexProperty<TextWrapping> TextWrappingProperty = public static readonly PerspexProperty<TextWrapping> TextWrappingProperty =
PerspexProperty.Register<TextBlock, TextWrapping>("TextWrapping"); PerspexProperty.Register<TextBlock, TextWrapping>(nameof(TextWrapping));
/// <summary> /// <summary>
/// The formatted text used for rendering. /// The formatted text used for rendering.
@ -80,6 +92,14 @@ namespace Perspex.Controls
/// </summary> /// </summary>
private Size constraint; private Size constraint;
/// <summary>
/// Initializes static members of the <see cref="TextBlock"/> class.
/// </summary>
static TextBlock()
{
AffectsRender(ForegroundProperty);
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="TextBlock"/> class. /// Initializes a new instance of the <see cref="TextBlock"/> class.
/// </summary> /// </summary>
@ -207,7 +227,7 @@ namespace Perspex.Controls
} }
this.FormattedText.Constraint = this.Bounds.Size; this.FormattedText.Constraint = this.Bounds.Size;
context.DrawText(this.Foreground, new Point(), this.FormattedText); context.DrawText(this.Foreground, new Point(), this.FormattedText);
} }
/// <summary> /// <summary>
@ -267,4 +287,4 @@ namespace Perspex.Controls
return new Size(); return new Size();
} }
} }
} }

14
Perspex.Controls/TextWrapping.cs

@ -1,14 +1,24 @@
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// <copyright file="TextWrapping.cs" company="Steven Kirk"> // <copyright file="TextWrapping.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information. // Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright> // </copyright>
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
namespace Perspex.Controls namespace Perspex.Controls
{ {
/// <summary>
/// Controls the wrapping mode in a <see cref="TextBlock"/>.
/// </summary>
public enum TextWrapping public enum TextWrapping
{ {
/// <summary>
/// Text should not wrap.
/// </summary>
NoWrap, NoWrap,
/// <summary>
/// Text can wrap.
/// </summary>
Wrap Wrap
} }
} }
Loading…
Cancel
Save