Browse Source

Merge pull request #3329 from donandren/improveparsing

add some parsing of primitive types
pull/3343/head
Jumar Macato 7 years ago
committed by GitHub
parent
commit
7f11d8374b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/Avalonia.Visuals/Matrix.cs
  2. 19
      src/Avalonia.Visuals/Media/Transform.cs
  3. 2
      src/Avalonia.Visuals/Point.cs
  4. 11
      src/Avalonia.Visuals/RelativePoint.cs
  5. 21
      src/Avalonia.Visuals/Vector.cs

2
src/Avalonia.Visuals/Matrix.cs

@ -306,7 +306,7 @@ namespace Avalonia
/// <summary>
/// Parses a <see cref="Matrix"/> string.
/// </summary>
/// <param name="s">The string.</param>
/// <param name="s">Six comma-delimited double values (m11, m12, m21, m22, offsetX, offsetY) that describe the new <see cref="Matrix"/></param>
/// <returns>The <see cref="Matrix"/>.</returns>
public static Matrix Parse(string s)
{

19
src/Avalonia.Visuals/Media/Transform.cs

@ -28,6 +28,16 @@ namespace Avalonia.Media
/// </summary>
public abstract Matrix Value { get; }
/// <summary>
/// Parses a <see cref="Transform"/> string.
/// </summary>
/// <param name="s">Six comma-delimited double values that describe the new <see cref="Transform"/>. For details check <see cref="Matrix.Parse(string)"/> </param>
/// <returns>The <see cref="Transform"/>.</returns>
public static Transform Parse(string s)
{
return new MatrixTransform(Matrix.Parse(s));
}
/// <summary>
/// Raises the <see cref="Changed"/> event.
/// </summary>
@ -35,5 +45,14 @@ namespace Avalonia.Media
{
Changed?.Invoke(this, EventArgs.Empty);
}
/// <summary>
/// Returns a String representing this transform matrix instance.
/// </summary>
/// <returns>The string representation.</returns>
public override string ToString()
{
return Value.ToString();
}
}
}

2
src/Avalonia.Visuals/Point.cs

@ -175,7 +175,7 @@ namespace Avalonia
/// Parses a <see cref="Point"/> string.
/// </summary>
/// <param name="s">The string.</param>
/// <returns>The <see cref="Thickness"/>.</returns>
/// <returns>The <see cref="Point"/>.</returns>
public static Point Parse(string s)
{
using (var tokenizer = new StringTokenizer(s, CultureInfo.InvariantCulture, exceptionMessage: "Invalid Point."))

11
src/Avalonia.Visuals/RelativePoint.cs

@ -177,5 +177,16 @@ namespace Avalonia
unit);
}
}
/// <summary>
/// Returns a String representing this RelativePoint instance.
/// </summary>
/// <returns>The string representation.</returns>
public override string ToString()
{
return _unit == RelativeUnit.Absolute ?
_point.ToString() :
string.Format(CultureInfo.InvariantCulture, "{0}%, {1}%", _point.X * 100, _point.Y * 100);
}
}
}

21
src/Avalonia.Visuals/Vector.cs

@ -4,6 +4,7 @@
using System;
using System.Globalization;
using Avalonia.Animation.Animators;
using Avalonia.Utilities;
using JetBrains.Annotations;
namespace Avalonia
@ -85,6 +86,22 @@ namespace Avalonia
public static Vector operator /(Vector vector, double scale)
=> Divide(vector, scale);
/// <summary>
/// Parses a <see cref="Vector"/> string.
/// </summary>
/// <param name="s">The string.</param>
/// <returns>The <see cref="Vector"/>.</returns>
public static Vector Parse(string s)
{
using (var tokenizer = new StringTokenizer(s, CultureInfo.InvariantCulture, exceptionMessage: "Invalid Vector."))
{
return new Vector(
tokenizer.ReadDouble(),
tokenizer.ReadDouble()
);
}
}
/// <summary>
/// Length of the vector
/// </summary>
@ -166,9 +183,9 @@ namespace Avalonia
}
/// <summary>
/// Returns the string representation of the point.
/// Returns the string representation of the vector.
/// </summary>
/// <returns>The string representation of the point.</returns>
/// <returns>The string representation of the vector.</returns>
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", _x, _y);

Loading…
Cancel
Save