Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#3329 from donandren/improveparsing
Browse files Browse the repository at this point in the history
add some parsing of primitive types
  • Loading branch information
jmacato authored Dec 10, 2019
2 parents 5b029f8 + 78b790e commit 7f11d83
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Avalonia.Visuals/Matrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public Matrix Invert()
/// <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)
{
Expand Down
19 changes: 19 additions & 0 deletions src/Avalonia.Visuals/Media/Transform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,31 @@ static Transform()
/// </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>
protected void RaiseChanged()
{
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 changes: 1 addition & 1 deletion src/Avalonia.Visuals/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static implicit operator Vector(Point p)
/// 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."))
Expand Down
11 changes: 11 additions & 0 deletions src/Avalonia.Visuals/RelativePoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,16 @@ public static RelativePoint Parse(string s)
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 changes: 19 additions & 2 deletions src/Avalonia.Visuals/Vector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Globalization;
using Avalonia.Animation.Animators;
using Avalonia.Utilities;
using JetBrains.Annotations;

namespace Avalonia
Expand Down Expand Up @@ -85,6 +86,22 @@ public static explicit operator Point(Vector a)
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>
Expand Down Expand Up @@ -166,9 +183,9 @@ public override int GetHashCode()
}

/// <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);
Expand Down

0 comments on commit 7f11d83

Please sign in to comment.