Browse Source

Fixed tabs in Canvas.cs

pull/146/merge
Nikita Tsukanov 11 years ago
parent
commit
a4e716f1d1
  1. 246
      src/Perspex.Controls/Canvas.cs

246
src/Perspex.Controls/Canvas.cs

@ -6,126 +6,126 @@ using Perspex.Input;
namespace Perspex.Controls namespace Perspex.Controls
{ {
public class Canvas : Panel, INavigableContainer public class Canvas : Panel, INavigableContainer
{ {
/// <summary> /// <summary>
/// Defines the <see cref="Left"/> property. /// Defines the <see cref="Left"/> property.
/// </summary> /// </summary>
public static readonly PerspexProperty<double> LeftProperty = public static readonly PerspexProperty<double> LeftProperty =
PerspexProperty.RegisterAttached<StackPanel, Control, double>("Left"); PerspexProperty.RegisterAttached<StackPanel, Control, double>("Left");
/// <summary> /// <summary>
/// Defines the <see cref="Top"/> property. /// Defines the <see cref="Top"/> property.
/// </summary> /// </summary>
public static readonly PerspexProperty<double> TopProperty = public static readonly PerspexProperty<double> TopProperty =
PerspexProperty.RegisterAttached<StackPanel, Control, double>("Top"); PerspexProperty.RegisterAttached<StackPanel, Control, double>("Top");
/// <summary> /// <summary>
/// Initializes static members of the <see cref="Canvas"/> class. /// Initializes static members of the <see cref="Canvas"/> class.
/// </summary> /// </summary>
static Canvas() static Canvas()
{ {
AffectsArrange(LeftProperty); AffectsArrange(LeftProperty);
AffectsArrange(TopProperty); AffectsArrange(TopProperty);
} }
/// <summary> /// <summary>
/// Gets the value of the Left attached property for a control. /// Gets the value of the Left attached property for a control.
/// </summary> /// </summary>
/// <param name="element">The control.</param> /// <param name="element">The control.</param>
/// <returns>The control's left coordinate.</returns> /// <returns>The control's left coordinate.</returns>
public static double GetLeft(PerspexObject element) public static double GetLeft(PerspexObject element)
{ {
return element.GetValue(LeftProperty); return element.GetValue(LeftProperty);
} }
/// <summary> /// <summary>
/// Sets the value of the Left attached property for a control. /// Sets the value of the Left attached property for a control.
/// </summary> /// </summary>
/// <param name="element">The control.</param> /// <param name="element">The control.</param>
/// <param name="value">The left value.</param> /// <param name="value">The left value.</param>
public static void SetLeft(PerspexObject element, double value) public static void SetLeft(PerspexObject element, double value)
{ {
element.SetValue(LeftProperty, value); element.SetValue(LeftProperty, value);
} }
/// <summary> /// <summary>
/// Gets the value of the Top attached property for a control. /// Gets the value of the Top attached property for a control.
/// </summary> /// </summary>
/// <param name="element">The control.</param> /// <param name="element">The control.</param>
/// <returns>The control's top coordinate.</returns> /// <returns>The control's top coordinate.</returns>
public static double GetTop(PerspexObject element) public static double GetTop(PerspexObject element)
{ {
return element.GetValue(TopProperty); return element.GetValue(TopProperty);
} }
/// <summary> /// <summary>
/// Sets the value of the Top attached property for a control. /// Sets the value of the Top attached property for a control.
/// </summary> /// </summary>
/// <param name="element">The control.</param> /// <param name="element">The control.</param>
/// <param name="value">The top value.</param> /// <param name="value">The top value.</param>
public static void SetTop(PerspexObject element, double value) public static void SetTop(PerspexObject element, double value)
{ {
element.SetValue(TopProperty, value); element.SetValue(TopProperty, value);
} }
/// <summary> /// <summary>
/// Gets the next control in the specified direction. /// Gets the next control in the specified direction.
/// </summary> /// </summary>
/// <param name="direction">The movement direction.</param> /// <param name="direction">The movement direction.</param>
/// <param name="from">The control from which movement begins.</param> /// <param name="from">The control from which movement begins.</param>
/// <returns>The control.</returns> /// <returns>The control.</returns>
IInputElement INavigableContainer.GetControl(FocusNavigationDirection direction, IInputElement from) IInputElement INavigableContainer.GetControl(FocusNavigationDirection direction, IInputElement from)
{ {
// TODO: Implement this // TODO: Implement this
return null; return null;
} }
/// <summary> /// <summary>
/// Measures the control. /// Measures the control.
/// </summary> /// </summary>
/// <param name="availableSize">The available size.</param> /// <param name="availableSize">The available size.</param>
/// <returns>The desired size of the control.</returns> /// <returns>The desired size of the control.</returns>
protected override Size MeasureOverride(Size availableSize) protected override Size MeasureOverride(Size availableSize)
{ {
availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity); availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
foreach (Control child in Children) foreach (Control child in Children)
{ {
child.Measure(availableSize); child.Measure(availableSize);
} }
return new Size(); return new Size();
} }
/// <summary> /// <summary>
/// Arranges the control's children. /// Arranges the control's children.
/// </summary> /// </summary>
/// <param name="finalSize">The size allocated to the control.</param> /// <param name="finalSize">The size allocated to the control.</param>
/// <returns>The space taken.</returns> /// <returns>The space taken.</returns>
protected override Size ArrangeOverride(Size finalSize) protected override Size ArrangeOverride(Size finalSize)
{ {
foreach (Control child in Children) foreach (Control child in Children)
{ {
double x = 0.0; double x = 0.0;
double y = 0.0; double y = 0.0;
double elementLeft = GetLeft(child); double elementLeft = GetLeft(child);
if (double.IsNaN(elementLeft) == false) if (double.IsNaN(elementLeft) == false)
{ {
x = elementLeft; x = elementLeft;
} }
double elementTop = GetTop(child); double elementTop = GetTop(child);
if (double.IsNaN(elementTop) == false) if (double.IsNaN(elementTop) == false)
{ {
y = elementTop; y = elementTop;
} }
child.Arrange(new Rect(new Point(x, y), child.DesiredSize)); child.Arrange(new Rect(new Point(x, y), child.DesiredSize));
} }
return finalSize; return finalSize;
} }
} }
} }

Loading…
Cancel
Save